asrt
Automated System Runtime Testing library
Loading...
Searching...
No Matches
collect.h
1
11#ifndef ASRT_COLLECT_CLIENT_H
12#define ASRT_COLLECT_CLIENT_H
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#include "../asrtl/chann.h"
19#include "../asrtl/collect_proto.h"
20#include "../asrtl/flat_tree.h"
21
23typedef asrt_send_done_cb asrt_collect_done_cb;
24
25enum asrt_collect_client_state
26{
27 ASRT_COLLECT_CLIENT_IDLE = 0,
28 ASRT_COLLECT_CLIENT_READY_RECV,
29 ASRT_COLLECT_CLIENT_READY_SENT,
30 ASRT_COLLECT_CLIENT_ACTIVE,
31 ASRT_COLLECT_CLIENT_APPEND_SENT,
32 ASRT_COLLECT_CLIENT_ERROR,
33};
34
41{
42 struct asrt_node node;
43
44 enum asrt_collect_client_state state;
45 asrt_flat_id root_id;
46 asrt_flat_id next_node_id;
47
48 struct asrt_u8d1msg ready_ack_msg;
49 struct asrt_collect_append_msg append_msg;
50
51 asrt_collect_done_cb append_done_cb;
52 void* append_done_ptr;
53};
54
57enum asrt_status asrt_collect_client_init(
58 struct asrt_collect_client* client,
59 struct asrt_node* prev );
60
63void asrt_collect_client_deinit( struct asrt_collect_client* client );
64
75enum asrt_status asrt_collect_client_append(
76 struct asrt_collect_client* client,
77 asrt_flat_id parent_id,
78 char const* key,
79 struct asrt_flat_value const* value,
80 asrt_flat_id* out_id,
81 asrt_collect_done_cb done_cb,
82 void* done_ptr );
83
85static inline enum asrt_status asrt_collect_client_append_object(
86 struct asrt_collect_client* client,
87 asrt_flat_id parent_id,
88 char const* key,
89 asrt_flat_id* out_id,
90 asrt_collect_done_cb done_cb,
91 void* done_ptr )
92{
93 struct asrt_flat_value v = { .type = ASRT_FLAT_CTYPE_OBJECT };
94 return asrt_collect_client_append( client, parent_id, key, &v, out_id, done_cb, done_ptr );
95}
96
98static inline enum asrt_status asrt_collect_client_append_array(
99 struct asrt_collect_client* client,
100 asrt_flat_id parent_id,
101 char const* key,
102 asrt_flat_id* out_id,
103 asrt_collect_done_cb done_cb,
104 void* done_ptr )
105{
106 struct asrt_flat_value v = { .type = ASRT_FLAT_CTYPE_ARRAY };
107 return asrt_collect_client_append( client, parent_id, key, &v, out_id, done_cb, done_ptr );
108}
109
111static inline enum asrt_status asrt_collect_client_append_u32(
112 struct asrt_collect_client* client,
113 asrt_flat_id parent_id,
114 char const* key,
115 uint32_t val,
116 asrt_collect_done_cb done_cb,
117 void* done_ptr )
118{
119 struct asrt_flat_value v = { .type = ASRT_FLAT_STYPE_U32 };
120 v.data.s.u32_val = val;
121 return asrt_collect_client_append( client, parent_id, key, &v, NULL, done_cb, done_ptr );
122}
123
125static inline enum asrt_status asrt_collect_client_append_i32(
126 struct asrt_collect_client* client,
127 asrt_flat_id parent_id,
128 char const* key,
129 int32_t val,
130 asrt_collect_done_cb done_cb,
131 void* done_ptr )
132{
133 struct asrt_flat_value v = { .type = ASRT_FLAT_STYPE_I32 };
134 v.data.s.i32_val = val;
135 return asrt_collect_client_append( client, parent_id, key, &v, NULL, done_cb, done_ptr );
136}
137
139static inline enum asrt_status asrt_collect_client_append_str(
140 struct asrt_collect_client* client,
141 asrt_flat_id parent_id,
142 char const* key,
143 char const* val,
144 asrt_collect_done_cb done_cb,
145 void* done_ptr )
146{
147 struct asrt_flat_value v = { .type = ASRT_FLAT_STYPE_STR };
148 v.data.s.str_val = val;
149 return asrt_collect_client_append( client, parent_id, key, &v, NULL, done_cb, done_ptr );
150}
151
153static inline enum asrt_status asrt_collect_client_append_bool(
154 struct asrt_collect_client* client,
155 asrt_flat_id parent_id,
156 char const* key,
157 uint32_t val,
158 asrt_collect_done_cb done_cb,
159 void* done_ptr )
160{
161 struct asrt_flat_value v = { .type = ASRT_FLAT_STYPE_BOOL };
162 v.data.s.bool_val = val;
163 return asrt_collect_client_append( client, parent_id, key, &v, NULL, done_cb, done_ptr );
164}
165
167static inline enum asrt_status asrt_collect_client_append_float(
168 struct asrt_collect_client* client,
169 asrt_flat_id parent_id,
170 char const* key,
171 float val,
172 asrt_collect_done_cb done_cb,
173 void* done_ptr )
174{
175 struct asrt_flat_value v = { .type = ASRT_FLAT_STYPE_FLOAT };
176 v.data.s.float_val = val;
177 return asrt_collect_client_append( client, parent_id, key, &v, NULL, done_cb, done_ptr );
178}
179
181static inline enum asrt_status asrt_collect_client_append_null(
182 struct asrt_collect_client* client,
183 asrt_flat_id parent_id,
184 char const* key,
185 asrt_collect_done_cb done_cb,
186 void* done_ptr )
187{
188 struct asrt_flat_value v = { .type = ASRT_FLAT_STYPE_NULL };
189 return asrt_collect_client_append( client, parent_id, key, &v, NULL, done_cb, done_ptr );
190}
191
193static inline asrt_flat_id asrt_collect_client_root_id( struct asrt_collect_client const* client )
194{
195 return client->root_id;
196}
197
199static inline uint8_t asrt_collect_client_is_busy( struct asrt_collect_client const* client )
200{
201 return client->state == ASRT_COLLECT_CLIENT_READY_SENT ||
202 client->state == ASRT_COLLECT_CLIENT_APPEND_SENT;
203}
204
205#ifdef __cplusplus
206}
207#endif
208
209#endif // ASRT_COLLECT_CLIENT_H
Definition: collect_proto.h:74
Reactor-side collect client (ASRT_COLL channel).
Definition: collect.h:41
asrt_flat_id root_id
Root ID from READY message.
Definition: collect.h:45
asrt_flat_id next_node_id
Next auto-assigned node ID.
Definition: collect.h:46
asrt_collect_done_cb append_done_cb
User callback, fired when append send completes.
Definition: collect.h:51
Definition: flat_tree.h:90
A node in a doubly-linked channel chain.
Definition: chann.h:122
Definition: chann.h:191