CXM_generic_protocol.anubis
2.83 KB
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
/*
*
* User: David RENE
* Date: 25/04/2007
* Time: 16:20
* (c) Calexium
*
*/
read system/muscle.anubis
read system/data_io.anubis
read system/string.anubis
read tools/basis.anubis
read system/message_queue.anubis
read calexium_lib/CXM_message_constants.anubis
public define Int32 _CXM_ERROR = 0.
public define Int32 _CXM_OK = 1.
public define Int32 _CXM_UNKNOW_CMD = 2.
public type ProtocolResult:
failure,
timeout,
unknow_cmd,
error,
ok,
ok_msg(Message).
public define One
send_ACK_error
(
MessageQueue queue,
Int32 cmd_id
)=
with err_msg = message(_CXM_ACK),
forget(add_int32(err_msg, "CMD", cmd_id));
forget(add_int32(err_msg, "STATUS", _CXM_ERROR));
forget(queue.add_Message_to_send(err_msg)).
public define One
send_ACK_ok
(
MessageQueue queue,
Int32 cmd_id
)=
with ok_msg = message(_CXM_ACK),
forget(add_int32(ok_msg, "CMD", cmd_id));
forget(add_int32(ok_msg, "STATUS", _CXM_OK));
forget(queue.add_Message_to_send(ok_msg))
.
public define One
send_ACK_ok
(
MessageQueue queue,
Int32 cmd_id,
Message result
)=
with ok_msg = message(_CXM_ACK),
forget(add_int32(ok_msg, "CMD", cmd_id));
forget(add_int32(ok_msg, "STATUS", _CXM_OK));
forget(add_message(ok_msg, "RESULT", result));
forget(queue.add_Message_to_send(ok_msg))
.
public define One
send_result
(
MessageQueue queue,
Int32 cmd_id,
Maybe(Message) mb_msg
)=
if mb_msg is
{
failure then send_ACK_error(queue, cmd_id),
success(msg) then send_ACK_ok(queue, cmd_id, msg)
}
.
public define ProtocolResult
wait_for_reply
(
MessageQueue mQ,
Int32 wait_cmd,
Int32 t_out
) =
if mQ.get_next_received_Message(t_out) is
{
timeout then timeout,
closed then println("wait_for_reply closed");failure,
msg(_msg) then
if *_msg.what = _CXM_ACK then
if find_int32(_msg, "CMD") is
{
failure then println("wait_for_reply CMD");failure,
success(cmd) then
println("wait_for_reply CMD="+to_hexa(cmd));
if find_int32(_msg, "STATUS") is
{
failure then println("wait_for_reply STATUS");failure,
success(status) then
if cmd = wait_cmd & status = _CXM_OK then
if find_message(_msg, "RESULT") is
{
failure then ok,
success(ok_message) then ok_msg(ok_message)
}
else if cmd = wait_cmd & status = _CXM_ERROR then
error
else if cmd = wait_cmd & status = _CXM_UNKNOW_CMD then
unknow_cmd
else
println("wait_for_reply ");failure
}
}
else
println("wait_for_reply not ACK");failure
}.