asrt
Automated System Runtime Testing library
Loading...
Searching...
No Matches
collect.hpp
1
11#pragma once
12
13#include "../asrtc/collect.h"
14#include "../asrtl/asrt_assert.h"
15#include "../asrtl/log.h"
16#include "../asrtl/status_to_str.h"
17#include "../asrtlpp/callback.hpp"
18#include "../asrtlpp/flat_type_traits.hpp"
19#include "../asrtlpp/task.hpp"
20#include "../asrtlpp/util.hpp"
21
22namespace asrt
23{
24
27ASRT_NODISCARD inline status init(
28 ref< asrt_collect_server > srv,
29 asrt_node& prev,
30 asrt_allocator alloc,
31 uint32_t tree_block_cap,
32 uint32_t tree_node_cap )
33{
34 return asrt_collect_server_init( srv, &prev, alloc, tree_block_cap, tree_node_cap );
35}
36
39ASRT_NODISCARD inline status send_ready(
40 ref< asrt_collect_server > srv,
41 flat_id root_id,
43 uint32_t timeout )
44{
45 return asrt_collect_server_send_ready( srv, root_id, timeout, ack_cb.fn, ack_cb.ptr );
46}
47
49inline asrt_flat_tree const& tree( ref< asrt_collect_server > srv )
50{
51 return *asrt_collect_server_tree( srv );
52}
53
55ASRT_NODISCARD inline flat_id next_node_id( ref< asrt_collect_server > srv )
56{
57 return srv->next_node_id;
58}
59
61inline void deinit( ref< asrt_collect_server > srv )
62{
63 asrt_collect_server_deinit( srv );
64}
65
67struct _collect_send_ready_ctx
68{
69 using completion_signatures =
70 ecor::completion_signatures< ecor::set_value_t(), ecor::set_error_t( status ) >;
71
73 flat_id root_id;
74 uint32_t timeout;
75
76 template < typename OP >
77 void start( OP& op )
78 {
79 auto s = asrt_collect_server_send_ready(
80 srv,
81 root_id,
82 timeout,
83 +[]( void* p, enum asrt_status s ) {
84 auto& o = *static_cast< OP* >( p );
85 if ( s == ASRT_SUCCESS )
86 o.receiver.set_value();
87 else
88 o.receiver.set_error( s );
89 },
90 &op );
91 if ( s != ASRT_SUCCESS )
92 op.receiver.set_error( s );
93 }
94};
95
98using collect_send_ready_sender = ecor::sender_from< _collect_send_ready_ctx >;
99
102inline ecor::sender auto send_ready(
103 ref< asrt_collect_server > srv,
104 flat_id root_id,
105 uint32_t timeout )
106{
107 return collect_send_ready_sender{ { srv, root_id, timeout } };
108}
109
110} // namespace asrt
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee ...
Definition: callback.hpp:17
ASRT_NODISCARD flat_id next_node_id(ref< asrt_collect_server > srv)
Return the next node ID the server will assign (useful for pre-allocating root IDs).
Definition: collect.hpp:55
ecor::sender_from< _collect_send_ready_ctx > collect_send_ready_sender
Sender backing co_await send_ready(srv, root_id, timeout).
Definition: collect.hpp:98
ASRT_NODISCARD enum asrt_status init(ref< asrt_cntr_assm > assm, asrt_allocator alloc)
Initialise the controller assembly — wires controller, diag, param, collect and stream channels.
Definition: cntr_assm.hpp:25
ASRT_NODISCARD status send_ready(ref< asrt_collect_server > srv, flat_id root_id, callback< asrt_collect_ready_ack_cb > ack_cb, uint32_t timeout)
Send a READY message to the reactor to start a collection session rooted at root_id.
Definition: collect.hpp:39
asrt_flat_tree const & tree(ref< asrt_collect_server > srv)
Access the flat_tree assembled from incoming APPEND messages.
Definition: collect.hpp:49
void deinit(ref< asrt_cntr_assm > assm)
Release all resources owned by the assembly.
Definition: cntr_assm.hpp:52
A type-erasing wrapper for C-style callback + void* pairs.
Definition: callback.hpp:27
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee ...
Definition: allocator.h:28
Controller-side collect server (ASRT_COLL channel).
Definition: collect.h:55
node_id maps to blocks[node_id / node_capacity][node_id % node_capacity].
Definition: flat_tree.h:121
A node in a doubly-linked channel chain.
Definition: chann.h:122