13#include "../asrtl/asrt_assert.h"
14#include "../asrtl/log.h"
15#include "../asrtl/status_to_str.h"
16#include "../asrtlpp/flat_type_traits.hpp"
17#include "../asrtlpp/util.hpp"
18#include "../asrtr/param.h"
19#include "./task_unit.hpp"
24using status = asrt_status;
28template <
typename T >
34 using cb_type = asrt_param_u32_cb;
35 static constexpr auto cb_member = &asrt_param_cb::u32;
41 using cb_type = asrt_param_i32_cb;
42 static constexpr auto cb_member = &asrt_param_cb::i32;
48 using cb_type = asrt_param_float_cb;
49 static constexpr auto cb_member = &asrt_param_cb::flt;
55 using cb_type = asrt_param_str_cb;
56 static constexpr auto cb_member = &asrt_param_cb::str;
62 using cb_type = asrt_param_bool_cb;
63 static constexpr auto cb_member = &asrt_param_cb::bln;
69 using cb_type = asrt_param_obj_cb;
70 static constexpr auto cb_member = &asrt_param_cb::obj;
76 using cb_type = asrt_param_arr_cb;
77 static constexpr auto cb_member = &asrt_param_cb::arr;
85 using cb_type = asrt_param_any_cb;
86 static constexpr auto flat_type = ASRT_FLAT_STYPE_NONE;
87 static constexpr auto cb_member = &asrt_param_cb::any;
96template <
typename T >
100template <
typename CB,
typename T >
102 has_param_query_traits< T > &&
requires(
106 param_query_traits< T >::value_type v ) {
107 { cb( c, q, v ) } -> std::same_as< void >;
112ASRT_NODISCARD
inline status
init(
113 ref< asrt_param_client > client,
118 return asrt_param_client_init( client, &prev, msg_buffer, timeout );
122ASRT_NODISCARD
inline bool ready( ref< asrt_param_client const > client )
124 return client->ready != 0;
128ASRT_NODISCARD
inline bool query_pending( ref< asrt_param_client const > client )
130 return asrt_param_query_pending( client ) != 0;
134ASRT_NODISCARD
inline flat_id root_id( ref< asrt_param_client const > client )
136 return asrt_param_client_root_id( client );
140template < has_param_query_traits T, typed_param_query_callable< T > CB >
141ASRT_NODISCARD asrt_status
146 q->cb.*traits::cb_member =
148 ( *
reinterpret_cast< CB*
>( qq->cb_ptr ) )(
149 c, qq,
static_cast< traits::value_type
>( raw ) );
152 return asrt_param_client_query( q, cl, node_id, key );
155template < has_param_query_traits T >
157 ref< asrt_param_client > cl,
166 q->cb.*traits::cb_member = cb;
168 return asrt_param_client_query( q, cl, node_id, key );
172ASRT_NODISCARD
inline asrt_status
query(
173 ref< asrt_param_client > cl,
177 asrt_param_any_cb cb,
183 return asrt_param_client_query( q, cl, node_id, key );
190template < has_param_query_traits T, typed_param_query_callable< T > CB >
191ASRT_NODISCARD asrt_status
194 return query< T >( cl, q, node_id,
nullptr, cb );
199template < has_param_query_traits T >
201 ref< asrt_param_client > cl,
207 return query< T >( cl, q, node_id,
nullptr, cb, cb_ptr );
211ASRT_NODISCARD
inline asrt_status
fetch(
212 ref< asrt_param_client > cl,
215 asrt_param_any_cb cb,
218 return query( cl, q, node_id,
nullptr, cb, cb_ptr );
222template < has_param_query_traits T, typed_param_query_callable< T > CB >
223ASRT_NODISCARD asrt_status
226 return query< T >( cl, q, parent_id, key, cb );
230template < has_param_query_traits T >
231ASRT_NODISCARD asrt_status
find(
232 ref< asrt_param_client > cl,
239 return query< T >( cl, q, parent_id, key, cb, cb_ptr );
243ASRT_NODISCARD
inline asrt_status
find(
244 ref< asrt_param_client > cl,
248 asrt_param_any_cb cb,
251 return query( cl, q, parent_id, key, cb, cb_ptr );
255inline void deinit( ref< asrt_param_client > client )
257 asrt_param_client_deinit( client );
262template < has_param_query_traits T >
269 flat_id next_sibling;
271 operator value_type()
const {
return value; }
277template < has_param_query_traits T >
278struct _param_query_ctx
280 using completion_signatures = ecor::completion_signatures<
282 ecor::set_error_t( status ) >;
289 template <
typename OP >
292 using traits = param_query_traits< T >;
294 auto* o =
static_cast< OP*
>( q->cb_ptr );
295 if ( q->error_code != ASRT_PARAM_ERR_NONE )
296 o->receiver.set_error( ASRT_RECV_ERR );
298 o->receiver.set_value( param_result< T >{
299 static_cast< traits::value_type
>( raw ),
303 auto s = query< T >( client, &q, node_id, key, cb, &op );
304 if ( s != ASRT_SUCCESS )
305 op.receiver.set_error( ASRT_RECV_ERR );
311template < has_param_query_traits T >
315template <
typename T >
316ecor::sender
auto fetch( ref< asrt_param_client > client, flat_id node_id )
322template <
typename T >
323ecor::sender
auto find( ref< asrt_param_client > client, flat_id parent_id,
char const* key )
330inline ecor::sender
auto fetch( ref< asrt_param_client > client, flat_id node_id )
337inline ecor::sender
auto find( ref< asrt_param_client > client, flat_id parent_id,
char const* key )
Concept: CB is a typed callback for T (callable as cb(client*, query*, value_type)).
Definition: param.hpp:101
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee ...
Definition: callback.hpp:17
ASRT_NODISCARD asrt_status query(ref< asrt_param_client > cl, asrt_param_query *q, flat_id node_id, char const *key, CB &cb)
Submit a typed QUERY or FIND_BY_KEY.
Definition: param.hpp:142
ASRT_NODISCARD bool query_pending(ref< asrt_param_client const > client)
Returns true if a query is currently in flight.
Definition: param.hpp:128
ASRT_NODISCARD asrt_status find(ref< asrt_param_client > cl, asrt_param_query *q, flat_id parent_id, char const *key, CB &cb)
Find child with key under parent_id, call cb with the value if successful.
Definition: param.hpp:224
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
void deinit(ref< asrt_cntr_assm > assm)
Release all resources owned by the assembly.
Definition: cntr_assm.hpp:52
ecor::sender_from< _param_query_ctx< T > > param_query_sender
Sender backing co_await fetch<T> and co_await find<T>.
Definition: param.hpp:312
ASRT_NODISCARD bool ready(ref< asrt_param_client const > client)
Returns true once the controller's READY has been received.
Definition: param.hpp:122
ASRT_NODISCARD asrt_status fetch(ref< asrt_param_client > cl, asrt_param_query *q, flat_id node_id, CB &cb)
Fetch information about node node_id from param client, call cb with the value if successful.
Definition: param.hpp:192
Tag type representing a flat-tree ARRAY container node.
Definition: flat_type_traits.hpp:28
Trait mapping a C++ type to its flat_tree metadata.
Definition: flat_type_traits.hpp:38
Tag type representing a flat-tree OBJECT container node.
Definition: flat_type_traits.hpp:24
Trait mapping a C++ type T to its corresponding C callback type and asrt_param_cb union member pointe...
Definition: param.hpp:29
Result of a completed param query.
Definition: param.hpp:264
Definition: flat_tree.h:90
A node in a doubly-linked channel chain.
Definition: chann.h:122
Param client module — PARAM channel, reactor side.
Definition: param.h:47
Active query state for a pending QUERY or FIND_BY_KEY request.
Definition: param.h:149
asrt_flat_value_type expected_type
Type filter; NONE means accept any type.
Definition: param.h:155
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee ...
Definition: span.h:23