unit uPSI_Socket;
{
This file has been generated by UnitParser v0.7, written by M. Knight
and updated by NP. v/d Spek and George Birbilis.
Source Code from Carlo Kok has been used to implement various sections of
UnitParser. Components of ROPS are used in the construction of UnitParser,
code implementing the class wrapper is taken from Carlo Kok's conv utility

}
interface



uses
   SysUtils
  ,Classes
  ,uPSComponent
  ,uPSRuntime
  ,uPSCompiler
  ;

type
(*----------------------------------------------------------------------------*)
  TPSImport_Socket = class(TPSPlugin)
  public
    procedure CompileImport1(CompExec: TPSScript); override;
    procedure ExecImport1(CompExec: TPSScript; const ri: TPSRuntimeClassImporter); override;
  end;


{ compile-time registration functions }
procedure SIRegister_TTCPClient(CL: TPSPascalCompiler);
procedure SIRegister_TSocketIOHandler(CL: TPSPascalCompiler);
procedure SIRegister_Socket(CL: TPSPascalCompiler);

{ run-time registration functions }
procedure RIRegister_TTCPClient(CL: TPSRuntimeClassImporter);
procedure RIRegister_TSocketIOHandler(CL: TPSRuntimeClassImporter);
procedure RIRegister_Socket(CL: TPSRuntimeClassImporter);

function PSPluginCreate(): TPSPlugin; stdcall;

implementation


uses
   IdBaseComponent
  ,IdComponent
  ,IdTCPConnection
  ,IdTCPClient
  ,IdIOHandler
  ,IdGlobal
  ,Socket
  ;


function PSPluginCreate(): TPSPlugin; stdcall;
var
  Import: TPSImport_Socket;
begin
  Import:= TPSImport_Socket.Create(nil);
  Result := Import;
end;

(* === compile-time registration functions === *)
(*----------------------------------------------------------------------------*)
procedure SIRegister_TTCPClient(CL: TPSPascalCompiler);
begin
  //with RegClassS(CL,'TObject', 'TTCPClient') do
  with CL.AddClassN(CL.FindClass('TObject'),'TTCPClient') do
  begin
    RegisterMethod('Constructor Create');
    RegisterMethod('Procedure Connect');
    RegisterMethod('Function Connected : boolean');
    RegisterProperty('BoundIP', 'string', iptrw);
    RegisterProperty('BoundPort', 'integer', iptrw);
    RegisterProperty('ReadTimeout', 'Integer', iptrw);
    RegisterProperty('Host', 'string', iptrw);
    RegisterProperty('Port', 'integer', iptrw);
    RegisterProperty('IOHandler', 'TSocketIOHandler', iptr);
  end;
end;

(*----------------------------------------------------------------------------*)
procedure SIRegister_TSocketIOHandler(CL: TPSPascalCompiler);
begin
  //with RegClassS(CL,'TObject', 'TSocketIOHandler') do
  with CL.AddClassN(CL.FindClass('TObject'),'TSocketIOHandler') do
  begin
    RegisterMethod('Procedure SetIOHandler( IOHandler : TIdIOHandler)');
    RegisterMethod('Procedure Write( Value : string)');
    RegisterMethod('Procedure WriteLn( Value : string)');
    RegisterMethod('Procedure WriteStream( Value : TStream; ASize : integer)');
    RegisterMethod('Procedure ReadStream( AStream : TStream; AByteCount : integer)');
    RegisterMethod('Function ReadLn : string');
  end;
end;

(*----------------------------------------------------------------------------*)
procedure SIRegister_Socket(CL: TPSPascalCompiler);
begin
  SIRegister_TSocketIOHandler(CL);
  SIRegister_TTCPClient(CL);
end;

(* === run-time registration functions === *)
(*----------------------------------------------------------------------------*)
procedure TTCPClientIOHandler_R(Self: TTCPClient; var T: TSocketIOHandler);
begin T := Self.IOHandler; end;

(*----------------------------------------------------------------------------*)
procedure TTCPClientPort_W(Self: TTCPClient; const T: integer);
begin Self.Port := T; end;

