$darkmode
moka 0.0.0.1
An EMV card processing stack by switstack
Message Broker

Technical component implementing moka's core architecture. More...

Data Structures

struct  moka_header
 Message header used to forward and trace a message from one service to another. More...
 
struct  moka_message
 Message used to communicate between services. More...
 
struct  moka_service
 Service definition. More...
 

Macros

#define MESSAGE_BROKER_LOG_ON   1
 
#define MESSAGE_BROKER_LOG_OFF   0
 

Typedefs

typedef struct moka_header moka_header_t
 Message header used to forward and trace a message from one service to another.
 
typedef struct moka_message moka_message_t
 Message used to communicate between services.
 
typedef struct moka_service moka_service_t
 Service definition.
 

Functions

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. More...
 
uint8_t msg_brk_get_maximum_supported_service (void)
 returns the maximum service that can be registered to a message broker. More...
 
uint16_t msg_brk_register_service (moka_service_t *service)
 registers a moka service. More...
 
uint16_t msg_brk_register_lists_of_services (moka_service_t *list_of_services, uint8_t number_of_services)
 registers a list of services. More...
 
uint16_t msg_brk_unregister_service (moka_service_t *service)
 removes a service from the routing table. More...
 
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 response's payload buffers. More...
 
uint16_t msg_brk_set_trace (moka_message_broker_t *message_broker, uint8_t on_off)
 enables message broker traces. More...
 
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. More...
 
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. More...
 
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. More...
 
uint16_t msg_brk_setup_service (moka_service_t *service)
 calls service's setup generic function. More...
 
uint16_t msg_brk_initialize_service (moka_service_t *service, const uint8_t *inbound, uint16_t in_length)
 calls service's initialize generic function. More...
 
uint16_t msg_brk_cleanup_service (moka_service_t *service)
 calls service's cleanup generic function. More...
 
uint16_t msg_brk_release_service (moka_service_t *service)
 calls service's release generic function. More...
 
moka_message_broker_tmsg_brk_get_instance (moka_service_type_t type)
 provides the message broker instance corresponding to the service type. More...
 

Variables

uint64_t timestamp
 
uint32_t msg_id
 
uint8_t src
 
uint32_t src_auth_token
 
uint8_t dst
 
uint16_t dst_fnct
 
uint16_t dst_srv_err
 
uint16_t dst_fnct_err
 
moka_header_t hdr
 
uint16_t payload_length
 
void * payload
 
char name [SERVICE_MAX_NAME_SIZE]
 
moka_service_type_t type
 
moka_service_proxy_t proxy
 
moka_message_broker_tmessage_broker
 

Detailed Description

Technical component implementing moka's core architecture.

Note
moka's message broker implements a set of structures and behaviors to manage services' requests routes. It aims to remain agnostic from physical architectures, and to provide high testability by imposing a service-based pattern. It doesn't implement any business or functional rules, but connects emitters to receivers through structured messages. For most usages, its integration can performed with the service manager to avoid dealing with the underlying complexity of messaging.

Macro Definition Documentation

◆ MESSAGE_BROKER_LOG_OFF

#define MESSAGE_BROKER_LOG_OFF   0

Turn log off.

◆ MESSAGE_BROKER_LOG_ON

#define MESSAGE_BROKER_LOG_ON   1

Turn log on.

Function Documentation

◆ msg_brk_cleanup_service()

uint16_t msg_brk_cleanup_service ( moka_service_t service)

calls service's cleanup generic function.

Parameters
serviceservice with valid message broker
Returns
MOKA_OK if successful, another return code from commom_errors.h otherwise.

◆ msg_brk_get_instance()

moka_message_broker_t* msg_brk_get_instance ( moka_service_type_t  type)

provides the message broker instance corresponding to the service type.

Returns
message_broker_t*

◆ msg_brk_get_maximum_supported_service()

uint8_t msg_brk_get_maximum_supported_service ( void  )

returns the maximum service that can be registered to a message broker.

Returns
uint8_t number of maximum services (see common_errors.h)

◆ msg_brk_initialize()

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.

Parameters
[in,out]message_brokermessage broker instance
[in,out]service_tableservice table provided by calling level
[in]max_servicesnumber of maximum services to be registered
Returns
MOKA_OK if successful, another return code from commom_errors.h otherwise.

