Solaris Software
Loading...
Searching...
No Matches
pubsub.h
Go to the documentation of this file.
1/**
2 * @file pubsub.h
3 * @brief Publish-subscribe packet router.
4 */
5
6#ifndef SPP_PUBSUB_H
7#define SPP_PUBSUB_H
8
9#include "spp/core/packet.h"
10#include "spp/core/types.h"
13#include "spp/util/macros.h"
14
15
16/* ----------------------------------------------------------------
17 * CONSTANTS
18 * ---------------------------------------------------------------- */
19#define K_SPP_SERVICES_PUBSUB_MAX_PRODUCERS (5U)
20#define K_SPP_SERVICES_PUBSUB_MAX_CONSUMERS (5U)
21#define K_SPP_SERVICES_PUBSUB_BUFFER_SIZE (128U) /**< Internal packet buffer depth. */
22#define K_SPP_SERVICES_PUBSUB_PREEMPT_PRIORITY (1U)
23
24#define K_SPP_SERVICES_PUBSUB_STEP (1U) /**< Step to increment circular buffer index. */
25#define K_SPP_SERVICES_PUBSUB_SORT_START_INDEX (1U) /**< Starting index for insertion sort. */
26#define K_SPP_SERVICES_PUBSUB_OFFSET (1U) /**< Array index offset. */
27#define K_SPP_SERVICES_PUBSUB_ZERO_INDEX (0) /**< Zero index/value for comparisons. */
28
29/* ----------------------------------------------------------------
30 * PUBLIC FUNCTIONS
31 * ---------------------------------------------------------------- */
32
33/**
34 * @brief Registers a producer and assigns it a unique KPID.
35 * @param p_producerData Pointer to the producer contract.
36 * @param p_assignedKpid Pointer where the assigned KPID is stored.
37 * @return K_SPP_OK, K_SPP_ERROR_NULL_POINTER or K_SPP_ERROR_REGISTRY_FULL.
38 */
40
41 /**
42 * @brief Registers a consumer with its KPID subscription bitmask.
43 * @param p_consumerData Pointer to the consumer contract.
44 * @param subscription KPID bitmask identifying subscribed producers.
45 * @return K_SPP_OK, K_SPP_ERROR_NULL_POINTER or K_SPP_ERROR_REGISTRY_FULL.
46 */
47 SPP_Kpid_t *p_assignedKpid);
49 SPP_Kpid_t subscription);
50
51/**
52 * @brief Sorts consumers by priority and initializes registered modules.
53 *
54 * Consumers are initialized before producers. Individual initialization
55 * results are stored for later inspection.
56 *
57 * @return K_SPP_OK. Individual module failures do not change this return value.
58 */
60
61/**
62 * @brief Copies a packet into the internal buffer and returns it to the databank.
63 *
64 * Called by producers after filling a packet. The packet is copied by value
65 * into the next free slot of the internal circular buffer; the original is
66 * returned to the databank pool immediately. Returns K_SPP_ERROR if the
67 * buffer is full (packet is still returned to the pool).
68 *
69 * @param p_pkt Packet to publish (ownership transferred — do not use after this call).
70 * @return K_SPP_OK on success, K_SPP_ERROR_NULL_POINTER if p_pkt is NULL,
71 * K_SPP_ERROR if the buffer is full.
72 */
74
75/**
76 * @brief Calls acquireData on every successfully initialized producer.
77 */
79
80/**
81 * @brief Dispatches one buffered packet and executes initialized consumers.
82 *
83 * Consumers execute in ascending priority order. Lower-priority consumers
84 * may be skipped when a producer signals that new data is ready.
85 */
87
88/**
89 * @brief Returns the number of packets currently held in the internal FIFO buffer.
90 */
92
93/**
94 * @brief Signals that a producer has new data pending.
95 *
96 * Must be called from within acquireData() as soon as a DRDY flag is detected,
97 * so that callConsumers() can preempt consumers with priority > K_SPP_SERVICES_PUBSUB_PREEMPT_PRIORITY.
98 */
100
101/**
102 * @brief Retrieves the initialization result of a registered producer.
103 * @param p_producerData Pointer to the producer contract.
104 * @param p_initResult Output pointer for the initialization result.
105 * @return K_SPP_OK if found, K_SPP_ERROR if not registered,
106 * or K_SPP_ERROR_NULL_POINTER for invalid pointers.
107 */
109 SPP_RetVal_t *p_initResult);
110
111/**
112 * @brief Retrieves the initialization result of a registered consumer.
113 * @param p_consumerData Pointer to the consumer contract.
114 * @param p_initResult Output pointer for the initialization result.
115 * @return K_SPP_OK if found, K_SPP_ERROR if not registered,
116 * or K_SPP_ERROR_NULL_POINTER for invalid pointers.
117 */
119 SPP_RetVal_t *p_initResult);
120#endif /* SPP_PUBSUB_H */
Compile-time configuration flags and utility macros for SPP.
Solaris Packet Protocol (SPP) packet structure definitions.
SPP_Packet_t
Definition packet.h:79
SPP_RetVal_t SPP_SERVICES_PUBSUB_getConsumerInitResult(const SPP_SERVICE_ConsumerContract_t *p_consumerData, SPP_RetVal_t *p_initResult)
Retrieves the initialization result of a registered consumer.
Definition pubsub.c:225
void SPP_SERVICES_PUBSUB_signalProducerReady(void)
Signals that a producer has new data pending.
Definition pubsub.c:184
void SPP_SERVICES_PUBSUB_callConsumers(void)
Dispatches one buffered packet and executes initialized consumers.
Definition pubsub.c:152
SPP_RetVal_t SPP_SERVICES_PUBSUB_init(void)
Sorts consumers by priority and initializes registered modules.
Definition pubsub.c:189
spp_uint8_t SPP_SERVICES_PUBSUB_queueDepth(void)
Returns the number of packets currently held in the internal FIFO buffer.
Definition pubsub.c:179
void SPP_SERVICES_PUBSUB_callProducers(void)
Calls acquireData on every successfully initialized producer.
Definition pubsub.c:115
SPP_RetVal_t SPP_SERVICES_PUBSUB_getProducerInitResult(const SPP_SERVICE_ProducerContract_t *p_producerData, SPP_RetVal_t *p_initResult)
Retrieves the initialization result of a registered producer.
Definition pubsub.c:206
SPP_RetVal_t SPP_SERVICES_PUBSUB_registerProducer(const SPP_SERVICE_ProducerContract_t *p_producerData, SPP_Kpid_t *p_assignedKpid)
Registers a producer and assigns it a unique KPID.
Definition pubsub.c:54
SPP_RetVal_t SPP_SERVICES_PUBSUB_publish(SPP_Packet_t *p_pkt)
Copies a packet into the internal buffer and returns it to the databank.
Definition pubsub.c:129
SPP_RetVal_t SPP_SERVICES_PUBSUB_registerConsumer(const SPP_SERVICE_ConsumerContract_t *p_consumerData, SPP_Kpid_t subscription)
Definition pubsub.c:91
Standard return-value type used across all SPP modules.
SPP_RetVal_t
Unified return type for all SPP API functions.
Definition returnTypes.h:24
SPP module descriptor and registry API.
Describes the contract of a consumer module. This module needs to have:
Definition service.h:40
Defines the callbacks and metadata of an SPP producer.
Definition service.h:25
Portable integer types and SPI/storage configuration types for SPP.
uint8_t spp_uint8_t
Definition types.h:27