Solaris Software
Toggle main menu visibility
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
"
11
#include "
spp/core/returnTypes.h
"
12
#include "
spp/services/service.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
SPP_RetVal_t
SPP_SERVICES_PUBSUB_registerProducer
(
const
SPP_SERVICE_ProducerContract_t
*p_producerData,
34
SPP_Kpid_t
*p_assignedKpid);
35
SPP_RetVal_t
SPP_SERVICES_PUBSUB_registerConsumer
(
const
SPP_SERVICE_ConsumerContract_t
*p_consumerData,
36
SPP_Kpid_t
subscription);
37
38
SPP_RetVal_t
SPP_SERVICES_PUBSUB_init
(
void
);
39
40
/**
41
* @brief Copies a packet into the internal buffer and returns it to the databank.
42
*
43
* Called by producers after filling a packet. The packet is copied by value
44
* into the next free slot of the internal circular buffer; the original is
45
* returned to the databank pool immediately. Returns K_SPP_ERROR if the
46
* buffer is full (packet is still returned to the pool).
47
*
48
* @param p_pkt Packet to publish (ownership transferred — do not use after this call).
49
* @return K_SPP_OK on success, K_SPP_ERROR_NULL_POINTER if p_pkt is NULL,
50
* K_SPP_ERROR if the buffer is full.
51
*/
52
SPP_RetVal_t
SPP_SERVICES_PUBSUB_publish
(
SPP_Packet_t
*p_pkt);
53
54
/**
55
* @brief Calls acquireData on every registered producer.
56
*/
57
void
SPP_SERVICES_PUBSUB_callProducers
(
void
);
58
59
/**
60
* @brief Routes all buffered packets to matching consumer mailboxes, then clears the buffer.
61
*/
62
63
void
SPP_SERVICES_PUBSUB_callConsumers
(
void
);
64
65
/**
66
* @brief Returns the number of packets currently held in the internal FIFO buffer.
67
*/
68
spp_uint8_t
SPP_SERVICES_PUBSUB_queueDepth
(
void
);
69
70
/**
71
* @brief Signals that a producer has new data pending.
72
*
73
* Must be called from within acquireData() as soon as a DRDY flag is detected,
74
* so that callConsumers() can preempt consumers with priority > K_SPP_SERVICES_PUBSUB_PREEMPT_PRIORITY.
75
*/
76
void
SPP_SERVICES_PUBSUB_signalProducerReady
(
void
);
77
78
SPP_RetVal_t
SPP_SERVICES_PUBSUB_getProducerInitResult
(
const
SPP_SERVICE_ProducerContract_t
*p_producerData,
79
SPP_RetVal_t
*p_initResult);
80
81
SPP_RetVal_t
SPP_SERVICES_PUBSUB_getConsumerInitResult
(
const
SPP_SERVICE_ConsumerContract_t
*p_consumerData,
82
SPP_RetVal_t
*p_initResult);
83
#endif
/* SPP_PUBSUB_H */
macros.h
Compile-time configuration flags and utility macros for SPP.
packet.h
Solaris Packet Protocol (SPP) packet structure definitions.
SPP_Packet_t
SPP_Packet_t
Definition
packet.h:79
SPP_SERVICES_PUBSUB_getConsumerInitResult
SPP_RetVal_t SPP_SERVICES_PUBSUB_getConsumerInitResult(const SPP_SERVICE_ConsumerContract_t *p_consumerData, SPP_RetVal_t *p_initResult)
Definition
pubsub.c:239
SPP_SERVICES_PUBSUB_signalProducerReady
void SPP_SERVICES_PUBSUB_signalProducerReady(void)
Signals that a producer has new data pending.
Definition
pubsub.c:177
SPP_SERVICES_PUBSUB_callConsumers
void SPP_SERVICES_PUBSUB_callConsumers(void)
Routes all buffered packets to matching consumer mailboxes, then clears the buffer.
Definition
pubsub.c:152
SPP_SERVICES_PUBSUB_init
SPP_RetVal_t SPP_SERVICES_PUBSUB_init(void)
Definition
pubsub.c:182
SPP_SERVICES_PUBSUB_queueDepth
spp_uint8_t SPP_SERVICES_PUBSUB_queueDepth(void)
Returns the number of packets currently held in the internal FIFO buffer.
Definition
pubsub.c:172
SPP_SERVICES_PUBSUB_callProducers
void SPP_SERVICES_PUBSUB_callProducers(void)
Calls acquireData on every registered producer.
Definition
pubsub.c:119
SPP_SERVICES_PUBSUB_getProducerInitResult
SPP_RetVal_t SPP_SERVICES_PUBSUB_getProducerInitResult(const SPP_SERVICE_ProducerContract_t *p_producerData, SPP_RetVal_t *p_initResult)
Definition
pubsub.c:220
SPP_SERVICES_PUBSUB_registerProducer
SPP_RetVal_t SPP_SERVICES_PUBSUB_registerProducer(const SPP_SERVICE_ProducerContract_t *p_producerData, SPP_Kpid_t *p_assignedKpid)
Definition
pubsub.c:58
SPP_SERVICES_PUBSUB_publish
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:128
SPP_SERVICES_PUBSUB_registerConsumer
SPP_RetVal_t SPP_SERVICES_PUBSUB_registerConsumer(const SPP_SERVICE_ConsumerContract_t *p_consumerData, SPP_Kpid_t subscription)
Definition
pubsub.c:94
returnTypes.h
Standard return-value type used across all SPP modules.
SPP_RetVal_t
SPP_RetVal_t
Unified return type for all SPP API functions.
Definition
returnTypes.h:24
service.h
SPP module descriptor and registry API.
SPP_SERVICE_ConsumerContract_t
Describes the contract of a consumer module. This module needs to have:
Definition
service.h:43
SPP_SERVICE_ProducerContract_t
Describes the contract of a producer module. This module needs to have:
Definition
service.h:28
types.h
Portable integer types and SPI/storage configuration types for SPP.
spp_uint8_t
uint8_t spp_uint8_t
Definition
types.h:27
SPP_Kpid_t
Definition
kpid.h:24
solaris-v2
spp
core
pubsub
pubsub.h
Generated by
1.18.0