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_THttpClient(CL: TPSPascalCompiler);
procedure SIRegister_TUDPClient(CL: TPSPascalCompiler);
procedure SIRegister_TTCPClient(CL: TPSPascalCompiler);
procedure SIRegister_TSocketIOHandler(CL: TPSPascalCompiler);
procedure SIRegister_Socket(CL: TPSPascalCompiler);

{ run-time registration functions }
procedure RIRegister_THttpClient(CL: TPSRuntimeClassImporter);
procedure RIRegister_TUDPClient(CL: TPSRuntimeClassImporter);
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
  ,IdUDPBase
  ,IdUDPClient
  ,IdHTTP
  ,IdMultipartFormData
  ,Socket
  ;


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

(* === compile-time registration functions === *)
(*----------------------------------------------------------------------------*)
procedure SIRegister_THttpClient(CL: TPSPascalCompiler);
begin
  //with RegClassS(CL,'TObject', 'THttpClient') do
  with CL.AddClassN(CL.FindClass('TObject'),'THttpClient') do
  begin
    RegisterMethod('Constructor Create');
    RegisterMethod('Function Delete( AURL : string) : string');
    RegisterMethod('Function Options( AURL : string) : string');
    RegisterMethod('Function Trace( AURL : string) : string');
    RegisterMethod('Procedure Head( AURL : string)');
    RegisterMethod('Function Post( AURL : string; ASource : TStrings) : string');
    RegisterMethod('Function PostFile( AURL : string; AFormData, AFileList : TStrings) : string');
    RegisterMethod('Function Put( AURL : string; ASource : TStream) : string');
    RegisterMethod('Function Patch( AURL : string; ASource : TStream) : string');
    RegisterMethod('Function Get( AURL : string) : string');
  end;

  with CL.AddClassN(CL.FindClass('TObject'),'TEmail') do
  begin
    RegisterMethod('Procedure Head( AURL : string)');
  end;
end;

(*----------------------------------------------------------------------------*)
procedure SIRegister_TUDPClient(CL: TPSPascalCompiler);
begin
  //with RegClassS(CL,'TObject', 'TUDPClient') do
  with CL.AddClassN(CL.FindClass('TObject'),'TUDPClient') do
  begin
    RegisterMethod('Constructor Create');
    RegisterMethod('Procedure Connect');
    RegisterMethod('Procedure Disconnect');
    RegisterProperty('ReceiveTimeout', 'Integer', iptrw);
    RegisterProperty('Host', 'string', iptrw);
    RegisterProperty('Port', 'integer', iptrw);
    RegisterMethod('Procedure Send( const AData : string)');
    RegisterMethod('Procedure SendBuffer( const ABuffer : TIdBytes)');
    RegisterMethod('Function ReceiveBuffer( var ABuffer : TIdBytes; const AMSec : Integer) : Integer');
    RegisterMethod('Function ReceiveString( ) : string');
  end;
end;

(*----------------------------------------------------------------------------*)
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('Procedure Disconnect');
    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);
  SIRegister_TUDPClient(CL);
  SIRegister_THttpClient(CL);
end;

(* === run-time registration functions === *)
(*----------------------------------------------------------------------------*)
procedure TUDPClientPort_W(Self: TUDPClient; const T: integer);
begin Self.Port := T; end;

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

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

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

(*----------------------------------------------------------------------------*)
procedure TUDPClientReceiveTimeout_W(Self: TUDPClient; const T: Integer);
begin Self.ReceiveTimeout := T; end;

(*----------------------------------------------------------------------------*)
procedure TUDPClientReceiveTimeout_R(Self: TUDPClient; var T: Integer);
begin T := Self.ReceiveTimeout; end;

(*----------------------------------------------------------------------------*)
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_THttpClient(CL: TPSRuntimeClassImporter);
begin
  with CL.Add(THttpClient) do
  begin
    RegisterConstructor(@THttpClient.Create, 'Create');
    RegisterMethod(@THttpClient.Delete, 'Delete');
    RegisterMethod(@THttpClient.Options, 'Options');
    RegisterMethod(@THttpClient.Trace, 'Trace');
    RegisterMethod(@THttpClient.Head, 'Head');
    RegisterMethod(@THttpClient.Post, 'Post');
    RegisterMethod(@THttpClient.PostFile, 'PostFile');
    RegisterMethod(@THttpClient.Put, 'Put');
    RegisterMethod(@THttpClient.Patch, 'Patch');
    RegisterMethod(@THttpClient.Get, 'Get');
  end;
end;

(*----------------------------------------------------------------------------*)
procedure RIRegister_TUDPClient(CL: TPSRuntimeClassImporter);
begin
  with CL.Add(TUDPClient) do
  begin
    RegisterConstructor(@TUDPClient.Create, 'Create');
    RegisterMethod(@TUDPClient.Connect, 'Connect');
    RegisterMethod(@TUDPClient.Disconnect, 'Disconnect');
    RegisterPropertyHelper(@TUDPClientReceiveTimeout_R,@TUDPClientReceiveTimeout_W,'ReceiveTimeout');
    RegisterPropertyHelper(@TUDPClientHost_R,@TUDPClientHost_W,'Host');
    RegisterPropertyHelper(@TUDPClientPort_R,@TUDPClientPort_W,'Port');
    RegisterMethod(@TUDPClient.Send, 'Send');
    RegisterMethod(@TUDPClient.SendBuffer, 'SendBuffer');
    RegisterMethod(@TUDPClient.ReceiveBuffer, 'ReceiveBuffer');
    RegisterMethod(@TUDPClient.ReceiveString, 'ReceiveString');
  end;
end;

(*----------------------------------------------------------------------------*)
procedure RIRegister_TTCPClient(CL: TPSRuntimeClassImporter);
begin
  with CL.Add(TTCPClient) do
  begin
    RegisterConstructor(@TTCPClient.Create, 'Create');
    RegisterMethod(@TTCPClient.Connect, 'Connect');
    RegisterMethod(@TTCPClient.Disconnect, 'Disconnect');
    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);
  RIRegister_TUDPClient(CL);
  RIRegister_THttpClient(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.
