LibJuno 1.0.4
LibJuno is a lightweight C11 library designed specifically for embedded systems.
Loading...
Searching...
No Matches
broker_api.h
Go to the documentation of this file.
1/*
2 MIT License
3
4 Copyright (c) 2025 Robin A. Onsay
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files
8 (the "Software"), to deal in the Software without restriction,
9 including without limitation the rights to use, copy, modify, merge,
10 publish, distribute, sublicense, and/or sell copies of the Software,
11 and to permit persons to whom the Software is furnished to do so,
12 subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be
15 included in all copies or substantial portions of the Software.
16*/
17
50// @{"req": ["REQ-SB-013"]}
51#ifndef JUNO_SB_API_H
52#define JUNO_SB_API_H
53#include "juno/ds/array_api.h"
54#include "juno/macros.h"
56#include "juno/status.h"
57#include "juno/module.h"
58#include "juno/ds/queue_api.h"
59#include <stddef.h>
60#include <stdint.h>
61#ifdef __cplusplus
62extern "C"
63{
64#endif
65
66typedef struct JUNO_SB_BROKER_ROOT_TAG JUNO_SB_BROKER_ROOT_T;
68typedef struct JUNO_SB_PIPE_TAG JUNO_SB_PIPE_T;
69typedef uint32_t JUNO_SB_MID_T;
70
72// @{"req": ["REQ-SB-004"]}
75 JUNO_SB_MID_T iMsgId;
76);
77
79// @{"req": ["REQ-SB-001"]}
80struct JUNO_SB_BROKER_ROOT_TAG JUNO_MODULE_ROOT(JUNO_SB_BROKER_API_T,
82 JUNO_SB_PIPE_T **ptPipeRegistry;
84 size_t zRegistryLength;
86 size_t zRegistryCapacity;
87);
88
89// @{"req": ["REQ-SB-002"]}
100
103{
105 ptBrokerApi &&
106 ptBrokerApi->Publish &&
107 ptBrokerApi->RegisterSubscriber
108 );
109 return JUNO_STATUS_SUCCESS;
110}
111
113// @{"req": ["REQ-SB-010", "REQ-SB-011"]}
115{
117 JUNO_ASSERT_EXISTS(ptBroker);
118 tStatus = JunoSb_BrokerApiVerify(ptBroker->ptApi);
119 JUNO_ASSERT_SUCCESS(tStatus, return tStatus);
120 JUNO_ASSERT_EXISTS(ptBroker->ptPipeRegistry && ptBroker->zRegistryCapacity);
121 return tStatus;
122}
123
125// @{"req": ["REQ-SB-012"]}
127{
128 JUNO_ASSERT_EXISTS(ptPipe);
129 JUNO_STATUS_T tStatus = JunoDs_QueueVerify(&ptPipe->tRoot);
130 JUNO_ASSERT_SUCCESS(tStatus, return tStatus);
131 return tStatus;
132}
133
135JUNO_STATUS_T JunoSb_BrokerInit(JUNO_SB_BROKER_ROOT_T *ptBroker, JUNO_SB_PIPE_T **ptPipeRegistry, size_t iRegistryCapacity, JUNO_FAILURE_HANDLER_T pfcnFailureHdlr, JUNO_USER_DATA_T *pvFailureUserData);
136
138// @{"req": ["REQ-SB-005"]}
139static inline JUNO_STATUS_T JunoSb_PipeInit(JUNO_SB_PIPE_T *ptPipe, JUNO_SB_MID_T iMid, JUNO_DS_ARRAY_ROOT_T *ptArray, JUNO_FAILURE_HANDLER_T pfcnFailureHandler, JUNO_USER_DATA_T *pvUserData)
140{
141 JUNO_ASSERT_EXISTS(ptPipe);
142 ptPipe->iMsgId = iMid;
143 return JunoDs_QueueInit(&ptPipe->tRoot, ptArray, pfcnFailureHandler, pvUserData);
144}
145
146#ifdef __cplusplus
147}
148#endif
149#endif // JUNO_SB_API_H
Abstract fixed-capacity array interface for DS modules.
struct JUNO_DS_ARRAY_ROOT_TAG JUNO_DS_ARRAY_ROOT_T
Opaque array root carrying capacity and API pointer.
Definition array_api.h:58
static JUNO_STATUS_T JunoSb_PipeInit(JUNO_SB_PIPE_T *ptPipe, JUNO_SB_MID_T iMid, JUNO_DS_ARRAY_ROOT_T *ptArray, JUNO_FAILURE_HANDLER_T pfcnFailureHandler, JUNO_USER_DATA_T *pvUserData)
Initialize a pipe for a specific MID backed by a queue over ptArray.
Definition broker_api.h:139
struct JUNO_SB_BROKER_ROOT_TAG JUNO_SB_BROKER_ROOT_T
Definition broker_api.h:66
static JUNO_STATUS_T JunoSb_BrokerApiVerify(const JUNO_SB_BROKER_API_T *ptBrokerApi)
Verify a broker API table has required functions.
Definition broker_api.h:102
uint32_t JUNO_SB_MID_T
Definition broker_api.h:69
static JUNO_STATUS_T JunoSb_PipeVerify(const JUNO_SB_PIPE_T *ptPipe)
Verify a pipe instance.
Definition broker_api.h:126
JUNO_STATUS_T JunoSb_BrokerInit(JUNO_SB_BROKER_ROOT_T *ptBroker, JUNO_SB_PIPE_T **ptPipeRegistry, size_t iRegistryCapacity, JUNO_FAILURE_HANDLER_T pfcnFailureHdlr, JUNO_USER_DATA_T *pvFailureUserData)
Initialize a broker with a pipe registry storage array.
Definition juno_broker.c:36
static JUNO_STATUS_T JunoSb_BrokerVerify(const JUNO_SB_BROKER_ROOT_T *ptBroker)
Verify a broker instance and basic registry invariants.
Definition broker_api.h:114
struct JUNO_SB_PIPE_TAG JUNO_SB_PIPE_T
Definition broker_api.h:68
#define JUNO_ASSERT_EXISTS(ptr)
Returns JUNO_STATUS_NULLPTR_ERROR if the expression is falsy.
Definition macros.h:51
#define JUNO_ASSERT_SUCCESS(tStatus,...)
Execute the provided failure operation(s) if status is not success.
Definition macros.h:89
#define JUNO_MODULE_DERIVE(ROOT_T,...)
Implement a derived module embedding the root as the first member.
Definition module.h:161
#define JUNO_MODULE_ROOT(API_T,...)
Implement a module root struct containing ptApi and failure fields.
Definition module.h:129
#define JUNO_STATUS_SUCCESS
Operation completed successfully.
Definition status.h:59
void(* JUNO_FAILURE_HANDLER_T)(JUNO_STATUS_T tStatus, const char *pcCustomMessage, JUNO_USER_DATA_T *pvUserData)
Failure handler callback signature.
Definition status.h:110
int32_t JUNO_STATUS_T
Canonical status type for LibJuno functions.
Definition status.h:51
void JUNO_USER_DATA_T
Opaque user data type for failure callbacks.
Definition status.h:101
Common assertion and helper macros for LibJuno modules.
Module system and dependency injection primitives for LibJuno.
Pointer trait and helpers for memory operations.
struct JUNO_POINTER_TAG JUNO_POINTER_T
Definition pointer_api.h:49
Fixed-capacity FIFO queue built on the Array API.
JUNO_STATUS_T JunoDs_QueueInit(JUNO_DS_QUEUE_ROOT_T *ptQueue, JUNO_DS_ARRAY_ROOT_T *ptQueueArray, JUNO_FAILURE_HANDLER_T pfcnFailureHdlr, JUNO_USER_DATA_T *pvFailureUserData)
Initialize a queue over a backing array with a given capacity.
Definition juno_buff_queue.c:107
struct JUNO_DS_QUEUE_ROOT_TAG JUNO_DS_QUEUE_ROOT_T
The queue root module.
Definition queue_api.h:65
static JUNO_STATUS_T JunoDs_QueueVerify(const JUNO_DS_QUEUE_ROOT_T *ptQueue)
Verify a queue instance and its API table.
Definition queue_api.h:117
Status codes and failure-handling helpers for LibJuno.
Definition broker_api.h:91
JUNO_STATUS_T(* RegisterSubscriber)(JUNO_SB_BROKER_ROOT_T *ptBroker, JUNO_SB_PIPE_T *ptPipe)
Register a subscriber pipe with the broker.
Definition broker_api.h:98
JUNO_STATUS_T(* Publish)(JUNO_SB_BROKER_ROOT_T *ptBroker, JUNO_SB_MID_T tMid, JUNO_POINTER_T tMsg)
Publish a message to all subscribers of tMid.
Definition broker_api.h:96