◆ msg_brk_initialize_service()

uint16_t msg_brk_initialize_service ( moka_service_t service,
const uint8_t *  inbound,
uint16_t  in_length 
)

calls service's initialize generic function.

Parameters
[in]serviceservice with valid message broker
[in]inboundoptional data set. Depends on the service
[in]in_lengthdata set's length
Returns
MOKA_OK if successful, another return code from commom_errors.h otherwise.

◆ msg_brk_is_service_registered()

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.

Parameters
[in]message_brokermessage broker instance
[in]typeservice type
Returns
moka_bool_t

◆ msg_brk_is_service_routed()

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.

Parameters
[in]message_brokermessage broker instance
[in]typeservice type
Returns
moka_bool_t

◆ msg_brk_prepare_message()

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.

Parameters
[in]sourceemitting service
[in]destinationreceiving service
[in]functionservice's function to request
[in,out]requestallocated by calling level
[in]payload_inallocated by calling level. May be null
[in]payload_in_lengthpayload's length
[in,out]responseallocated by calling level
[in]payload_outallocated by calling level. May be null
[in]payload_out_lengthpayload length
Returns
MOKA_OK if successful, another return code from commom_errors.h otherwise.

◆ msg_brk_register_lists_of_services()

uint16_t msg_brk_register_lists_of_services ( moka_service_t list_of_services,
uint8_t  number_of_services 
)

registers a list of services.

Parameters
[in]list_of_services
[in]number_of_services
Returns
MOKA_OK if successful, another return code from commom_errors.h otherwise.

◆ msg_brk_register_service()

uint16_t msg_brk_register_service ( moka_service_t service)

registers a moka service.

Parameters
[in,out]servicea service with a valid message broker
Returns
MOKA_OK if successful, another return code from commom_errors.h otherwise.

◆ msg_brk_release_service()

uint16_t msg_brk_release_service ( moka_service_t service)

calls service's release generic function.

Parameters
serviceservice with valid message broker
Returns
MOKA_OK if successful, another return code from commom_errors.h otherwise.

◆ msg_brk_send()

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 response's payload buffers.

Note
don't forget to set response's payload length in order to specify available payload's length for the response.
Parameters
[in,out]message_brokermessage broker instance
[in,out]requestmessage instance
[in,out]responsemessage instance
Returns
MOKA_OK if successful, another return code from commom_errors.h otherwise.

◆ msg_brk_set_trace()

uint16_t msg_brk_set_trace ( moka_message_broker_t message_broker,
uint8_t  on_off 
)

enables message broker traces.

Parameters
[in,out]message_brokermessage broker instance
[in]on_off
Returns
MOKA_OK if successful, another return code from commom_errors.h otherwise.

◆ msg_brk_setup_service()

uint16_t msg_brk_setup_service ( moka_service_t service)

calls service's setup generic function.

Parameters
[in]servicea service with valid message broker
Returns
MOKA_OK if successful, another return code from commom_errors.h otherwise.

◆ msg_brk_unregister_service()

uint16_t msg_brk_unregister_service ( moka_service_t service)

removes a service from the routing table.

Parameters
[in,out]servicea service with a valid message broker
Returns
MOKA_OK if successful, another return code from commom_errors.h otherwise.

Variable Documentation

◆ dst

uint8_t dst

receiver - service id

◆ dst_fnct

uint16_t dst_fnct

receiver - service's function id

◆ dst_fnct_err

uint16_t dst_fnct_err

receiver - service's function error

◆ dst_srv_err

uint16_t dst_srv_err

receiver - service error

◆ hdr

Message header.

◆ message_broker

moka_message_broker_t* message_broker

Service message broker.

◆ msg_id

uint32_t msg_id

unique exchange identifier for a pair of request/response message

◆ name

service name.

◆ payload

void* payload

Message data.

◆ payload_length

uint16_t payload_length

Message length.

◆ proxy

Service proxy.

◆ src

uint8_t src

sender - service id

◆ src_auth_token

uint32_t src_auth_token

sender's authentication token

◆ timestamp

uint64_t timestamp

optional message timestamp

◆ type

Service type.