Architecture of the MQTT Agent library.
The MQTT Agent APIs are designed to be used by two types of tasks:
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 Pointer | Use |
| MQTTAgentMessageRecv_t | Receiving commands sent to the agent task. |
| MQTTAgentMessageSend_t | Sending commands to the agent task from the application |
| MQTTAgentCommandGet_t | Allocating storage for a command to be sent to the agent task. |
| MQTTAgentCommandRelease_t | Releasing a command obtained from MQTTAgentCommandGet_t. |
| MQTTAgentIncomingPublishCallback_t | Accepting incoming publish messages, with the possibility of further distributing them to other tasks. |
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:
The completion callback using such a context could be:
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.