Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
sapi_ipc_pubsub.c
Go to the documentation of this file.
1
6
9#include "safeapi/log.h"
10
11/* Implementation stubs - actual implementation would use base IPC layer */
12
14
16
18
20
22
23
27{
28 sapi_status_t lifecycle_status;
29
30 if (topic_out == NULL || config == NULL) {
32 }
33
34 if (config->message_size == 0 || config->max_subscribers == 0) {
36 }
37
38 /* REQ-LIFECYCLE-001 (ADR-026): a pub-sub topic is a setup-only resource -
39 * refuse once the application's setup phase has been locked. */
40 lifecycle_status = sapi_lifecycle_check_setup_allowed();
41 if (lifecycle_status != SAPI_STATUS_OK)
42 {
43 return lifecycle_status;
44 }
45
46 SAPI_LOG_INFO("Creating pub-sub topic: %s (msg_sz=%zu, max_sub=%zu)",
47 config->topic_name, config->message_size, config->max_subscribers);
48
49 /* TODO: Implement topic creation */
50 return SAPI_STATUS_OK;
51}
52
54 const void *message,
55 size_t message_size)
56{
57 if (topic == NULL || message == NULL) {
59 }
60
61 SAPI_LOG_DEBUG("Publishing message to topic (%zu bytes)", message_size);
62
63 /* TODO: Deliver message to all subscribers */
64 return SAPI_STATUS_OK;
65}
66
68{
69 if (topic == NULL) {
71 }
72
73 SAPI_LOG_INFO("Destroying pub-sub topic");
74 return SAPI_STATUS_OK;
75}
76
79{
80 if (subscriber_out == NULL || config == NULL) {
82 }
83
84 if (config->topic == NULL || config->queue_depth == 0) {
86 }
87
88 SAPI_LOG_INFO("Subscribing: %s to topic (queue_depth=%zu)",
89 config->subscriber_name, config->queue_depth);
90
91 /* TODO: Register subscriber and create queue */
92 return SAPI_STATUS_OK;
93}
94
96 void *message_out,
97 size_t message_size,
98 sapi_duration_ms_t timeout_ms)
99{
100 if (subscriber == NULL || message_out == NULL) {
102 }
103
104 /* TODO: Receive from subscriber queue with timeout */
105 return SAPI_STATUS_TIMEOUT;
106}
107
109{
110 if (subscriber == NULL) {
112 }
113
114 SAPI_LOG_INFO("Unsubscribing from topic");
115 return SAPI_STATUS_OK;
116}
sapi_status_t sapi_lifecycle_check_setup_allowed(void)
Convenience check for a setup-only constructor: call this as one of the first checks in any function ...
sapi_status_t
Common result/status codes.
Definition sapi_status.h:27
@ SAPI_STATUS_TIMEOUT
Definition sapi_status.h:32
@ SAPI_STATUS_INVALID_PARAM
Definition sapi_status.h:29
@ SAPI_STATUS_OK
Definition sapi_status.h:28
uint32_t sapi_duration_ms_t
Definition sapi_types.h:27
IPC Publish-Subscribe Pattern (one-to-many broadcasting).
sapi_status_t sapi_ipc_pubsub_subscribe(sapi_ipc_pubsub_subscriber_t *subscriber_out, const sapi_ipc_pubsub_subscriber_config_t *config)
Subscribe to a topic.
sapi_status_t sapi_ipc_pubsub_topic_create(sapi_ipc_pubsub_topic_t *topic_out, const sapi_ipc_pubsub_topic_config_t *config)
Create a publish-subscribe topic.
sapi_status_t sapi_ipc_pubsub_receive(sapi_ipc_pubsub_subscriber_t subscriber, void *message_out, size_t message_size, sapi_duration_ms_t timeout_ms)
Receive a message from subscribed topic (blocking with timeout).
sapi_status_t sapi_ipc_pubsub_unsubscribe(sapi_ipc_pubsub_subscriber_t subscriber)
Unsubscribe from a topic.
struct sapi_ipc_pubsub_subscriber_s * sapi_ipc_pubsub_subscriber_t
Subscriber handle for receiving from a topic.
struct sapi_ipc_pubsub_topic_s * sapi_ipc_pubsub_topic_t
Publish-subscribe topic handle.
sapi_status_t sapi_ipc_pubsub_topic_destroy(sapi_ipc_pubsub_topic_t topic)
Destroy a publish-subscribe topic.
sapi_status_t sapi_ipc_pubsub_publish(sapi_ipc_pubsub_topic_t topic, const void *message, size_t message_size)
Publish a message to all subscribers on a topic.
Process-wide application setup-phase lock (ADR-026).
Configuration for a subscriber.
Configuration for a pub-sub topic.