$darkmode
moka 0.0.0.1
An EMV card processing stack by switstack
message_broker.h
1 /*
2  * @file message_broker.h
3  *
4  * @author Olivier Chauvineau
5  *
6  * @copyright Copyright (C) 2024 switstack <contact@switstack.io>
7  */
8 
9 #ifndef MOKA_MESSAGE_BROKER_H
10 #define MOKA_MESSAGE_BROKER_H
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif /* __cplusplus */
15 
32 /* ---------------------------------------------------------------------------------------------- *
33  * Includes *
34  * ---------------------------------------------------------------------------------------------- */
35 
36 /* - System */
37 
38 /* - Project */
39 #include "moka/util/common.h"
40 
41 /* - Local */
42 
59 /* -------------------------------------------------------------------------- *
60  * Definitions *
61  * -------------------------------------------------------------------------- */
62 
64 #define MESSAGE_BROKER_LOG_ON 1
66 #define MESSAGE_BROKER_LOG_OFF 0
67 
68 /* ---------------------------------------------------------------------------------------------- *
69  * Declarations *
70  * ---------------------------------------------------------------------------------------------- */
71 
76 typedef struct moka_header {
78  uint64_t timestamp;
80  uint32_t msg_id;
82  uint8_t src;
84  uint32_t src_auth_token;
86  uint8_t dst;
88  uint16_t dst_fnct;
90  uint16_t dst_srv_err;
92  uint16_t dst_fnct_err;
94 
98 typedef struct moka_message {
102  uint16_t payload_length;
104  void* payload;
106 
110 typedef struct moka_service {
120 
121 /* -------------------------------------------------------------------------- *
122  * Public Primitives *
123  * -------------------------------------------------------------------------- */
124 
133 uint16_t
135  moka_message_broker_t* message_broker,
136  moka_service_proxy_t* service_table,
137  uint8_t max_services);
138 
144 uint8_t
146 
152 uint16_t
154 
161 uint16_t
162 msg_brk_register_lists_of_services(moka_service_t* list_of_services, uint8_t number_of_services);
163 
169 uint16_t
171 
182 uint16_t
184  moka_message_broker_t* message_broker, moka_message_t* request, moka_message_t* response);
185 
192 uint16_t
193 msg_brk_set_trace(moka_message_broker_t* message_broker, uint8_t on_off);
194 
203  const moka_message_broker_t* message_broker, moka_service_type_t type);
204 
214 
228 uint16_t
230  uint8_t source,
231  uint8_t destination,
232  uint16_t function,
233  moka_message_t* request,
234  const uint8_t* payload_in,
235  uint16_t payload_in_length,
236  moka_message_t* response,
237  const uint8_t* payload_out,
238  uint16_t payload_out_length);
239 
245 uint16_t
247 
255 uint16_t
256 msg_brk_initialize_service(moka_service_t* service, const uint8_t* inbound, uint16_t in_length);
257 
263 uint16_t
265 
271 uint16_t
273 
281 
282 #ifdef __cplusplus
283 }
284 #endif /* __cplusplus */
285 
286 #endif /* MOKA_MESSAGE_BROKER_H */
287 
Common definitions, structures, routines, and errors.
enum moka_bool moka_bool_t
moka's boolean type.
uint16_t(* moka_service_proxy_t)(uint16_t function_identifier, const void *inbound, uint16_t in_length, void *outbound, uint16_t *out_length, uint16_t *error)
Proxy that shall be implemented by each service registered onto a essage broker so it will be contact...
Definition: common.h:351
#define SERVICE_MAX_NAME_SIZE
Definition: memory_footprint.h:29
enum moka_service_type moka_service_type_t
A service is a moka end-point that fulfills a functional responsbility.
uint16_t dst_fnct
Definition: message_broker.h:88
moka_bool_t msg_brk_is_service_registered(const moka_message_broker_t *message_broker, moka_service_type_t type)
returns whether or not a service is registered.
uint16_t payload_length
Definition: message_broker.h:102
moka_message_broker_t * msg_brk_get_instance(moka_service_type_t type)
provides the message broker instance corresponding to the service type.
uint32_t src_auth_token
Definition: message_broker.h:84
uint16_t msg_brk_cleanup_service(moka_service_t *service)
calls service's cleanup generic function.
uint8_t dst
Definition: message_broker.h:86
uint64_t timestamp
Definition: message_broker.h:78
moka_service_type_t type
Definition: message_broker.h:114
uint16_t msg_brk_unregister_service(moka_service_t *service)
removes a service from the routing table.
uint16_t msg_brk_prepare_message(uint8_t source, uint8_t destination, uint16_t function, moka_message_t *request, const uint8_t *payload_in, uint16_t payload_in_length, moka_message_t *response, const uint8_t *payload_out, uint16_t payload_out_length)
builds a request/response couple to send through a message broker.
uint16_t msg_brk_register_service(moka_service_t *service)
registers a moka service.
uint16_t msg_brk_register_lists_of_services(moka_service_t *list_of_services, uint8_t number_of_services)
registers a list of services.
moka_service_proxy_t proxy
Definition: message_broker.h:116
uint16_t msg_brk_initialize(moka_message_broker_t *message_broker, moka_service_proxy_t *service_table, uint8_t max_services)
initializes internal structures. Mandatory call ahead of any other calls.
uint16_t msg_brk_release_service(moka_service_t *service)
calls service's release generic function.
struct moka_service moka_service_t
Service definition.
moka_bool_t msg_brk_is_service_routed(const moka_message_broker_t *message_broker, moka_service_type_t type)
notifies whether a service proxy has been registered or not for a given service.
moka_header_t hdr
Definition: message_broker.h:100
uint32_t msg_id
Definition: message_broker.h:80
uint16_t msg_brk_setup_service(moka_service_t *service)
calls service's setup generic function.
uint16_t msg_brk_initialize_service(moka_service_t *service, const uint8_t *inbound, uint16_t in_length)
calls service's initialize generic function.
uint16_t msg_brk_send(moka_message_broker_t *message_broker, moka_message_t *request, moka_message_t *response)
routes a message to a destination service. Source shall allocate and provide both request's and respo...
struct moka_message moka_message_t
Message used to communicate between services.
void * payload
Definition: message_broker.h:104
struct moka_header moka_header_t
Message header used to forward and trace a message from one service to another.
char name[SERVICE_MAX_NAME_SIZE]
Definition: message_broker.h:112
uint16_t dst_srv_err
Definition: message_broker.h:90
uint16_t dst_fnct_err
Definition: message_broker.h:92
moka_message_broker_t * message_broker
Definition: message_broker.h:118
uint8_t msg_brk_get_maximum_supported_service(void)
returns the maximum service that can be registered to a message broker.
uint8_t src
Definition: message_broker.h:82
uint16_t msg_brk_set_trace(moka_message_broker_t *message_broker, uint8_t on_off)
enables message broker traces.
Message header used to forward and trace a message from one service to another.
Definition: message_broker.h:76
Message broker structure gathering all its states.
Definition: common.h:607
Message used to communicate between services.
Definition: message_broker.h:98
Service definition.
Definition: message_broker.h:110