-
Notifications
You must be signed in to change notification settings - Fork 9
/
GS.Pixel.Service.pas
100 lines (81 loc) · 2.34 KB
/
GS.Pixel.Service.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
//Bus based service access.
// - Allow to have easy, transparent, and full multithreading capabilities (throught bus)
// - Allow easy move to a full C/S (GRID or other) system.
// - Allow to not blow your project with dozen of units, which their own geometry/logic system.
// - Allow to use powerfull third part lib, to give acces to their magic, with no technical hassle.
unit GS.Pixel.Service;
interface
uses classes, sysutils, GS.Pixel, GS.Bus, GS.Stream;
Type
TPixelCustomService = class(TPixelInterfacedObject,iPixService)
protected
furi : string;
fcli : TBusClientReader;
fcontent, freport : TMemoryStream;
//Bus related.
Procedure IncomingMessage(Sender : TBusSystem; aReader : TBusClientReader; Var Packet : TBusEnvelop);
public
Constructor Create(_uri : string); reintroduce;
Destructor Destroy; override;
//iPixSurface
function uri : string; virtual;
function id : string; virtual; abstract;
procedure Ask(param : TStream); virtual;
procedure Answer(content : TStream; success : boolean; report : TStream); virtual; abstract;
end;
implementation
{ TPixel32CustomPXLService }
procedure TPixelCustomService.Ask(param: TStream);
var mes : TBusMessage;
begin
assert(assigned(param));
param.Position := 0;
mes.FromStream(param);
Bus.Send(mes,furi,'','',False,id,'');
end;
constructor TPixelCustomService.Create(_uri: string);
begin
assert(length(trim(_uri))>0);
inherited create;
furi := trim(lowercase(_uri));
fcli := Bus.Subscribe(_Uri,IncomingMessage);
fcontent := TMemoryStream.Create;
freport := TMemoryStream.Create;
end;
destructor TPixelCustomService.Destroy;
begin
Bus.UnSubscribe(fCli);
FreeAndNil(fcli);
FreeAndNil(freport);
FreeAndNil(fcontent);
inherited;
end;
procedure TPixelCustomService.IncomingMessage(Sender: TBusSystem;
aReader: TBusClientReader; var Packet: TBusEnvelop);
var l : TMemoryStream;
r : Boolean;
begin
if Packet.ClientSourceId = id then
begin
l := Packet.ContentMessage.AsStream;
try
fcontent.Clear;
freport.Clear;
ReadStream(l,TStream(fcontent));
r := ReadBoolean(l);
ReadStream(l,TStream(freport));
Answer(fcontent,r,freport);
finally
FreeAndNil(l);
end;
end;
end;
function TPixelCustomService.uri: string;
begin
result := furi;
end;
initialization
StartStandartBus;
finalization
ReleaseStandartBus;
end.