DelphiWebsockets/DUnit/NewService_Impl.pas

93 lines
2.4 KiB
ObjectPascal
Raw Normal View History

2013-11-18 14:27:13 +01:00
unit NewService_Impl;
{----------------------------------------------------------------------------}
{ This unit was automatically generated by the RemObjects SDK after reading }
{ the RODL file associated with this project . }
{ }
{ This is where you are supposed to code the implementation of your objects. }
{----------------------------------------------------------------------------}
{$I RemObjects.inc}
interface
uses
{vcl:} Classes, SysUtils,
{RemObjects:} uROXMLIntf, uROClientIntf, uROTypes, uROServer, uROServerIntf, uROSessions,
{Required:} uRORemoteDataModule,
{Generated:} NewLibrary_Intf;
type
{ TNewService }
TNewService = class(TRORemoteDataModule,
INewService)
private
protected
{ INewService methods }
function Sum(const a: Integer; const b: Integer): Integer;
function LongDurationIntermediateSocketIOResults(const aDuration_ms: Integer; const aSleep_ms: Integer): Integer;
end;
implementation
{$IFDEF DELPHIXE2UP}
{%CLASSGROUP 'System.Classes.TPersistent'}
{$ENDIF}
{$IFNDEF FPC}
{$R *.dfm}
{$ELSE}
{$R *.lfm}
{$ENDIF}
uses
{Generated:} NewLibrary_Invk, DateUtils, uROHTTPWebsocketServer,
IdServerSocketIOHandling;
procedure Create_NewService(out anInstance : IUnknown);
begin
anInstance := TNewService.Create(nil);
end;
var
fClassFactory: IROClassFactory;
{ TNewService }
function TNewService.LongDurationIntermediateSocketIOResults(const aDuration_ms,
aSleep_ms: Integer): Integer;
var
tstart: TDateTime;
ctx: TROTransportContext;
iCounter: Integer;
begin
tstart := Now;
iCounter := 0;
while MilliSecondsBetween(Now, tstart) < aDuration_ms do
begin
//send intermediate (!) response to client back (for progress etc)
Assert(Transport is TROTransportContext);
ctx := Transport as TROTransportContext;
Inc(iCounter);
if ctx.Context.IsSocketIO then
ctx.Context.SocketIO.SendTo(ctx.Context, IntToStr(iCounter));
Sleep(aSleep_ms);
end;
Result := iCounter;
end;
function TNewService.Sum(const a, b: Integer): Integer;
begin
Result := a + b;
end;
initialization
fClassFactory := TROClassFactory.Create('NewService', {$IFDEF FPC}@{$ENDIF}Create_NewService, TNewService_Invoker);
// RegisterForZeroConf(fClassFactory,'_NewService_rosdk._tcp.');
finalization
UnRegisterClassFactory(fClassFactory);
fClassFactory := nil;
end.