LibJuno 1.0.4
LibJuno is a lightweight C11 library designed specifically for embedded systems.
Loading...
Searching...
No Matches
udp_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
49#ifndef JUNO_UDP_API_H
50#define JUNO_UDP_API_H
51
52#include <stdint.h>
53#include <stdbool.h>
54#include "juno/status.h"
55#include "juno/module.h"
56#include "juno/types.h"
57
58#ifdef __cplusplus
59extern "C"
60{
61#endif
62
63/* --------------------------------------------------------------------------
64 * Forward declarations
65 * -------------------------------------------------------------------------- */
66
69
71typedef struct JUNO_UDP_ROOT_TAG JUNO_UDP_ROOT_T;
72
74typedef struct JUNO_UDP_LINUX_TAG JUNO_UDP_LINUX_T;
75
81typedef union JUNO_UDP_TAG JUNO_UDP_T;
82
83/* --------------------------------------------------------------------------
84 * UDP_THREAD_MSG_T — fixed-size datagram message
85 * -------------------------------------------------------------------------- */
86
99// @{"req": ["REQ-UDP-018"]}
100typedef struct UDP_THREAD_MSG_TAG
101{
103 uint32_t uSeqNum;
109 uint8_t arrPayload[64];
111
112/* --------------------------------------------------------------------------
113 * JUNO_UDP_CFG_T — socket configuration
114 * -------------------------------------------------------------------------- */
115
129// @{"req": ["REQ-UDP-017"]}
130typedef struct JUNO_UDP_CFG_TAG
131{
133 const char *pcAddress;
135 uint16_t uPort;
139
140/* --------------------------------------------------------------------------
141 * JUNO_UDP_API_T — vtable
142 * -------------------------------------------------------------------------- */
143
157// @{"req": ["REQ-UDP-002"]}
188
189/* --------------------------------------------------------------------------
190 * JUNO_UDP_ROOT_T — module root (freestanding)
191 * -------------------------------------------------------------------------- */
192
209// @{"req": ["REQ-UDP-001", "REQ-UDP-010", "REQ-UDP-011"]}
211typedef struct JUNO_UDP_ROOT_TAG JUNO_UDP_ROOT_T;
212
213/* --------------------------------------------------------------------------
214 * JUNO_UDP_T — module union
215 * -------------------------------------------------------------------------- */
216
235/* Full union definition lives in udp_linux.h — see JUNO_UDP_T forward typedef above. */
236
237/* --------------------------------------------------------------------------
238 * Public function declarations
239 * -------------------------------------------------------------------------- */
240
264// @{"req": ["REQ-UDP-016"]}
266 JUNO_UDP_ROOT_T *ptRoot,
267 const JUNO_UDP_API_T *ptApi,
268 JUNO_FAILURE_HANDLER_T pfcnFailureHandler,
269 void *pvFailureUserData
270);
271
272#ifdef __cplusplus
273}
274#endif
275
276#endif /* JUNO_UDP_API_H */
#define JUNO_MODULE_EMPTY
Helper for module definitions with no additional members.
Definition module.h:87
#define JUNO_MODULE_ROOT(API_T,...)
Implement a module root struct containing ptApi and failure fields.
Definition module.h:129
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
Module system and dependency injection primitives for LibJuno.
Status codes and failure-handling helpers for LibJuno.
Vtable defining the UDP socket module interface.
Definition udp_api.h:159
JUNO_STATUS_T(* Free)(JUNO_UDP_ROOT_T *ptRoot)
Release all resources held by the module (RAII cleanup).
Definition udp_api.h:186
JUNO_STATUS_T(* Receive)(JUNO_UDP_ROOT_T *ptRoot, UDP_THREAD_MSG_T *ptMsg)
Receive exactly one UDP_THREAD_MSG_T datagram.
Definition udp_api.h:176
JUNO_STATUS_T(* Send)(JUNO_UDP_ROOT_T *ptRoot, const UDP_THREAD_MSG_T *ptMsg)
Send exactly one UDP_THREAD_MSG_T datagram.
Definition udp_api.h:166
Configuration passed to JunoUdp_LinuxInit to open and configure a UDP socket.
Definition udp_api.h:131
const char * pcAddress
IPv4 address string (e.g. "127.0.0.1"); NULL or "0.0.0.0" for receiver.
Definition udp_api.h:133
uint16_t uPort
UDP port number in host byte order.
Definition udp_api.h:135
bool bIsReceiver
true = bind to local port (receiver); false = connect to remote (sender).
Definition udp_api.h:137
Fixed-size UDP datagram message transferred between sender and receiver.
Definition udp_api.h:101
uint32_t uSeqNum
Monotonically increasing sequence number; wraps at UINT32_MAX.
Definition udp_api.h:103
uint8_t arrPayload[64]
Fixed-size application-defined payload (64 bytes).
Definition udp_api.h:109
uint32_t uTimestampSubSec
Sub-second component of the sender's timestamp (units defined by application).
Definition udp_api.h:107
uint32_t uTimestampSec
Whole-second component of the sender's timestamp.
Definition udp_api.h:105
Common module result type aliases used throughout LibJuno.
struct UDP_THREAD_MSG_TAG UDP_THREAD_MSG_T
Fixed-size UDP datagram message transferred between sender and receiver.
struct JUNO_UDP_ROOT_TAG JUNO_UDP_ROOT_T
Forward declaration of the UDP module root type.
Definition udp_api.h:71
JUNO_STATUS_T JunoUdp_Init(JUNO_UDP_ROOT_T *ptRoot, const JUNO_UDP_API_T *ptApi, JUNO_FAILURE_HANDLER_T pfcnFailureHandler, void *pvFailureUserData)
Type-safe polymorphic handle for a UDP module instance.
Definition juno_udp_init.cpp:51
struct JUNO_UDP_LINUX_TAG JUNO_UDP_LINUX_T
Forward declaration of the Linux derivation type.
Definition udp_api.h:74
struct JUNO_UDP_CFG_TAG JUNO_UDP_CFG_T
Configuration passed to JunoUdp_LinuxInit to open and configure a UDP socket.
union JUNO_UDP_TAG JUNO_UDP_T
Forward declaration of the UDP module union type.
Definition udp_api.h:81