coreMQTT Agent v2.0.0
Thread safe MQTT 3.1.1 Client
Loading...
Searching...
No Matches
Design

Architecture of the MQTT Agent library.

Thread Safe and Unsafe APIs

The MQTT Agent APIs are designed to be used by two types of tasks:

Interfaces and Callbacks

Similar to coreMQTT, the MQTT Agent library relies on interfaces to dissociate itself from platform specific functionality. Interfaces used by the MQTT Agent library are simply function pointers with expectations of behavior.

The MQTT Agent library expects the application to provide implementations for the following interfaces:

Function PointerUse
MQTTAgentMessageRecv_tReceiving commands sent to the agent task.
MQTTAgentMessageSend_tSending commands to the agent task from the application
MQTTAgentCommandGet_tAllocating storage for a command to be sent to the agent task.
MQTTAgentCommandRelease_tReleasing a command obtained from MQTTAgentCommandGet_t.
MQTTAgentIncomingPublishCallback_tAccepting incoming publish messages, with the possibility of further distributing them to other tasks.

Command Completion

Commands do not have any timeout associated with them. The only way for a task to be aware of a command's completion is through the invocation of an optional MQTTAgentCommandCallback_t completion callback. The completion callback will be invoked with an optional MQTTAgentCommandContext_t, which is the incomplete type struct MQTTAgentCommandContext. This type must be defined by the application, and should contain information that would be useful in distinguishing commands.
Example code:

struct MQTTAgentCommandContext
{
//Allow the calling thread to view the return code by copying it here.
MQTTStatus_t returnCode;
//pthread mutex and condition variables to signal to the thread that created the command.
pthread_mutex_t lock;
pthread_cond_t cond;
};


The completion callback using such a context could be:

void commandCompleteCallback( MQTTAgentCommandContext_t * pCmdContext, MQTTAgentReturnInfo_t * pReturnInfo )
{
pthread_mutex_lock( &( pCmdContext->lock ) );
//Set return code so the thread that created the command can view.
pCmdContext->returnCode = pReturnInfo->returnCode;
pthread_mutex_unlock( &( pCmdContext->lock ) );
//Signal the thread using the condition variable.
pthread_cond_broadcast( &( pCmdContext->cond ) );
}
struct MQTTAgentCommandContext MQTTAgentCommandContext_t
Struct containing context for a specific command.
Definition core_mqtt_agent.h:83
Struct holding return codes and outputs from a command.
Definition core_mqtt_agent.h:71
MQTTStatus_t returnCode
Definition core_mqtt_agent.h:72


The completion callback and completion context are each optional, and passed at time of command creation in the MQTTAgentCommandInfo_t parameter. If a command completion context is passed, it MUST remain in scope until the completion callback has been invoked.