fprpccodegen.pp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. unit fprpccodegen;
  2. {$mode ObjFPC}
  3. {$h+}
  4. interface
  5. uses
  6. Classes, SysUtils, fpjson, pascodegen;
  7. type
  8. { TAPIClientCodeGen }
  9. TClientCodeOption = (ccoPreferNativeInt,ccoForceJSValueResult);
  10. TClientCodeOptions = set of TClientCodeOption;
  11. { TAPIMethodParam }
  12. TAPIMethodParam = Class(TCollectionItem)
  13. private
  14. FDefaultValue: String;
  15. FJSType: TJSONtype;
  16. FName: String;
  17. FPasName: String;
  18. FPasType: String;
  19. FRequired: Boolean;
  20. Public
  21. Procedure Assign(Source : TPersistent); override;
  22. Property Name : String Read FName Write FName;
  23. Property PasName : String Read FPasName Write FPasName;
  24. Property JSType : TJSONtype Read FJSType Write FJSType;
  25. Property PasType : String Read FPasType Write FPasType;
  26. Property Required : Boolean Read FRequired Write FRequired;
  27. Property DefaultValue : String Read FDefaultValue Write FDefaultValue;
  28. end;
  29. { TAPIService }
  30. { TAPIMethodParams }
  31. TAPIMethodParams = Class(TCollection)
  32. private
  33. function GetParam(aIndex : Integer): TAPIMethodParam;
  34. Public
  35. Constructor Create; overload;
  36. Function AddParam : TAPIMethodParam;
  37. Property Params [aIndex : Integer] : TAPIMethodParam Read GetParam; default;
  38. end;
  39. { TAPIServiceMethod }
  40. TAPIServiceMethod = Class(TCollectionItem)
  41. private
  42. FName: String;
  43. FParams: TAPIMethodParams;
  44. FPasName: String;
  45. FPasReturnType: String;
  46. FReturnType: TJSONtype;
  47. procedure SetParams(AValue: TAPIMethodParams);
  48. Public
  49. Constructor Create(aCollection : TCollection) ; override;
  50. Destructor Destroy; override;
  51. Procedure Assign(Source : TPersistent); override;
  52. Property Name : String Read FName Write FName;
  53. Property PasName : String Read FPasName Write FPasName;
  54. Property ReturnType : TJSONtype Read FReturnType Write FReturnType;
  55. Property PasReturnType : String Read FPasReturnType Write FPasReturnType;
  56. Property Params : TAPIMethodParams Read FParams Write SetParams;
  57. end;
  58. { TAPIServiceMethods }
  59. TAPIServiceMethods = Class(TCollection)
  60. private
  61. function GetMethod(aIndex : Integer): TAPIServiceMethod;
  62. Public
  63. Constructor Create; overload;
  64. Function AddMethod : TAPIserviceMethod;
  65. Property Methods [aIndex : Integer] : TAPIServiceMethod Read GetMethod; default;
  66. end;
  67. TAPIService = Class(TCollectionItem)
  68. private
  69. FMethods: TAPIServiceMethods;
  70. FName: String;
  71. FPasName: String;
  72. procedure SetMethods(AValue: TAPIServiceMethods);
  73. Public
  74. Constructor Create(aCollection : TCollection) ; override;
  75. Destructor Destroy; override;
  76. Procedure Assign(aSource : TPersistent); override;
  77. Property Methods : TAPIServiceMethods Read FMethods Write SetMethods;
  78. Property Name : String Read FName Write FName;
  79. Property PasName : String Read FPasName Write FPasName;
  80. end;
  81. { TAPService }
  82. TAPIServices = Class(TCollection)
  83. private
  84. function GetAPIService(aIndex : Integer): TAPIService;
  85. Public
  86. Constructor Create; overload;
  87. Function AddService : TAPIservice;
  88. Property Service [aIndex : Integer] : TAPIService Read GetAPIService; default;
  89. end;
  90. TAPIClientCodeGen = Class(TPascalCodeGenerator)
  91. private
  92. FAPI: TJSONObject;
  93. FOptions: TClientCodeOptions;
  94. FServiceParentClass: String;
  95. procedure SetAPI(AValue: TJSONObject);
  96. protected
  97. // Overrides
  98. Function BaseUnits : String; override;
  99. function StringToJSType(S: String): TJSONtype;
  100. // High-level decl
  101. procedure GenerateServiceClassDeclarations(aServices: TAPIServices); virtual;
  102. procedure GenerateServiceDeclaration(aService: TAPIService); virtual;
  103. procedure GenerateServiceMethodDeclaration(aSvc : TAPIService; aMeth : TAPIServiceMethod); virtual;
  104. // High-level impl
  105. procedure GenerateServiceClassImplementations(aServices: TAPIServices); virtual;
  106. procedure GenerateServiceImplementation(aService: TAPIService); virtual;
  107. procedure GenerateServiceMethodImplementation(aSvc : TAPIService; aMeth : TAPIServiceMethod); virtual;
  108. procedure GenerateRPCClassNameImplementation(aService: TAPIService); virtual;
  109. // Get names. All incoming names are the original names of the API
  110. function GetServiceClassName(const aName: string): String; virtual;
  111. function GetServiceMethodName(const aClassName, aMethodName: string): String; virtual;
  112. function GetServiceMethodParamName(const aClassName, aMethodName, aParamName: string): String; virtual;
  113. function GetServiceMethodParamType(const aClassName, aMethodName, aParamName: String; aParamType: TJSONtype): String; virtual;
  114. function GetServiceMethodParamDefault(const aClassName, aMethodName, aParamName: string; aParamType : TJSONType): String; virtual;
  115. function GetServiceMethodResultHandler(const aClassName, aMethodName: string; aResultType: TJSONType): String; virtual;
  116. // Convert JSON to API structures
  117. Procedure FillAPIServices(aAPI : TAPIServices); virtual;
  118. procedure FillAPIMethod(aSvc: TAPIService; aMeth: TAPIServiceMethod; aJSParams: TJSONArray); virtual;
  119. procedure FillAPIMethodParam(aSvc: TAPIService; aMeth: TAPIServiceMethod; aParam: TAPIMethodParam; aJSON: TJSONObject); virtual;
  120. procedure FillAPIService(aSvc: TAPIService; aJSService: TJSONArray); virtual;
  121. Public
  122. Constructor Create(aOwner : TComponent); override;
  123. Procedure Execute;
  124. Property API : TJSONObject Read FAPI Write SetAPI;
  125. Property Options : TClientCodeOptions Read FOptions Write FOptions;
  126. Property ServiceParentClass : String Read FServiceParentClass Write FServiceParentClass;
  127. end;
  128. implementation
  129. { TAPIMethodParams }
  130. function TAPIMethodParams.GetParam(aIndex : Integer): TAPIMethodParam;
  131. begin
  132. Result:=TAPIMethodParam(Items[aIndex]);
  133. end;
  134. constructor TAPIMethodParams.Create;
  135. begin
  136. Inherited Create(TAPIMethodParam);
  137. end;
  138. function TAPIMethodParams.AddParam: TAPIMethodParam;
  139. begin
  140. Result:=TAPIMethodParam(Add);
  141. end;
  142. { TAPIMethodParam }
  143. procedure TAPIMethodParam.Assign(Source: TPersistent);
  144. Var
  145. P : TAPIMethodParam absolute Source;
  146. begin
  147. if Source is TAPIMethodParam then
  148. begin
  149. FName:=P.FName;
  150. FPasName:=P.FPasName;
  151. FPasType:=P.FPasType;
  152. FRequired:=P.FRequired;
  153. FDefaultValue:=P.FDefaultValue;
  154. FJSType:=P.FJSType;
  155. end
  156. else
  157. inherited Assign(Source);
  158. end;
  159. { TAPIServiceMethod }
  160. procedure TAPIServiceMethod.SetParams(AValue: TAPIMethodParams);
  161. begin
  162. if FParams=AValue then Exit;
  163. FParams.Assign(AValue);
  164. end;
  165. constructor TAPIServiceMethod.Create(aCollection: TCollection);
  166. begin
  167. inherited Create(aCollection);
  168. FParams:=TAPIMethodParams.Create;
  169. end;
  170. destructor TAPIServiceMethod.Destroy;
  171. begin
  172. FreeAndNil(FParams);
  173. Inherited;
  174. end;
  175. procedure TAPIServiceMethod.Assign(Source: TPersistent);
  176. Var
  177. M : TAPIServiceMethod absolute Source;
  178. begin
  179. if Source is TAPIServiceMethod then
  180. begin
  181. FName:=M.FName;
  182. FPasName:=M.FPasName;
  183. FReturnType:=M.FReturnType;
  184. FPasReturnType:=M.FPasReturnType;
  185. FParams.Assign(M.Params);
  186. end
  187. else
  188. inherited Assign(Source);
  189. end;
  190. { TAPIServiceMethods }
  191. function TAPIServiceMethods.GetMethod(aIndex : Integer): TAPIServiceMethod;
  192. begin
  193. Result:=TAPIServiceMethod(Items[aIndex]);
  194. end;
  195. constructor TAPIServiceMethods.Create;
  196. begin
  197. Inherited Create(TAPIServiceMethod);
  198. end;
  199. function TAPIServiceMethods.AddMethod: TAPIserviceMethod;
  200. begin
  201. Result:=Add as TAPIserviceMethod
  202. end;
  203. { TAPIService }
  204. procedure TAPIService.SetMethods(AValue: TAPIServiceMethods);
  205. begin
  206. if FMethods=AValue then Exit;
  207. FMethods.Assign(AValue);
  208. end;
  209. constructor TAPIService.Create(aCollection: TCollection);
  210. begin
  211. inherited Create(aCollection);
  212. FMethods:=TAPIServiceMethods.Create;
  213. end;
  214. destructor TAPIService.Destroy;
  215. begin
  216. FreeAndNil(FMethods);
  217. Inherited;
  218. end;
  219. procedure TAPIService.Assign(aSource: TPersistent);
  220. Var
  221. svc : TAPIService absolute aSource;
  222. begin
  223. if aSource is TAPIService then
  224. begin
  225. FName:=svc.FName;
  226. FPasName:=svc.FPasName;
  227. FMethods.Assign(svc.Methods);
  228. end
  229. else
  230. inherited Assign(aSource);
  231. end;
  232. { TAPIServices }
  233. function TAPIServices.GetAPIService(aIndex : Integer): TAPIService;
  234. begin
  235. Result:=TAPIService(Items[aIndex])
  236. end;
  237. constructor TAPIServices.Create;
  238. begin
  239. Inherited Create(TAPIService);
  240. end;
  241. function TAPIServices.AddService: TAPIservice;
  242. begin
  243. Result:=Add as TAPIservice;
  244. end;
  245. { TAPIClientCodeGen }
  246. procedure TAPIClientCodeGen.SetAPI(AValue: TJSONObject);
  247. begin
  248. if FAPI=AValue then Exit;
  249. FAPI.Free;
  250. FAPI:=AValue;
  251. end;
  252. procedure TAPIClientCodeGen.GenerateServiceClassDeclarations(aServices: TAPIServices);
  253. Var
  254. I : Integer;
  255. begin
  256. For I:=0 to aServices.Count-1 do
  257. GenerateServiceDeclaration(aServices[i]);
  258. end;
  259. procedure TAPIClientCodeGen.GenerateServiceClassImplementations(aServices: TAPIServices);
  260. Var
  261. I : Integer;
  262. begin
  263. For I:=0 to aServices.Count-1 do
  264. GenerateServiceImplementation(aServices[i]);
  265. end;
  266. procedure TAPIClientCodeGen.Execute;
  267. Var
  268. Services : TAPIServices;
  269. begin
  270. CreateUnitClause;
  271. CreateHeader;
  272. AddLn('Type');
  273. Indent;
  274. Services:=TAPIServices.Create;
  275. try
  276. FillAPIServices(Services);
  277. GenerateServiceClassDeclarations(Services);
  278. Addln('');
  279. Addln('implementation');
  280. Addln('');
  281. GenerateServiceClassImplementations(Services);
  282. Addln('');
  283. Addln('end.');
  284. finally
  285. Services.Free;
  286. Undent;
  287. end;
  288. end;
  289. function TAPIClientCodeGen.GetServiceClassName(const aName: string): String;
  290. begin
  291. Result:='T'+EscapeKeyWord(aName)+'Service';
  292. end;
  293. function TAPIClientCodeGen.GetServiceMethodName(const aClassName,
  294. aMethodName: string): String;
  295. begin
  296. Result:=EscapeKeyWord(aMethodName);
  297. end;
  298. function TAPIClientCodeGen.GetServiceMethodParamName(const aClassName, aMethodName, aParamName: string): String;
  299. begin
  300. Result:=EscapeKeyWord(aParamName);
  301. end;
  302. function TAPIClientCodeGen.GetServiceMethodParamType(const aClassName,
  303. aMethodName, aParamName: String; aParamType: TJSONtype): String;
  304. begin
  305. case aParamtype of
  306. jtString : Result:='String';
  307. jtBoolean : Result:='Boolean';
  308. jtNumber : begin
  309. if ccoPreferNativeInt in Options then
  310. Result:='NativeInt'
  311. else
  312. Result:='Double';
  313. end;
  314. jtArray : Result:='TJSArray';
  315. jtObject : Result:='TJSObject';
  316. else
  317. Result:='JSValue';
  318. end;
  319. end;
  320. function TAPIClientCodeGen.GetServiceMethodParamDefault(const aClassName, aMethodName, aParamName: string; aParamType : TJSONType): String;
  321. begin
  322. case aParamtype of
  323. jtString : Result:='''''';
  324. jtBoolean : Result:='False';
  325. jtNumber : begin
  326. if ccoPreferNativeInt in Options then
  327. Result:='0'
  328. else
  329. Result:='0.0';
  330. end;
  331. jtArray : Result:='Nil';
  332. jtObject : Result:='Nil';
  333. else
  334. Result:='Nil';
  335. end;
  336. end;
  337. function TAPIClientCodeGen.GetServiceMethodResultHandler(const aClassName,
  338. aMethodName: string; aResultType: TJSONType): String;
  339. begin
  340. {
  341. TEmptyResultHandler = reference to procedure;
  342. TBooleanResultHandler = reference to procedure (aResult : Boolean);
  343. TNativeIntResultHandler = reference to procedure (aResult : NativeInt);
  344. TDoubleResultHandler = reference to procedure (aResult : Double);
  345. TStringResultHandler = reference to procedure (aResult : String);
  346. TArrayResultHandler = reference to procedure (aResult : TJSArray);
  347. TObjectResultHandler = reference to procedure (aResult : TJSObject);
  348. TJSValueResultHandler = reference to procedure (aResult : JSValue);
  349. }
  350. if ccoForceJSValueResult in options then
  351. Result:='TJSValueResultHandler'
  352. else
  353. case aResultType of
  354. jtString : Result:='TStringResultHandler';
  355. jtBoolean : Result:='TBooleanResultHandler';
  356. jtNumber : begin
  357. if ccoPreferNativeInt in Options then
  358. Result:='TNativeIntResultHandler'
  359. else
  360. Result:='TDoubleResultHandler';
  361. end;
  362. jtArray : Result:='TArrayResultHandler';
  363. jtObject : Result:='TObjectResultHandler';
  364. jtNull : Result:='TEmptyResultHandler';
  365. jtUnknown : Result:='TJSValueResultHandler';
  366. else
  367. Result:='TEmptyResultHandler';
  368. end;
  369. end;
  370. procedure TAPIClientCodeGen.FillAPIServices(aAPI: TAPIServices);
  371. Var
  372. Actions : TJSONObject;
  373. I : Integer;
  374. AService : TJSONArray;
  375. svc : TAPIService;
  376. begin
  377. Actions:=API.Get('actions',TJSONObject(Nil));
  378. If Not Assigned(Actions) then
  379. exit;
  380. For I:=0 to Actions.Count-1 do
  381. begin
  382. svc:=aAPI.AddService;
  383. svc.Name:=Actions.Names[i];
  384. svc.PasName:=GetServiceClassName(svc.Name);
  385. aService:=Actions.Arrays[svc.Name];
  386. FillAPIService(svc,aService);
  387. end;
  388. end;
  389. function TAPIClientCodeGen.StringToJSType(S : String) : TJSONtype;
  390. begin
  391. S:=LowerCase(S);
  392. Case S of
  393. 'jtunknown' : Result:=jtUnknown;
  394. 'jtnumber' : Result:=jtNumber;
  395. 'jtstring' : Result:=jtString;
  396. 'jtboolean' : Result:=jtBoolean;
  397. 'jtnull' : Result:=jtNull;
  398. 'jtarray' : Result:=jtArray;
  399. 'jtobject' : Result:=jtObject;
  400. else
  401. Result:=jtUnknown;
  402. end;
  403. end;
  404. procedure TAPIClientCodeGen.FillAPIService(aSvc : TAPIService; aJSService : TJSONArray);
  405. Var
  406. I : Integer;
  407. aJSON : TJSONObject;
  408. aMeth : TAPIServiceMethod;
  409. aParams : TJSONArray;
  410. begin
  411. For I:=0 to aJSService.Count-1 do
  412. begin
  413. aJSON:=aJSService.Objects[i];
  414. aMeth:=aSvc.Methods.AddMethod;
  415. aMeth.Name:=aJSON.Get('name','');
  416. aMeth.PasName:=GetServiceMethodName(aSvc.Name,aMeth.Name);
  417. aMeth.ReturnType:=StringToJSType(aJSON.Get('resulttype',''));
  418. aParams:=aJSON.Get('paramdefs',TJSONarray(Nil));
  419. if (aJSON.Get('len',0)>0) and Assigned(aParams) then
  420. FillAPIMethod(aSvc,aMeth,aParams);
  421. end;
  422. end;
  423. constructor TAPIClientCodeGen.Create(aOwner: TComponent);
  424. begin
  425. inherited Create(aOwner);
  426. FServiceParentClass:='TRPCCustomService';
  427. end;
  428. procedure TAPIClientCodeGen.FillAPIMethodParam(aSvc : TAPIService; aMeth : TAPIServiceMethod; aParam :TAPIMethodParam; aJSON : TJSONObject);
  429. begin
  430. aParam.Name:=aJSON.get('name','');
  431. aParam.PasName:=GetServiceMethodParamName(aSvc.Name,aMeth.Name,aParam.Name);
  432. aParam.JSType:=StringToJSType(aJSON.Get('type',''));
  433. aParam.PasType:=GetServiceMethodParamType(aSvc.Name,aMeth.Name,aParam.Name,aParam.JSType);
  434. aParam.Required:=aJSON.Get('required',true);
  435. aParam.DefaultValue:=GetServiceMethodParamDefault(aSVC.Name,aMeth.Name,aParam.Name,aParam.JSType);
  436. end;
  437. procedure TAPIClientCodeGen.FillAPIMethod(aSvc : TAPIService; aMeth : TAPIServiceMethod; aJSParams : TJSONArray);
  438. var
  439. I : Integer;
  440. aJSON : TJSONObject;
  441. aParam : TAPIMethodParam;
  442. begin
  443. For I:=0 to aJSParams.Count-1 do
  444. begin
  445. aJSON:=aJSParams.Objects[i];
  446. aParam:=aMeth.Params.AddParam;
  447. FillAPIMethodParam(aSvc,aMeth,aParam,aJSON);
  448. end;
  449. end;
  450. procedure TAPIClientCodeGen.GenerateServiceMethodDeclaration(aSvc : TAPIService; aMeth : TAPIServiceMethod);
  451. Var
  452. I : Integer;
  453. ResType,ParamLine : String;
  454. aParam : TAPIMethodParam;
  455. begin
  456. resType:=GetServiceMethodResultHandler(aSvc.Name, aMeth.Name, aMeth.ReturnType);
  457. ParamLine:='';
  458. For I:=0 to aMeth.Params.Count-1 do
  459. begin
  460. aParam:=aMeth.Params[i];
  461. if ParamLine<>'' then
  462. ParamLine:=ParamLine+'; ';
  463. ParamLine:=ParamLine+aParam.PasName+' : '+aParam.PasType;
  464. if (not aParam.Required) and (aParam.DefaultValue<>'') then
  465. ParamLine:=ParamLine+' = '+aParam.DefaultValue;
  466. end;
  467. if ParamLine<>'' then
  468. ParamLine:=ParamLine+'; ';
  469. ParamLine:=ParamLine+'aOnSuccess : '+ResType+' = Nil; aOnFailure : TRPCFailureCallBack = Nil';
  470. AddLn('Function %s (%s) : NativeInt;',[aMeth.PasName,ParamLine]);
  471. // For I:=0 to
  472. end;
  473. procedure TAPIClientCodeGen.GenerateServiceMethodImplementation(aSvc : TAPIService; aMeth : TAPIServiceMethod);
  474. Var
  475. I : Integer;
  476. ResType,ParamLine : String;
  477. aParam : TAPIMethodParam;
  478. begin
  479. resType:=GetServiceMethodResultHandler(aSvc.Name, aMeth.Name, aMeth.ReturnType);
  480. ParamLine:='';
  481. For I:=0 to aMeth.Params.Count-1 do
  482. begin
  483. aParam:=aMeth.Params[i];
  484. if ParamLine<>'' then
  485. ParamLine:=ParamLine+'; ';
  486. ParamLine:=ParamLine+aParam.PasName+' : '+aParam.PasType;
  487. if (not aParam.Required) and (aParam.DefaultValue<>'') then
  488. ParamLine:=ParamLine+' = '+aParam.DefaultValue;
  489. end;
  490. if ParamLine<>'' then
  491. ParamLine:=ParamLine+'; ';
  492. ParamLine:=ParamLine+'aOnSuccess : '+ResType+' = Nil; aOnFailure : TRPCFailureCallBack = Nil';
  493. AddLn('Function %s.%s (%s) : NativeInt;',[aSvc.PasName,aMeth.PasName,ParamLine]);
  494. AddLn('');
  495. Indent;
  496. Addln('Procedure DoSuccess(Sender : TObject; const aResult : JSValue);');
  497. AddLn('');
  498. Addln('begin');
  499. indent;
  500. Addln('If Assigned(aOnSuccess) then');
  501. Indent;
  502. Addln('aOnSuccess(%s(aResult))',[aMeth.PasReturnType]);
  503. undent;
  504. undent;
  505. Addln('end;');
  506. Undent;
  507. AddLn('');
  508. Addln('Var');
  509. Indent;
  510. Addln('_Params : JSValue;');
  511. Undent;
  512. AddLn('');
  513. Addln('begin');
  514. Indent;
  515. Addln('StartParams;');
  516. For I:=0 to aMeth.Params.Count-1 do
  517. begin
  518. aParam:=aMeth.Params[i];
  519. AddLn('AddParam(''%s'',%s);',[aParam.Name,aParam.PasName]);
  520. end;
  521. Addln('_Params:=EndParams;');
  522. AddLn('Result:=ExecuteRequest(RPCClassName,''%s'',_Params,@DoSuccess,aOnFailure);',[aMeth.Name]);
  523. Undent;
  524. Addln('end;');
  525. AddLn('');
  526. AddLn('');
  527. end;
  528. procedure TAPIClientCodeGen.GenerateServiceDeclaration(aService: TAPIService);
  529. Var
  530. I : integer;
  531. begin
  532. ClassHeader(aService.PasName);
  533. AddLn('%s = Class(TRPCCustomService)',[aService.PasName]);
  534. Addln('Protected');
  535. Indent;
  536. AddLn('Function RPCClassName : string; override;');
  537. Undent;
  538. Addln('Public');
  539. Indent;
  540. For I:=0 to aService.Methods.Count-1 do
  541. GenerateServiceMethodDeclaration(aService,aService.Methods[i]);
  542. Undent;
  543. Addln('end;');
  544. end;
  545. procedure TAPIClientCodeGen.GenerateRPCClassNameImplementation(aService: TAPIService);
  546. begin
  547. Addln('Function %s.RPCClassName : string;',[aService.PasName]);
  548. Addln('');
  549. AddLn('begin');
  550. indent;
  551. AddLn('Result:=''%s'';',[aService.Name]);
  552. undent;
  553. Addln('end;');
  554. Addln('');
  555. Addln('');
  556. end;
  557. procedure TAPIClientCodeGen.GenerateServiceImplementation(aService: TAPIService);
  558. Var
  559. I : integer;
  560. begin
  561. ClassHeader(aService.PasName);
  562. Addln('');
  563. GenerateRPCClassNameImplementation(aService);
  564. For I:=0 to aService.Methods.Count-1 do
  565. GenerateServiceMethodImplementation(aService,aService.Methods[i]);
  566. Addln('');
  567. end;
  568. function TAPIClientCodeGen.BaseUnits: String;
  569. begin
  570. Result:='fprpcclient';
  571. end;
  572. end.