forked from grijjy/DelphiZeroMQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZMQ.Shared.pas
88 lines (72 loc) · 1.72 KB
/
ZMQ.Shared.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
unit ZMQ.Shared;
{ Shared consts, types and helpers across all ZeroMQ classes }
{$I Grijjy.inc}
interface
uses
System.SysUtils,
System.Messaging,
PascalZMQ;
const
{ Error codes }
ERR_TIMEOUT = 1;
ERR_RECV_INTERRUPTED = 2;
ERR_POLL_INTERRUPTED = 3;
ERR_CONTEXT_INTERRUPTED = 4;
ERR_INVALID_PAYLOAD = 5;
type
{ Protocol state }
TZMQState = (Idle, Bind, Connect, Connected, Disconnect, Disconnected, Shutdown);
{ Commands }
TZMQCommand = (
Ready = 1,
Heartbeat = 2,
Disconnect = 3,
WorkerMessage = 4,
ClientMessage = 5
);
{ Actions }
TZMQAction = (
Discard = 1,
Forward = 2,
SendTo = 3
);
{ Internal message }
TZMQLogMessage = class(TMessage)
private
FText: String;
public
constructor Create(AText: String);
public
property Text: String read FText;
end;
{ Command to string }
function ZMQCommandToString(const ACommand: TZMQCommand): String;
{ Log internal message }
procedure LogMessage(const AText: String);
implementation
{ TZMQLogMessage }
constructor TZMQLogMessage.Create(AText: String);
begin
inherited Create;
FText := AText;
end;
function ZMQCommandToString(const ACommand: TZMQCommand): String;
begin
case ACommand of
TZMQCommand.Ready: Result := 'READY';
TZMQCommand.Heartbeat: Result := 'HEARTBEAT';
TZMQCommand.Disconnect: Result := 'DISCONNECT';
TZMQCommand.WorkerMessage: Result := 'WORKER_MESSAGE';
TZMQCommand.ClientMessage: Result := 'CLIENT_MESSAGE';
else
Result := Ord(ACommand).ToString;
end;
end;
procedure LogMessage(const AText: String);
var
LogMessage: TZMQLogMessage;
begin
LogMessage := TZMQLogMessage.Create(AText);
TMessageManager.DefaultManager.SendMessage(nil, LogMessage);
end;
end.