(*----------------------------------------------------------------------------*)
procedure TTCPClientPort_R(Self: TTCPClient; var T: integer);
begin T := Self.Port; end;

(*----------------------------------------------------------------------------*)
procedure TTCPClientHost_W(Self: TTCPClient; const T: string);
begin Self.Host := T; end;

(*----------------------------------------------------------------------------*)
procedure TTCPClientHost_R(Self: TTCPClient; var T: string);
begin T := Self.Host; end;

(*----------------------------------------------------------------------------*)
procedure TTCPClientReadTimeout_W(Self: TTCPClient; const T: Integer);
begin Self.ReadTimeout := T; end;

(*----------------------------------------------------------------------------*)
procedure TTCPClientReadTimeout_R(Self: TTCPClient; var T: Integer);
begin T := Self.ReadTimeout; end;

(*----------------------------------------------------------------------------*)
procedure TTCPClientBoundPort_W(Self: TTCPClient; const T: integer);
begin Self.BoundPort := T; end;

(*----------------------------------------------------------------------------*)
procedure TTCPClientBoundPort_R(Self: TTCPClient; var T: integer);
begin T := Self.BoundPort; end;

(*----------------------------------------------------------------------------*)
procedure TTCPClientBoundIP_W(Self: TTCPClient; const T: string);
begin Self.BoundIP := T; end;

(*----------------------------------------------------------------------------*)
procedure TTCPClientBoundIP_R(Self: TTCPClient; var T: string);
begin T := Self.BoundIP; end;

(*----------------------------------------------------------------------------*)
procedure RIRegister_TTCPClient(CL: TPSRuntimeClassImporter);
begin
  with CL.Add(TTCPClient) do
  begin
    RegisterConstructor(@TTCPClient.Create, 'Create');
    RegisterMethod(@TTCPClient.Connect, 'Connect');
    RegisterMethod(@TTCPClient.Connected, 'Connected');
    RegisterPropertyHelper(@TTCPClientBoundIP_R,@TTCPClientBoundIP_W,'BoundIP');
    RegisterPropertyHelper(@TTCPClientBoundPort_R,@TTCPClientBoundPort_W,'BoundPort');
    RegisterPropertyHelper(@TTCPClientReadTimeout_R,@TTCPClientReadTimeout_W,'ReadTimeout');
    RegisterPropertyHelper(@TTCPClientHost_R,@TTCPClientHost_W,'Host');
    RegisterPropertyHelper(@TTCPClientPort_R,@TTCPClientPort_W,'Port');
    RegisterPropertyHelper(@TTCPClientIOHandler_R,nil,'IOHandler');
  end;
end;

(*----------------------------------------------------------------------------*)
procedure RIRegister_TSocketIOHandler(CL: TPSRuntimeClassImporter);
begin
  with CL.Add(TSocketIOHandler) do
  begin
    RegisterMethod(@TSocketIOHandler.SetIOHandler, 'SetIOHandler');
    RegisterMethod(@TSocketIOHandler.Write, 'Write');
    RegisterMethod(@TSocketIOHandler.WriteLn, 'WriteLn');
    RegisterMethod(@TSocketIOHandler.WriteStream, 'WriteStream');
    RegisterMethod(@TSocketIOHandler.ReadStream, 'ReadStream');
    RegisterMethod(@TSocketIOHandler.ReadLn, 'ReadLn');
  end;
end;

(*----------------------------------------------------------------------------*)
procedure RIRegister_Socket(CL: TPSRuntimeClassImporter);
begin
  RIRegister_TSocketIOHandler(CL);
  RIRegister_TTCPClient(CL);
end;



{ TPSImport_Socket }
(*----------------------------------------------------------------------------*)
procedure TPSImport_Socket.CompileImport1(CompExec: TPSScript);
begin
  SIRegister_Socket(CompExec.Comp);
end;
(*----------------------------------------------------------------------------*)
procedure TPSImport_Socket.ExecImport1(CompExec: TPSScript; const ri: TPSRuntimeClassImporter);
begin
  RIRegister_Socket(ri);
end;
(*----------------------------------------------------------------------------*)


end.
