7#ifndef ZEPHYR_INCLUDE_ZBUS_PROXY_AGENT_ZBUS_PROXY_AGENT_H_
8#define ZEPHYR_INCLUDE_ZBUS_PROXY_AGENT_ZBUS_PROXY_AGENT_H_
163#define ZBUS_PROXY_AGENT_DEFINE(_name, _type, _backend_dt_node) \
164 _ZBUS_PROXY_AGENT_BACKEND_CONFIG_DEFINE(_name, _type, _backend_dt_node) \
165 K_THREAD_STACK_DEFINE(_name##_thread_stack, \
166 CONFIG_ZBUS_PROXY_AGENT_WORK_QUEUE_STACK_SIZE); \
167 K_MSGQ_DEFINE_STATIC_TYPE(_name##_rx_msgq, struct zbus_proxy_agent_rx_msg, \
168 CONFIG_ZBUS_PROXY_AGENT_RX_QUEUE_DEPTH); \
169 static struct k_thread _name##_thread; \
170 static k_tid_t _name##_thread_id; \
171 const struct zbus_proxy_agent _name = { \
173 .backend_config = _ZBUS_PROXY_AGENT_GET_BACKEND_CONFIG(_name, _type), \
174 .backend_api = _ZBUS_PROXY_AGENT_GET_BACKEND_API(_type), \
175 .thread = &_name##_thread, \
176 .msgq = &_name##_rx_msgq, \
177 .stack = _name##_thread_stack, \
178 .thread_id = &_name##_thread_id, \
180 static void _name##_zbus_listener_cb(const struct zbus_channel *chan) \
182 zbus_proxy_agent_listener_cb(chan, &_name); \
184 ZBUS_LISTENER_DEFINE(_name##_listener, _name##_zbus_listener_cb); \
185 _ZBUS_PROXY_AGENT_GENERATE_SHADOW_VALIDATOR(_name); \
186 static int _name##_init(void) \
188 return zbus_init_proxy_agent(&_name); \
190 SYS_INIT(_name##_init, APPLICATION, CONFIG_ZBUS_PROXY_AGENT_INIT_PRIORITY)
200#define _ZBUS_PROXY_AGENT_BACKEND_CONFIG_DEFINE(_name, _type, _backend_dt_node) \
201 _ZBUS_PROXY_AGENT_BACKEND_CONFIG_DEFINE_##_type(_name, _backend_dt_node)
209#define _ZBUS_PROXY_AGENT_GET_BACKEND_CONFIG(_name, _type) \
210 _ZBUS_PROXY_AGENT_GET_BACKEND_CONFIG_##_type(_name)
217#define _ZBUS_PROXY_AGENT_GET_BACKEND_API(_type) _ZBUS_PROXY_AGENT_GET_BACKEND_API_##_type
225void zbus_proxy_agent_log_shadow_pub_denied(
const struct zbus_proxy_agent *agent);
233#define _ZBUS_PROXY_AGENT_VALIDATOR(_proxy_name) _proxy_name##_shadow_validator
243#define _ZBUS_PROXY_AGENT_GENERATE_SHADOW_VALIDATOR(_proxy_name) \
244 bool _proxy_name##_shadow_validator(const void *msg, size_t msg_size) \
249 if (k_current_get() != *_proxy_name.thread_id) { \
250 zbus_proxy_agent_log_shadow_pub_denied(&_proxy_name); \
270#define ZBUS_PROXY_ADD_CHAN(_agent, _chan) \
271 ZBUS_CHAN_ADD_OBS(_chan, _agent##_listener, zz)
281#define _ZBUS_SHADOW_CHAN_REGISTER(_name, _proxy_name) \
282 extern const struct zbus_proxy_agent _proxy_name; \
283 static const STRUCT_SECTION_ITERABLE(zbus_shadow_channel, \
284 _CONCAT(_zbus_shadow_chan_, _name)) = { \
286 .proxy_agent = &_proxy_name, \
304#define ZBUS_SHADOW_CHAN_DEFINE(_name, _type, _proxy_name, _user_data, _observers, _init_val) \
305 ZBUS_CHAN_DEFINE(_name, _type, _ZBUS_PROXY_AGENT_VALIDATOR(_proxy_name), _user_data, \
306 _observers, _init_val); \
307 _ZBUS_SHADOW_CHAN_REGISTER(_name, _proxy_name)
323#define ZBUS_SHADOW_CHAN_DEFINE_WITH_ID(_name, _id, _type, _proxy_name, _user_data, _observers, \
325 ZBUS_CHAN_DEFINE_WITH_ID(_name, _id, _type, _ZBUS_PROXY_AGENT_VALIDATOR(_proxy_name), \
326 _user_data, _observers, _init_val); \
327 _ZBUS_SHADOW_CHAN_REGISTER(_name, _proxy_name)
struct z_thread_stack_element k_thread_stack_t
Typedef of struct z_thread_stack_element.
Definition arch_interface.h:46
int(* zbus_proxy_agent_recv_cb_t)(const struct zbus_proxy_agent *agent, const struct zbus_proxy_msg *msg)
Type definition for the proxy agent receive callback function.
Definition zbus_proxy_agent.h:111
zbus_proxy_agent_backend_type
Enum for supported proxy agent backend types.
Definition zbus_proxy_agent.h:36
int zbus_init_proxy_agent(const struct zbus_proxy_agent *agent)
Internal proxy agent receive callback.
void zbus_proxy_agent_listener_cb(const struct zbus_channel *chan, const struct zbus_proxy_agent *agent)
Internal proxy agent listener callback.
@ ZBUS_PROXY_AGENT_BACKEND_IPC
IPC backend for inter-process communication.
Definition zbus_proxy_agent.h:38
struct k_thread * k_tid_t
Definition thread.h:383
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Message Queue Structure.
Definition kernel.h:5316
Thread Structure.
Definition thread.h:259
Type used to represent a channel.
Definition zbus.h:99
Backend API structure for proxy agent backends.
Definition zbus_proxy_agent.h:117
int(* backend_send)(const struct zbus_proxy_agent *agent, struct zbus_proxy_msg *msg)
Send function for the backend.
Definition zbus_proxy_agent.h:121
int(* backend_set_recv_cb)(const struct zbus_proxy_agent *agent, zbus_proxy_agent_recv_cb_t recv_cb)
Function to set the receive callback for incoming messages.
Definition zbus_proxy_agent.h:123
int(* backend_init)(const struct zbus_proxy_agent *agent)
Initializer function for the backend.
Definition zbus_proxy_agent.h:119
Internal thread payload for validated received messages.
Definition zbus_proxy_agent.h:71
const struct zbus_channel * chan
Resolved shadow channel that will receive the message.
Definition zbus_proxy_agent.h:73
uint8_t message[CONFIG_ZBUS_PROXY_AGENT_MAX_MESSAGE_SIZE]
Binary message data.
Definition zbus_proxy_agent.h:75
Structure for proxy agent configuration.
Definition zbus_proxy_agent.h:83
k_thread_stack_t * stack
Stack for the dedicated proxy agent thread.
Definition zbus_proxy_agent.h:95
const struct zbus_proxy_agent_backend_api * backend_api
Backend API determined at compile-time based on backend type.
Definition zbus_proxy_agent.h:89
const void * backend_config
Backend specific configuration.
Definition zbus_proxy_agent.h:87
const char * name
The name of the proxy agent.
Definition zbus_proxy_agent.h:85
struct k_thread * thread
Dedicated thread used to process received proxy messages.
Definition zbus_proxy_agent.h:91
struct k_msgq * msgq
msgq for received proxy messages
Definition zbus_proxy_agent.h:93
k_tid_t *const thread_id
Pointer to the thread ID of the dedicated proxy agent thread.
Definition zbus_proxy_agent.h:97
Structure for proxy agent message.
Definition zbus_proxy_agent.h:57
uint32_t message_size
Size of the message data.
Definition zbus_proxy_agent.h:59
uint32_t channel_name_len
Length of the channel name including the NUL terminator.
Definition zbus_proxy_agent.h:63
char channel_name[CONFIG_ZBUS_PROXY_AGENT_MAX_CHANNEL_NAME_SIZE]
Channel name associated with the message.
Definition zbus_proxy_agent.h:65
uint8_t message[CONFIG_ZBUS_PROXY_AGENT_MAX_MESSAGE_SIZE]
Binary message data.
Definition zbus_proxy_agent.h:61
Metadata for shadow channels to track their ownership by proxy agents.
Definition zbus_proxy_agent.h:44
const struct zbus_proxy_agent * proxy_agent
Pointer to the proxy agent that owns this shadow channel.
Definition zbus_proxy_agent.h:48
const struct zbus_channel * chan
Pointer to the shadow channel.
Definition zbus_proxy_agent.h:46
Iterable sections helpers.