123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- {
- This file is part of the Free Component Library
- Unit with the server-side interface implementations of the interfaces
- Registers the classes.
- Copyright (c) 2022 by Michael Van Canneyt [email protected]
- See the file COPYING.FPC, included in this distribution,
- for details about the copyright.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- **********************************************************************}
- unit rpcapi;
- {$mode ObjFPC}{$H+}
- interface
- uses
- Classes, SysUtils, fprpcrtti, myapi;
- Type
- { TIntfImpl }
- TIntfImpl = class(TInterfacedObject, IMyInterface)
- public
- procedure SayHello;
- Function Echo(args : Array of string) : String;
- function DoSum(a,b : Integer) : integer;
- function Split(aLine,aSep : string) : TStringArray;
- function DoVarTest(var aArg: String): Boolean;
- end;
- { TIntf2Impl }
- TIntf2Impl = class(TInterfacedObject, IMyOtherInterface)
- public
- function Echo(args: TStringArray): String;
- function SayHello: string;
- end;
- Implementation
- { TIntf2Impl }
- function TIntf2Impl.Echo(args: TStringArray): String;
- var
- S : String;
- begin
- Result:='';
- For S in Args do
- begin
- if Result<>'' then
- Result:=Result+' ';
- Result:=Result+S;
- end
- end;
- function TIntf2Impl.SayHello: string;
- begin
- Result:='Hello, World!';
- end;
- procedure TIntfImpl.SayHello;
- begin
- Writeln('Hello, World!');
- end;
- function TIntfImpl.Echo(args: array of string): String;
- var
- S : String;
- begin
- Result:='';
- For S in Args do
- begin
- if Result<>'' then
- Result:=Result+' ';
- Result:=Result+S;
- end
- end;
- function TIntfImpl.DoSum(a,b : Integer) : integer;
- begin
- Result := a + b;
- end;
- function TIntfImpl.Split(aLine,aSep : string) : TStringArray;
- begin
- Result := aLine.Split(aSep);
- end;
- function TIntfImpl.DoVarTest(var aArg: String): Boolean;
- begin
- if aArg = 'Test' then begin
- aArg := 'Foo';
- Result := True;
- end else
- Result := False;
- end;
- Function GetMyInterface(Const aName : string) : IInterface;
- begin
- Result:=TIntfImpl.Create as IInterface;
- end;
- Function GetMyOtherInterface(Const aName : string) : IInterface;
- begin
- Result:=TIntf2Impl.Create as IInterface;
- end;
- initialization
- RTTIJSONRPCRegistry.Add(TypeInfo(IMyInterface),@GetMyInterface);
- RTTIJSONRPCRegistry.Add(TypeInfo(IMyOtherInterface),@GetMyOtherInterface,'Service2');
- end.
|