-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuROPSServerLink.pas
1231 lines (1109 loc) · 37.2 KB
/
uROPSServerLink.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit uROPSServerLink;
interface
uses
SysUtils, Classes, uPSCompiler, uPSUtils, uPSRuntime,
uROServer, uROClient, uRODL{$IFDEF WIN32},
Windows{$ELSE}, Types{$ENDIF}, uROTypes, uROClientIntf,
uROSerializer, uPSComponent;
type
TPSROModule = class
protected
class procedure ExecImp(exec: TPSExec; ri: TPSRuntimeClassImporter); virtual;
class procedure CompImp(comp: TPSPascalCompiler); virtual;
end;
TPSROModuleClass = class of TPSROModule;
TPSRemObjectsSdkPlugin = class;
TPSROModuleLoadEvent = procedure (Sender: TPSRemObjectsSdkPlugin) of object;
TPSRemObjectsSdkPlugin = class(TPSPlugin)
private
FRodl: TRODLLibrary;
FModules: TList;
FOnLoadModule: TPSROModuleLoadEvent;
FEnableIndyTCP: Boolean;
FEnableIndyHTTP: Boolean;
FEnableBinary: Boolean;
function GetHaveRodl: Boolean;
function MkStructName(Struct: TRODLStruct): string;
public
procedure CompileImport1(CompExec: TPSScript); override;
procedure ExecImport1(CompExec: TPSScript; const ri: TPSRuntimeClassImporter); override;
protected
procedure Loaded; override;
public
procedure RODLLoadFromFile(const FileName: string);
procedure RODLLoadFromResource;
procedure RODLLoadFromStream(S: TStream);
procedure ClearRodl;
property HaveRodl: Boolean read GetHaveRodl;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure ReloadModules;
procedure RegisterModule(Module: TPSROModuleClass);
published
property OnLoadModule: TPSROModuleLoadEvent read FOnLoadModule write FOnLoadModule;
property EnableIndyTCP: Boolean read FEnableIndyTCP write FEnableIndyTCP default true;
property EnableIndyHTTP: Boolean read FEnableIndyHTTP write FEnableIndyHTTP default true;
property EnableBinary: Boolean read FEnableBinary write FEnableBinary default true;
end;
implementation
uses
uRODLToXML, uROPSImports;
procedure SIRegisterTROTRANSPORTCHANNEL(CL: TPSPascalCompiler);
Begin
With cl.AddClassN(cl.FindClass('TComponent'), 'TROTRANSPORTCHANNEL') do
begin
end;
end;
procedure SIRegisterTROMESSAGE(CL: TPSPascalCompiler);
Begin
With cl.AddClassN(cl.FindClass('TComponent'),'TROMESSAGE') do
begin
RegisterProperty('MESSAGENAME', 'STRING', iptrw);
RegisterProperty('INTERFACENAME', 'STRING', iptrw);
end;
end;
procedure TROMESSAGEINTERFACENAME_W(Self: TROMESSAGE; const T: STRING);
begin Self.INTERFACENAME := T; end;
procedure TROMESSAGEINTERFACENAME_R(Self: TROMESSAGE; var T: STRING);
begin T := Self.INTERFACENAME; end;
procedure TROMESSAGEMESSAGENAME_W(Self: TROMESSAGE; const T: STRING);
begin Self.MESSAGENAME := T; end;
procedure TROMESSAGEMESSAGENAME_R(Self: TROMESSAGE; var T: STRING);
begin T := Self.MESSAGENAME; end;
procedure RIRegisterTROTRANSPORTCHANNEL(Cl: TPSRuntimeClassImporter);
Begin
with Cl.Add(TROTRANSPORTCHANNEL) do
begin
RegisterVirtualConstructor(@TROTRANSPORTCHANNEL.CREATE, 'CREATE');
end;
end;
procedure RIRegisterTROMESSAGE(Cl: TPSRuntimeClassImporter);
Begin
with Cl.Add(TROMESSAGE) do
begin
RegisterVirtualConstructor(@TROMESSAGE.CREATE, 'CREATE');
RegisterPropertyHelper(@TROMESSAGEMESSAGENAME_R,@TROMESSAGEMESSAGENAME_W,'MESSAGENAME');
RegisterPropertyHelper(@TROMESSAGEINTERFACENAME_R,@TROMESSAGEINTERFACENAME_W,'INTERFACENAME');
end;
end;
(*----------------------------------------------------------------------------*)
procedure SIRegister_TROBinaryMemoryStream(CL: TPSPascalCompiler);
begin
//with RegClassS(CL,'TMemoryStream', 'TROBinaryMemoryStream') do
with CL.AddClassN(CL.FindClass('TMemoryStream'),'TROBinaryMemoryStream') do
begin
RegisterMethod('Constructor Create2( const iString : Ansistring);');
RegisterMethod('Constructor Create;');
RegisterMethod('Procedure Assign( iSource : TStream)');
RegisterMethod('Function Clone : TROBinaryMemoryStream');
RegisterMethod('Procedure LoadFromString( const iString : Ansistring)');
RegisterMethod('Procedure LoadFromHexString( const iString : Ansistring)');
RegisterMethod('Function ToString : AnsiString');
RegisterMethod('Function ToHexString : Ansistring');
RegisterMethod('Function ToReadableString : Ansistring');
RegisterMethod('Function WriteAnsiString( AString : AnsiString) : integer');
RegisterProperty('CapacityIncrement', 'integer', iptrw);
end;
end;
(*----------------------------------------------------------------------------*)
procedure SIRegister_uROClasses(CL: TPSPascalCompiler);
begin
SIRegister_TROBinaryMemoryStream(CL);
end;
(* === run-time registration functions === *)
(*----------------------------------------------------------------------------*)
procedure TROBinaryMemoryStreamCapacityIncrement_W(Self: TROBinaryMemoryStream; const T: integer);
begin Self.CapacityIncrement := T; end;
(*----------------------------------------------------------------------------*)
procedure TROBinaryMemoryStreamCapacityIncrement_R(Self: TROBinaryMemoryStream; var T: integer);
begin T := Self.CapacityIncrement; end;
(*----------------------------------------------------------------------------*)
Function TROBinaryMemoryStreamCreate_P(Self: TClass; CreateNewInstance: Boolean):TObject;
Begin Result := TROBinaryMemoryStream.Create; END;
(*----------------------------------------------------------------------------*)
Function TROBinaryMemoryStreamCreate2_P(Self: TClass; CreateNewInstance: Boolean; const iString : Ansistring):TObject;
Begin Result := TROBinaryMemoryStream.Create(iString); END;
(*----------------------------------------------------------------------------*)
procedure RIRegister_TROBinaryMemoryStream(CL: TPSRuntimeClassImporter);
begin
with CL.Add(TROBinaryMemoryStream) do
begin
RegisterConstructor(@TROBinaryMemoryStreamCreate2_P, 'Create2');
RegisterConstructor(@TROBinaryMemoryStreamCreate_P, 'Create');
RegisterMethod(@TROBinaryMemoryStream.Assign, 'Assign');
RegisterMethod(@TROBinaryMemoryStream.Clone, 'Clone');
RegisterMethod(@TROBinaryMemoryStream.LoadFromString, 'LoadFromString');
RegisterMethod(@TROBinaryMemoryStream.LoadFromHexString, 'LoadFromHexString');
RegisterMethod(@TROBinaryMemoryStream.ToString, 'ToString');
RegisterMethod(@TROBinaryMemoryStream.ToHexString, 'ToHexString');
RegisterMethod(@TROBinaryMemoryStream.ToReadableString, 'ToReadableString');
RegisterMethod(@TROBinaryMemoryStream.WriteAnsiString, 'WriteAnsiString');
RegisterPropertyHelper(@TROBinaryMemoryStreamCapacityIncrement_R,@TROBinaryMemoryStreamCapacityIncrement_W,'CapacityIncrement');
end;
end;
(*----------------------------------------------------------------------------*)
procedure RIRegister_uROClasses(CL: TPSRuntimeClassImporter);
begin
RIRegister_TROBinaryMemoryStream(CL);
end;
(*----------------------------------------------------------------------------*)
type
TRoObjectInstance = class;
{ }
IROClass = interface
['{246B5804-461F-48EC-B2CA-FBB7B69B0D64}']
function SLF: TRoObjectInstance;
end;
TRoObjectInstance = class(TInterfacedObject, IROClass)
private
FMessage: IROMessage;
FChannel: IROTransportChannel;
public
constructor Create;
function SLF: TRoObjectInstance;
property Message: IROMessage read FMessage write FMessage;
property Channel: IROTransportChannel read FChannel write FChannel;
end;
function CreateProc(Caller: TPSExec; p: PIFProcRec; Global, Stack: TPSStack): Boolean;
var
temp, res: TPSVariantIFC;
Chan: TROTransportChannel;
Msg: TROMessage;
NewRes: TRoObjectInstance;
begin
res := NewTPSVariantIFC(Stack[Stack.count -1], True);
if (Res.Dta = nil) or (res.aType.BaseType <> btInterface) then
begin
Caller.CMD_Err2(erCustomError, 'RO Invoker: Invalid Parameters');
Result := False;
exit;
end;
IUnknown(Res.Dta^) := nil;
NewRes := TRoObjectInstance.Create;
temp := NewTPSVariantIFC(Stack[Stack.Count -4], True);
if (temp.aType <> nil) and (temp.Dta <> nil) and (Temp.aType.BaseType = btClass) and (TObject(Temp.Dta^) is TROTransportChannel) then
Chan := TROTransportChannel(temp.dta^)
else
Chan := nil;
temp := NewTPSVariantIFC(Stack[Stack.Count -3], True);
if (temp.aType <> nil) and (temp.Dta <> nil) and (Temp.aType.BaseType = btClass) and (TObject(Temp.Dta^) is TROMessage) then
Msg := TROMessage(temp.dta^)
else
Msg := nil;
if (msg = nil) or (chan = nil) then
begin
Chan.free;
msg.Free;
NewRes.Free;
Result := false;
Caller.CMD_Err2(erCustomError, 'Could not create message');
exit;
end;
IRoClass(Res.Dta^) := NewRes;
NewRes.Message := Msg;
NewRes.Channel := Chan;
Result := True;
end;
function NilProc(Caller: TPSExec; p: PIFProcRec; Global, Stack: TPSStack): Boolean;
var
n: TPSVariantIFC;
begin
n := NewTPSVariantIFC(Stack[Stack.count -1], True);
if (n.Dta = nil) or (n.aType = nil) or (n.aType.BaseType <> btInterface) then
begin
Caller.CMD_Err2(erCustomError, 'RO Invoker: Cannot free');
Result := False;
exit;
end;
IUnknown(n.Dta^) := nil;
Result := True;
end;
type
TROStructure = class(TPersistent, IROCustomStreamableType, IROCustomStreamableStruct)
private
FVar: TPSVariantIFC;
FExec: TPSExec;
protected
function GetTypeName: string;
procedure SetTypeName(const s: string);
procedure Write(Serializer: TROSerializer; const Name: string);
procedure Read(Serializer: TROSerializer; const Name: string);
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
function CanImplementType(const aName: string):boolean;
procedure SetNull(b: Boolean);
function IsNull: Boolean;
public
constructor Create(aVar: TPSVariantIfc; Exec: TPSExec);
end;
TROArray = class(TROStructure, IROCustomStreamableType, IROCustomStreamableStruct, IROCustomStreamableArray)
protected
function GetCount: Longint;
procedure SetCount(l: Longint);
end;
procedure WriteUserDefined(Exec: TPSExec; const Msg: IROMessage; const Name: string; const n: TPSVariantIfc);
var
obj: TROStructure;
begin
if n.aType.BaseType = btArray then
obj := TROArray.Create(n, exec)
else if n.aType.BaseType = btRecord then
obj := TROStructure.Create(n, exec)
else
raise Exception.Create('Unknown custom type');
try
Msg.Write(Name, obj.ClassInfo, obj, []);
finally
obj.Free;
end;
end;
procedure ReadUserDefined(Exec: TPSExec; const Msg: IROMessage; const Name: string; const n: TPSVariantIfc);
var
obj: TROStructure;
begin
if n.aType.BaseType = btArray then
obj := TROArray.Create(n, exec)
else if n.aType.BaseType = btRecord then
obj := TROStructure.Create(n, exec)
else
raise Exception.Create('Unknown custom type');
try
Msg.Read(Name, obj.ClassInfo, obj, []);
finally
obj.Free;
end;
end;
function RoProc(Caller: TPSExec; p: TIFExternalProcRec; Global, Stack: TIfList): Boolean;
var
s, s2: string;
res, n: TPSVariantIFC;
aType: TRODataType;
aMode: TRODLParamFlag;
StartOffset, I: Longint;
__request, __response : TMemoryStream;
Inst: TRoObjectInstance;
begin
s := p.Decl;
if s[1] = #255 then
begin
n := NewTPSVariantIFC(Stack[Stack.Count -1], True);
res.Dta := nil;
res.aType := nil;
StartOffset := Stack.Count -2;
end
else
begin
n := NewTPSVariantIFC(Stack[Stack.Count -2], True);
res := NewTPSVariantIFC(Stack[Stack.Count -1], True);
StartOffset := Stack.Count -3;
end;
if (n.Dta = nil) or (N.aType = nil) or (n.aType.BaseType <> btInterface) or (Longint(n.Dta^) = 0) then
begin
Caller.CMD_Err2(erCustomError, 'RO Invoker: Invalid Parameters');
Result := False;
exit;
end;
Inst := IROClass(n.dta^).Slf;
Delete(s, 1, 1);
i := StartOffset;
try
Inst.SLF.Message.InitializeRequestMessage(Inst.Channel, '', Copy(p.Name,1,pos('.', p.Name) -1), Copy(p.Name, pos('.', p.Name)+1, MaxInt));
while Length(s) > 0 do
begin
s2 := copy(s, 2, ord(s[1]));
aMode := TRODLParamFlag(ord(s[length(s2)+2]));
aType := TRODataType(ord(s[length(s2)+3]));
Delete(s, 1, length(s2)+3);
n := NewTPSVariantIFC(Stack[i], True);
Dec(I);
if ((aMode = fIn) or (aMode = fInOut)) and (n.Dta <> nil) then
begin
case aType of
rtInteger: Inst.Message.Write(s2, TypeInfo(Integer), Integer(n.Dta^), []);
rtDateTime: Inst.Message.Write(s2, TypeInfo(DateTime), Double(n.Dta^), []);
rtDouble: Inst.Message.Write(s2, TypeInfo(Double), Double(n.Dta^), []);
rtCurrency: Inst.Message.Write(s2, TypeInfo(Double), Double(n.Dta^), []);
rtWideString: Inst.Message.Write(s2, TypeInfo(WideString), WideString(n.Dta^), []);
rtString: Inst.Message.Write(s2, TypeInfo(String), String(n.Dta^), []);
rtInt64: Inst.Message.Write(s2, TypeInfo(Int64), Int64(n.Dta^), []);
rtBoolean: Inst.Message.Write(s2, TypeInfo(Boolean), Byte(n.Dta^), []);
rtUserDefined: WriteUserDefined(Caller, Inst.Message, s2, n);
end;
end;
end;
__request := TMemoryStream.Create;
__response := TMemoryStream.Create;
try
Inst.Message.WriteToStream(__request);
Inst.Channel.Dispatch(__request, __response);
Inst.Message.ReadFromStream(__response);
finally
__request.Free;
__response.Free;
end;
s := p.Decl;
Delete(s, 1, 1);
i := StartOffset;
while Length(s) > 0 do
begin
s2 := copy(s, 2, ord(s[1]));
aMode := TRODLParamFlag(ord(s[length(s2)+2]));
aType := TRODataType(ord(s[length(s2)+3]));
Delete(s, 1, length(s2)+3);
n := NewTPSVariantIFC(Stack[i], True);
Dec(I);
if ((aMode = fOut) or (aMode = fInOut)) and (n.Dta <> nil) then
begin
case aType of
rtInteger: Inst.Message.Read(s2, TypeInfo(Integer), Longint(n.Dta^), []);
rtDateTime: Inst.Message.Read(s2, TypeInfo(DateTime), double(n.dta^), []);
rtDouble: Inst.Message.Read(s2, TypeInfo(Double), double(n.dta^), []);
rtCurrency: Inst.Message.Read(s2, TypeInfo(Double), double(n.dta^), []);
rtWideString: Inst.Message.Read(s2, TypeInfo(WideString), widestring(n.Dta^), []);
rtString: Inst.Message.Read(s2, TypeInfo(String), string(n.dta^), []);
rtInt64: Inst.Message.Read(s2, TypeInfo(Int64), Int64(n.Dta^), []);
rtBoolean: Inst.Message.Read(s2, TypeInfo(Boolean), Boolean(n.Dta^), []);
rtUserDefined: ReadUserDefined(Caller, Inst.Message, s2, n);
end;
end;
end;
aType := TRODataType(p.Decl[1]);
case aType of
rtInteger: Inst.Message.Read('Result', TypeInfo(Integer), Longint(res.Dta^), []);
rtDateTime: Inst.Message.Read('Result', TypeInfo(DateTime), Double(res.dta^), []);
rtDouble: Inst.Message.Read('Result', TypeInfo(Double), Double(res.Dta^), []);
rtCurrency: Inst.Message.Read('Result', TypeInfo(Double), double(res.Dta^), []);
rtWideString: Inst.Message.Read('Result', TypeInfo(WideString), WideString(res.Dta^), []);
rtString: Inst.Message.Read('Result', TypeInfo(String), String(res.Dta^), []);
rtInt64: Inst.Message.Read('Result', TypeInfo(Int64), Int64(res.dta^), []);
rtBoolean: Inst.Message.Read('Result', TypeInfo(Boolean), Boolean(res.dta^), []);
rtUserDefined: ReadUserDefined(Caller, Inst.Message, 'Result', res);
end;
except
on e: Exception do
begin
Caller.CMD_Err2(erCustomError, e.Message);
Result := False;
exit;
end;
end;
Result := True;
end;
function SProcImport(Sender: TPSExec; p: TIFExternalProcRec; Tag: Pointer): Boolean;
var
s: string;
begin
s := p.Decl;
Delete(s, 1, pos(':', s));
if s[1] = '-' then
p.ProcPtr := @NilProc
else if s[1] = '!' then
begin
P.ProcPtr := @CreateProc;
p.Decl := Copy(s, 2, MaxInt);
end else
begin
Delete(s, 1, 1);
p.Name := Copy(S,1,pos('!', s)-1);
Delete(s, 1, pos('!', s));
p.Decl := s;
p.ProcPtr := @RoProc;
end;
Result := True;
end;
type
TMYComp = class(TPSPascalCompiler);
TRoClass = class(TPSExternalClass)
private
FService: TRODLService;
FNilProcNo: Cardinal;
FCompProcno: Cardinal;
function CreateParameterString(l: TRODLOperation): string;
function GetDT(DataType: string): TRODataType;
procedure MakeDeclFor(Dest: TPSParametersDecl; l: TRODLOperation);
public
constructor Create(Se: TPSPascalCompiler; Service: TRODLService; Const Typeno: TPSType);
function SelfType: TPSType; override;
function Func_Find(const Name: tbtstring; var Index: Cardinal): Boolean; override;
function Func_Call(Index: Cardinal; var ProcNo: Cardinal): Boolean; override;
function SetNil(var ProcNo: Cardinal): Boolean; override;
function ClassFunc_Find(const Name: tbtstring; var Index: Cardinal): Boolean; override;
function ClassFunc_Call(Index: Cardinal; var ProcNo: Cardinal): Boolean; override;
function IsCompatibleWith(Cl: TPSExternalClass): Boolean; override;
end;
{ TROPSLink }
procedure TPSRemObjectsSdkPlugin.RODLLoadFromFile(const FileName: string);
var
f: TFileStream;
begin
f := TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone);
try
RODLLoadFromStream(f);
finally
f.Free;
end;
end;
procedure TPSRemObjectsSdkPlugin.RODLLoadFromResource;
var
rs: TResourceStream;
begin
rs := TResourceStream.Create(HInstance, 'RODLFILE', RT_RCDATA);
try
RODLLoadFromStream(rs);
finally
rs.Free;
end;
end;
procedure TPSRemObjectsSdkPlugin.RODLLoadFromStream(S: TStream);
begin
FreeAndNil(FRodl);
with TXMLToRODL.Create do
begin
try
FRodl := Read(S);
finally
Free;
end;
end;
end;
destructor TPSRemObjectsSdkPlugin.Destroy;
begin
FreeAndNil(FRodl);
FModules.Free;
inherited Destroy;
end;
{ TRoClass }
constructor TRoClass.Create(Se: TPSPascalCompiler; Service: TRODLService; Const Typeno: TPSType);
begin
inherited Create(SE, TypeNo);
FService := Service;
FNilProcNo := Cardinal(-1);
FCompProcNo := Cardinal(-1);
end;
function TRoClass.GetDT(DataType: string): TRODataType;
begin
DataType := LowerCase(DataType);
if DataType = 'integer' then
Result := rtInteger
else if DataType = 'datetime' then
Result := rtDateTime
else if DataType = 'double' then
Result := rtDouble
else if DataType = 'currency' then
Result := rtCurrency
else if DataType = 'widestring' then
Result := rtWidestring
else if DataType = 'string' then
Result := rtString
else if DataType = 'int64' then
Result := rtInt64
else if DataType = 'boolean' then
Result := rtBoolean
else if DataType = 'variant' then
Result := rtVariant
else if DataType = 'binary' then
Result := rtBinary
else
Result := rtUserDefined;
end;
function TRoClass.CreateParameterString(l: TRODLOperation): string;
var
i: Longint;
begin
if L.Result = nil then
begin
Result := #$FF;
end else
begin
Result := Chr(Ord(GetDT(l.Result.DataType)));
end;
for i := 0 to l.Count -1 do
begin
if l.Items[i].Flag = fResult then Continue;
Result := Result + Chr(Length(l.Items[i].Info.Name))+ l.Items[i].Info.Name + Chr(Ord(l.Items[i].Flag)) + Chr(Ord(GetDT(l.Items[i].DataType)));
end;
end;
procedure TRoClass.MakeDeclFor(Dest: TPSParametersDecl; l: TRODLOperation);
var
i: Longint;
dd: TPSParameterDecl;
begin
if l.Result <> nil then
begin
Dest.Result := TMyComp(SE).at2ut(SE.FindType(l.Result.DataType));
end;
for i := 0 to l.Count -1 do
begin
if l.Items[i].Flag = fResult then Continue;
dd := Dest.AddParam;
if l.Items[i].Flag = fIn then
dd.mode := pmIn
else
dd.Mode := pmInOut;
dd.OrgName := l.Items[i].Info.Name;
dd.aType := TMyComp(SE).at2ut(SE.FindType(l.Items[i].DataType));
end;
end;
function TRoClass.Func_Call(Index: Cardinal; var ProcNo: Cardinal): Boolean;
var
h, i: Longint;
s, e: string;
P: TPSProcedure;
p2: TPSExternalProcedure;
begin
s := 'roclass:_'+FService.Info.Name + '.' + FService.Default.Items[Index].Info.Name;
h := MakeHash(s);
for i := 0 to TMyComp(SE).FProcs.Count -1 do
begin
P := TMyComp(SE).FProcs[i];
if (p is TPSExternalProcedure) then
begin
p2 := TPSExternalProcedure(p);
if (p2.RegProc.NameHash = h) and (Copy(p2.RegProc.ImportDecl, 1, pos(tbtchar('!'), p2.RegProc.ImportDecl)) = s) then
begin
Procno := I;
Result := True;
Exit;
end;
end;
end;
e := CreateParameterString(FService.Default.Items[Index]);
s := s + '!' + e;
ProcNo := TMyComp(SE).AddUsedFunction2(P2);
p2.RegProc := TPSRegProc.Create;
TMYComp(SE).FRegProcs.Add(p2.RegProc);
p2.RegProc.Name := '';
p2.RegProc.ExportName := True;
MakeDeclFor(p2.RegProc.Decl, FService.Default.Items[Index]);
p2.RegProc.ImportDecl := s;
Result := True;
end;
function TRoClass.Func_Find(const Name: tbtstring; var Index: Cardinal): Boolean;
var
i: Longint;
begin
for i := 0 to FService.Default.Count -1 do
begin
if CompareText(FService.Default.Items[i].Info.Name, Name) = 0 then
begin
Index := i;
Result := True;
Exit;
end;
end;
Result := False;
end;
const
PSClassType = '!ROClass';
MyGuid: TGuid = '{CADCCF37-7FA0-452E-971D-65DA691F7648}';
function TRoClass.SelfType: TPSType;
begin
Result := SE.FindType(PSClassType);
if Result = nil then
begin
Result := se.AddInterface(se.FindInterface('IUnknown'), MyGuid, PSClassType).aType;
end;
end;
function TRoClass.SetNil(var ProcNo: Cardinal): Boolean;
var
P: TPSExternalProcedure;
begin
if FNilProcNo <> Cardinal(-1) then
ProcNo:= FNilProcNo
else
begin
ProcNo := TMyComp(SE).AddUsedFunction2(P);
p.RegProc := TPSRegProc.Create;
TMyComp(SE).FRegProcs.Add(p.RegProc);
p.RegProc.Name := '';
p.RegProc.ExportName := True;
with p.RegProc.Decl.AddParam do
begin
OrgName := 'VarNo';
aType := TMYComp(Se).at2ut(SelfType);
end;
p.RegProc.ImportDecl := 'roclass:-';
FNilProcNo := Procno;
end;
Result := True;
end;
function TRoClass.ClassFunc_Call(Index: Cardinal;
var ProcNo: Cardinal): Boolean;
var
P: TPSExternalProcedure;
begin
if FCompProcNo <> Cardinal(-1) then
begin
Procno := FCompProcNo;
Result := True;
Exit;
end;
ProcNo := TMyComp(SE).AddUsedFunction2(P);
p.RegProc := TPSRegProc.Create;
TMyComp(SE).FRegProcs.Add(p.RegProc);
p.RegProc.ExportName := True;
p.RegProc.Decl.Result := TMyComp(SE).at2ut(SelfType);
with p.RegProc.Decl.AddParam do
begin
Orgname := 'Message';
aType :=TMyComp(SE).at2ut(SE.FindType('TROMESSAGE'));
end;
with p.RegProc.Decl.AddParam do
begin
Orgname := 'Channel';
aType :=TMyComp(SE).at2ut(SE.FindType('TROTRANSPORTCHANNEL'));
end;
p.RegProc.ImportDecl := 'roclass:!';
FCompProcNo := Procno;
Result := True;
end;
function TRoClass.ClassFunc_Find(const Name: tbtstring;
var Index: Cardinal): Boolean;
begin
if Name = 'CREATE' then
begin
Result := True;
Index := 0;
end else
result := False;
end;
function TRoClass.IsCompatibleWith(Cl: TPSExternalClass): Boolean;
begin
Result := Cl is TRoClass;
end;
{ TRoObjectInstance }
function TRoObjectInstance.SLF: TRoObjectInstance;
begin
Result := Self;
end;
constructor TRoObjectInstance.Create;
begin
FRefCount := 1;
end;
function TPSRemObjectsSdkPlugin.MkStructName(Struct: TRODLStruct): string;
var
i: Longint;
begin
Result := '!ROStruct!'+Struct.Info.Name+ ',';
for i := 0 to Struct.Count -1 do
begin
Result := Result + Struct.Items[i].Info.Name+ ',';
end;
end;
function CompareStructItem(const S1, S2: TRODLTypedEntity): Integer;
begin
Result := CompareText(S1.Info.Name, S2.Info.Name);
end;
procedure SortStruct(struct: TRODLStruct; First, Last: Longint);
var
l, r, Pivot: Integer;
begin
while First < Last do
begin
Pivot := (First + Last) div 2;
l := First - 1;
r := Last + 1;
repeat
repeat inc(l); until CompareStructItem(Struct.Items[l], Struct.Items[Pivot]) >= 0;
repeat dec(r); until CompareStructItem(Struct.Items[r], Struct.Items[Pivot]) <= 0;
if l >= r then break;
Struct.Exchange(l, r);
until false;
if First < r then SortStruct(Struct, First, r);
First := r+1;
end;
end;
procedure TPSRemObjectsSdkPlugin.CompileImport1(CompExec: TPSScript);
var
i, i1: Longint;
Enum: TRODLEnum;
TempType: TPSType;
Struct: TRODLStruct;
Arr: TRODLArray;
RecType: TPSRecordFieldTypeDef;
Service: TRODLService;
begin
if FRODL = nil then exit;
if CompExec.Comp.FindType('TDateTime') = nil then
raise Exception.Create('Please register the DateUtils library first');
if CompExec.Comp.FindType('TStream') = nil then
raise Exception.Create('Please register the sysutils/classes library first');
SIRegisterTROTRANSPORTCHANNEL(CompExec.Comp);
SIRegisterTROMESSAGE(CompExec.Comp);
SIRegister_uROClasses(CompExec.Comp);
CompExec.Comp.AddTypeCopyN('Binary', 'TROBinaryMemoryStream');
if CompExec.Comp.FindType('DateTime') = nil then
CompExec.Comp.AddTypeCopyN('DateTime', 'TDateTime');
if CompExec.Comp.FindType('Currency') = nil then
CompExec.Comp.AddTypeCopyN('Currency', 'Double'); // for now
for i := 0 to FRodl.EnumCount -1 do
begin
Enum := FRodl.Enums[i];
TempType := CompExec.Comp.AddType(Enum.Info.Name, btEnum);
for i1 := 0 to Enum.Count -1 do
begin
CompExec.Comp.AddConstant(Enum.Items[i1].Info.Name, TempType).SetUInt(i1);
end;
end;
for i := 0 to FRodl.StructCount -1 do
begin
Struct := FRodl.Structs[i];
SortStruct(Struct, 0, Struct.Count-1);
TempType := CompExec.Comp.AddType('', btRecord);
TempType.ExportName := True;
TempType.Name := MkStructName(Struct);
for i1 := 0 to Struct.Count -1 do
begin
RecType := TPSRecordType(TempType).AddRecVal;
RecType.FieldOrgName := Struct.Items[i1].Info.Name;
RecType.aType := CompExec.Comp.FindType(Struct.Items[i1].DataType);
if RecType.aType = nil then begin
Arr := fRodl.FindArray(Struct.Items[i1].DataType);
if Arr <> nil then begin
RecType.aType := CompExec.Comp.AddType(Arr.Info.Name, btArray);
TPSArrayType(RecType.aType).ArrayTypeNo := CompExec.Comp.FindType(Arr.ElementType);
end;
end;
end;
CompExec.Comp.AddTypeCopy(Struct.Info.Name, TempType);
end;
for i := 0 to FRodl.ArrayCount -1 do
begin
Arr := FRodl.Arrays[i];
TempType := CompExec.Comp.FindType(Arr.Info.Name);
if TempType <> nil then begin
if not (TempType is TPSArrayType) then begin
CompExec.Comp.MakeError('ROPS', ecDuplicateIdentifier, Arr.Info.Name);
end;
end else begin
TempType := CompExec.Comp.AddType(Arr.Info.Name, btArray);
end;
TPSArrayType(TempType).ArrayTypeNo := CompExec.Comp.FindType(Arr.ElementType);
end;
for i := 0 to FRodl.ServiceCount -1 do
begin
Service := FRodl.Services[i];
TempType := CompExec.Comp.AddType(Service.Info.Name, btExtClass);
TPSUndefinedClassType(TempType).ExtClass := TRoClass.Create(CompExec.Comp, Service, TempType);
end;
for i := 0 to FModules.Count -1 do
TPSROModuleClass(FModules[i]).CompImp(CompExec.Comp);
end;
function TPSRemObjectsSdkPlugin.GetHaveRodl: Boolean;
begin
Result := FRodl <> nil;
end;
procedure TPSRemObjectsSdkPlugin.ClearRodl;
begin
FRodl.Free;
FRodl := nil;
end;
procedure TPSRemObjectsSdkPlugin.ExecImport1(CompExec: TPSScript;
const ri: TPSRuntimeClassImporter);
var
i: Longint;
begin
if FRODL = nil then exit;
CompExec.Exec.AddSpecialProcImport('roclass', SProcImport, nil);
RIRegisterTROTRANSPORTCHANNEL(ri);
RIRegisterTROMESSAGE(ri);
RIRegister_TROBinaryMemoryStream(ri);
for i := 0 to FModules.Count -1 do
TPSROModuleClass(FModules[i]).ExecImp(CompExec.Exec, ri);
end;
constructor TPSRemObjectsSdkPlugin.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FModules := TList.Create;
//FEnableSOAP := True;
FEnableBinary := True;
FEnableIndyTCP := True;
FEnableIndyHTTP := True;
end;
procedure TPSRemObjectsSdkPlugin.Loaded;
begin
inherited Loaded;
ReloadModules;
end;
procedure TPSRemObjectsSdkPlugin.RegisterModule(
Module: TPSROModuleClass);
begin
FModules.Add(Module);
end;
procedure TPSRemObjectsSdkPlugin.ReloadModules;
begin
FModules.Clear;
if FEnableIndyTCP then RegisterModule(TPSROIndyTCPModule);
if FEnableIndyHTTP then RegisterModule(TPSROIndyHTTPModule);
//if FEnableSOAP then RegisterModule(TPSROSoapModule);
if FEnableBinary then RegisterModule(TPSROBinModule);
if assigned(FOnLoadModule) then
FOnLoadModule(Self);
end;
{ TPSROModule }
class procedure TPSROModule.CompImp(comp: TPSPascalCompiler);
begin
// do nothing
end;
class procedure TPSROModule.ExecImp(exec: TPSExec;
ri: TPSRuntimeClassImporter);
begin
// do nothing
end;
procedure IntRead(Exec: TPSExec; Serializer: TROSerializer;
const Name: string; aVar: TPSVariantIFC; arridx: Longint);
var
i: Longint;
s, s2: string;
r: TROStructure;
begin
case aVar.aType.BaseType of
btS64: Serializer.Read(Name, TypeInfo(int64), Int64(avar.Dta^), arridx);
btu32: Serializer.Read(Name, TypeInfo(cardinal), Cardinal(avar.Dta^), arridx);
bts32: Serializer.Read(Name, TypeInfo(longint), Longint(avar.Dta^), arridx);
btu16: Serializer.Read(Name, TypeInfo(word), Word(aVar.Dta^), arridx);
btS16: Serializer.Read(Name, TypeInfo(smallint), Smallint(aVar.Dta^), arridx);
btu8: Serializer.Read(Name, TypeInfo(byte), Byte(aVar.Dta^), arridx);
btS8: Serializer.Read(Name, TypeInfo(shortint), Shortint(aVar.Dta^), arridx);
btDouble:
begin
if aVar.aType.ExportName = 'TDATETIME' then
Serializer.Read(Name, TypeInfo(datetime), Double(avar.Dta^), arridx)
else
Serializer.Read(Name, TypeInfo(double), Double(aVar.Dta^), arridx);
end;
btSingle: Serializer.Read(Name, TypeInfo(single), Single(avar.Dta^), arridx);
btExtended: Serializer.Read(Name, TypeInfo(extended), Extended(avar.dta^), arridx);
btWideString: Serializer.Read(Name, TypeInfo(widestring), widestring(avar.dta^), arridx);
btString: Serializer.Read(Name, TypeInfo(string), string(avar.dta^), arridx);
btArray:
begin
if (TPSTypeRec_Array(avar.aType).ArrayType.BaseType = btRecord) then
begin
for i := 0 to PSDynArrayGetLength(Pointer(aVar.Dta^), aVar.aType) -1 do
begin
r := TROStructure.Create(PSGetArrayField(avar, i), Exec);
try
Serializer.Read(Name, typeinfo(TROArray), r, i);
finally
r.Free;
end;
end;
end else if (TPSTypeRec_Array(avar.aType).ArrayType.BaseType = btArray) then
begin
for i := 0 to PSDynArrayGetLength(Pointer(aVar.Dta^), aVar.aType) -1 do
begin
r := TROArray.Create(PSGetArrayField(avar, i), Exec);
try
Serializer.Read(Name, typeinfo(TROArray), r, i);
finally