-
Notifications
You must be signed in to change notification settings - Fork 49
/
ZMQ.ClientProtocol.pas
78 lines (63 loc) · 1.78 KB
/
ZMQ.ClientProtocol.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
unit ZMQ.ClientProtocol;
{ Base class for ZeroMQ client protocol }
{$I Grijjy.inc}
interface
uses
PascalZMQ,
System.SysUtils,
System.Classes,
ZMQ.Protocol,
ZMQ.Shared;
type
{ This event is called whenever a new message is received by the client }
TOnRecv = procedure(const AService: String; const AMsg: PZMessage) of object;
{ Client interface }
TZMQClientProtocol = class(TZMQProtocol)
private
{ Internal }
FOnRecv: TOnRecv;
protected
{ This method is called when recv is idle, so that the parent can
perform other background tasks while connected }
procedure DoIdle; override;
{ This method is called whenever a new message is received by the client }
procedure DoRecv(const ACommand: TZMQCommand; var AMsg: PZMessage;
var ASentFrom: PZFrame); override;
public
constructor Create;
destructor Destroy; override;
{ Sends a message to the specified service }
procedure Send(const AService: String; var AMsg: PZMessage); virtual;
{ This event is called whenever a new message is received by the client }
property OnRecv: TOnRecv read FOnRecv write FOnRecv;
end;
implementation
constructor TZMQClientProtocol.Create;
begin
inherited Create;
end;
destructor TZMQClientProtocol.Destroy;
begin
inherited;
end;
procedure TZMQClientProtocol.DoIdle;
begin
inherited;
end;
procedure TZMQClientProtocol.DoRecv(const ACommand: TZMQCommand;
var AMsg: PZMessage; var ASentFrom: PZFrame);
var
Service: String;
begin
inherited;
Service := AMsg.PopString;
if Assigned(FOnRecv) then
FOnRecv(Service, AMsg);
end;
procedure TZMQClientProtocol.Send(const AService: String; var AMsg: PZMessage);
begin
AMsg.PushString(AService);
AMsg.PushEnum<TZMQCommand>(TZMQCommand.ClientMessage);
inherited Send(AMsg);
end;
end.