coreMQTT Agent v2.0.0
Thread safe MQTT 3.1.1 Client
Loading...
Searching...
No Matches
core_mqtt_agent.h
Go to the documentation of this file.
1/*
2 * coreMQTT Agent <DEVELOPMENT BRANCH>
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 */
22
27#ifndef CORE_MQTT_AGENT_H
28#define CORE_MQTT_AGENT_H
29
30/* *INDENT-OFF* */
31#ifdef __cplusplus
32 extern "C" {
33#endif
34/* *INDENT-ON* */
35
36/* MQTT library includes. */
37#include "core_mqtt.h"
38#include "core_mqtt_state.h"
39
41
42/* Command messaging interface include. */
44
62
63struct MQTTAgentContext;
64struct MQTTAgentCommandContext;
65
70typedef struct MQTTAgentReturnInfo
71{
72 MQTTStatus_t returnCode;
73 uint8_t * pSubackCodes;
75
83typedef struct MQTTAgentCommandContext MQTTAgentCommandContext_t;
84
101typedef void (* MQTTAgentCommandCallback_t )( MQTTAgentCommandContext_t * pCmdCallbackContext,
102 MQTTAgentReturnInfo_t * pReturnInfo );
103
117
122typedef struct MQTTAckInfo
123{
124 uint16_t packetId;
125 MQTTAgentCommand_t * pOriginalCommand;
127
142typedef void (* MQTTAgentIncomingPublishCallback_t )( struct MQTTAgentContext * pMqttAgentContext,
143 uint16_t packetId,
144 MQTTPublishInfo_t * pPublishInfo );
145
163
168typedef struct MQTTAgentSubscribeArgs
169{
170 MQTTSubscribeInfo_t * pSubscribeInfo;
172 const MQTTPropBuilder_t * pProperties;
174
179typedef struct MQTTAgentConnectArgs
180{
181 MQTTConnectInfo_t * pConnectInfo;
182 MQTTPublishInfo_t * pWillInfo;
183 uint32_t timeoutMs;
185 MQTTPropBuilder_t * pProperties;
186 const MQTTPropBuilder_t * pWillProperties;
188
193typedef struct MQTTAgentPublishArgs
194{
195 MQTTPublishInfo_t * pPublishInfo;
196 const MQTTPropBuilder_t * pProperties;
198
203typedef struct MQTTAgentDisconnectArgs
204{
205 const MQTTPropBuilder_t * pProperties;
206 const MQTTSuccessFailReasonCode_t * reasonCode;
208
219
220/*-----------------------------------------------------------*/
221
313/* @[declare_mqtt_agent_init] */
314MQTTStatus_t MQTTAgent_Init( MQTTAgentContext_t * pMqttAgentContext,
315 const MQTTAgentMessageInterface_t * pMsgInterface,
316 const MQTTFixedBuffer_t * pNetworkBuffer,
317 const TransportInterface_t * pTransportInterface,
318 MQTTGetCurrentTimeFunc_t getCurrentTimeMs,
319 MQTTAgentIncomingPublishCallback_t incomingCallback,
320 void * pIncomingPacketContext,
321 uint8_t * pAckPropsBuffer,
322 size_t ackPropsBufferSize );
323/* @[declare_mqtt_agent_init] */
324
365/* @[declare_mqtt_agent_commandloop] */
366MQTTStatus_t MQTTAgent_CommandLoop( MQTTAgentContext_t * pMqttAgentContext );
367/* @[declare_mqtt_agent_commandloop] */
368
406/* @[declare_mqtt_agent_resumesession] */
407MQTTStatus_t MQTTAgent_ResumeSession( MQTTAgentContext_t * pMqttAgentContext,
408 bool sessionPresent );
409/* @[declare_mqtt_agent_resumesession] */
410
445/* @[declare_mqtt_agent_cancelall] */
446MQTTStatus_t MQTTAgent_CancelAll( MQTTAgentContext_t * pMqttAgentContext );
447/* @[declare_mqtt_agent_cancelall] */
448
504/* @[declare_mqtt_agent_subscribe] */
505MQTTStatus_t MQTTAgent_Subscribe( const MQTTAgentContext_t * pMqttAgentContext,
506 MQTTAgentSubscribeArgs_t * pSubscriptionArgs,
507 const MQTTAgentCommandInfo_t * pCommandInfo );
508/* @[declare_mqtt_agent_subscribe] */
509
564/* @[declare_mqtt_agent_unsubscribe] */
565MQTTStatus_t MQTTAgent_Unsubscribe( const MQTTAgentContext_t * pMqttAgentContext,
566 MQTTAgentSubscribeArgs_t * pSubscriptionArgs,
567 const MQTTAgentCommandInfo_t * pCommandInfo );
568/* @[declare_mqtt_agent_unsubscribe] */
569
624/* @[declare_mqtt_agent_publish] */
625MQTTStatus_t MQTTAgent_Publish( const MQTTAgentContext_t * pMqttAgentContext,
626 MQTTAgentPublishArgs_t * pPublishArgs,
627 const MQTTAgentCommandInfo_t * pCommandInfo );
628/* @[declare_mqtt_agent_publish] */
629
675/* @[declare_mqtt_agent_processloop] */
676MQTTStatus_t MQTTAgent_ProcessLoop( const MQTTAgentContext_t * pMqttAgentContext,
677 const MQTTAgentCommandInfo_t * pCommandInfo );
678/* @[declare_mqtt_agent_processloop] */
679
731/* @[declare_mqtt_agent_ping] */
732MQTTStatus_t MQTTAgent_Ping( const MQTTAgentContext_t * pMqttAgentContext,
733 const MQTTAgentCommandInfo_t * pCommandInfo );
734/* @[declare_mqtt_agent_ping] */
735
824/* @[declare_mqtt_agent_connect] */
825MQTTStatus_t MQTTAgent_Connect( const MQTTAgentContext_t * pMqttAgentContext,
826 MQTTAgentConnectArgs_t * pConnectArgs,
827 const MQTTAgentCommandInfo_t * pCommandInfo );
828/* @[declare_mqtt_agent_connect] */
829
888/* @[declare_mqtt_agent_disconnect] */
889MQTTStatus_t MQTTAgent_Disconnect( const MQTTAgentContext_t * pMqttAgentContext,
890 MQTTAgentDisconnectArgs_t * pDisconnectArgs,
891 const MQTTAgentCommandInfo_t * pCommandInfo );
892/* @[declare_mqtt_agent_disconnect] */
893
952/* @[declare_mqtt_agent_terminate] */
953MQTTStatus_t MQTTAgent_Terminate( const MQTTAgentContext_t * pMqttAgentContext,
954 const MQTTAgentCommandInfo_t * pCommandInfo );
955/* @[declare_mqtt_agent_terminate] */
956
957/* *INDENT-OFF* */
958#ifdef __cplusplus
959 }
960#endif
961/* *INDENT-ON* */
962
963#endif /* CORE_MQTT_AGENT_H */
MQTTStatus_t MQTTAgent_CancelAll(MQTTAgentContext_t *pMqttAgentContext)
Cancel all enqueued commands and those awaiting acknowledgment while the command loop is not running.
Definition core_mqtt_agent.c:1119
MQTTStatus_t MQTTAgent_Init(MQTTAgentContext_t *pMqttAgentContext, const MQTTAgentMessageInterface_t *pMsgInterface, const MQTTFixedBuffer_t *pNetworkBuffer, const TransportInterface_t *pTransportInterface, MQTTGetCurrentTimeFunc_t getCurrentTimeMs, MQTTAgentIncomingPublishCallback_t incomingCallback, void *pIncomingPacketContext, uint8_t *pAckPropsBuffer, size_t ackPropsBufferSize)
Perform any initialization the MQTT agent requires before it can be used. Must be called before any o...
Definition core_mqtt_agent.c:967
MQTTStatus_t MQTTAgent_Subscribe(const MQTTAgentContext_t *pMqttAgentContext, MQTTAgentSubscribeArgs_t *pSubscriptionArgs, const MQTTAgentCommandInfo_t *pCommandInfo)
Add a command to call MQTT_Subscribe() for an MQTT connection.
Definition core_mqtt_agent.c:1168
MQTTStatus_t MQTTAgent_ResumeSession(MQTTAgentContext_t *pMqttAgentContext, bool sessionPresent)
Resume a session by resending publishes if a session is present in the broker, or clear state informa...
Definition core_mqtt_agent.c:1076
MQTTStatus_t MQTTAgent_Connect(const MQTTAgentContext_t *pMqttAgentContext, MQTTAgentConnectArgs_t *pConnectArgs, const MQTTAgentCommandInfo_t *pCommandInfo)
Add a command to call MQTT_Connect() for an MQTT connection. If a session is resumed with the broker,...
Definition core_mqtt_agent.c:1266
MQTTStatus_t MQTTAgent_CommandLoop(MQTTAgentContext_t *pMqttAgentContext)
Process commands from the command queue in a loop.
Definition core_mqtt_agent.c:1034
MQTTStatus_t MQTTAgent_ProcessLoop(const MQTTAgentContext_t *pMqttAgentContext, const MQTTAgentCommandInfo_t *pCommandInfo)
Send a message to the MQTT agent purely to trigger an iteration of its loop, which will result in a c...
Definition core_mqtt_agent.c:1243
MQTTStatus_t MQTTAgent_Unsubscribe(const MQTTAgentContext_t *pMqttAgentContext, MQTTAgentSubscribeArgs_t *pSubscriptionArgs, const MQTTAgentCommandInfo_t *pCommandInfo)
Add a command to call MQTT_Unsubscribe() for an MQTT connection.
Definition core_mqtt_agent.c:1193
MQTTStatus_t MQTTAgent_Terminate(const MQTTAgentContext_t *pMqttAgentContext, const MQTTAgentCommandInfo_t *pCommandInfo)
Add a termination command to the command queue.
Definition core_mqtt_agent.c:1338
MQTTStatus_t MQTTAgent_Ping(const MQTTAgentContext_t *pMqttAgentContext, const MQTTAgentCommandInfo_t *pCommandInfo)
Add a command to call MQTT_Ping() for an MQTT connection.
Definition core_mqtt_agent.c:1315
MQTTStatus_t MQTTAgent_Disconnect(const MQTTAgentContext_t *pMqttAgentContext, MQTTAgentDisconnectArgs_t *pDisconnectArgs, const MQTTAgentCommandInfo_t *pCommandInfo)
Add a command to disconnect an MQTT connection.
Definition core_mqtt_agent.c:1291
MQTTStatus_t MQTTAgent_Publish(const MQTTAgentContext_t *pMqttAgentContext, MQTTAgentPublishArgs_t *pPublishArgs, const MQTTAgentCommandInfo_t *pCommandInfo)
Add a command to call MQTT_Publish() for an MQTT connection.
Definition core_mqtt_agent.c:1218
This represents the default values for the configuration macros for the MQTT-Agent library.
#define MQTT_AGENT_MAX_OUTSTANDING_ACKS
The maximum number of pending acknowledgments to track for a single connection.
Definition core_mqtt_agent_config_defaults.h:84
Functions to interact with queues.
void(* MQTTAgentCommandCallback_t)(MQTTAgentCommandContext_t *pCmdCallbackContext, MQTTAgentReturnInfo_t *pReturnInfo)
Callback function called when a command completes.
Definition core_mqtt_agent.h:101
void(* MQTTAgentIncomingPublishCallback_t)(struct MQTTAgentContext *pMqttAgentContext, uint16_t packetId, MQTTPublishInfo_t *pPublishInfo)
Callback function called when receiving a publish.
Definition core_mqtt_agent.h:142
MQTTAgentCommandType_t
A type of command for interacting with the MQTT API.
Definition core_mqtt_agent.h:50
@ NUM_COMMANDS
The number of command types handled by the agent.
Definition core_mqtt_agent.h:60
@ CONNECT
Call MQTT_Connect().
Definition core_mqtt_agent.h:57
@ DISCONNECT
Call MQTT_Disconnect().
Definition core_mqtt_agent.h:58
@ PING
Call MQTT_Ping().
Definition core_mqtt_agent.h:56
@ UNSUBSCRIBE
Call MQTT_Unsubscribe().
Definition core_mqtt_agent.h:55
@ PROCESSLOOP
Call MQTT_ProcessLoop().
Definition core_mqtt_agent.h:52
@ TERMINATE
Exit the command loop and stop processing commands.
Definition core_mqtt_agent.h:59
@ SUBSCRIBE
Call MQTT_Subscribe().
Definition core_mqtt_agent.h:54
@ PUBLISH
Call MQTT_Publish().
Definition core_mqtt_agent.h:53
@ NONE
No command received. Must be zero (its memset() value).
Definition core_mqtt_agent.h:51
struct MQTTAgentCommandContext MQTTAgentCommandContext_t
Struct containing context for a specific command.
Definition core_mqtt_agent.h:83
Information for a pending MQTT ack packet expected by the agent.
Definition core_mqtt_agent.h:123
MQTTAgentCommand_t * pOriginalCommand
Definition core_mqtt_agent.h:125
uint16_t packetId
Definition core_mqtt_agent.h:124
The commands sent from the APIs to the MQTT agent task.
Definition core_mqtt_agent.h:111
void * pArgs
Arguments of command.
Definition core_mqtt_agent.h:113
MQTTAgentCommandCallback_t pCommandCompleteCallback
Callback to invoke upon completion.
Definition core_mqtt_agent.h:114
MQTTAgentCommandContext_t * pCmdContext
Context for completion callback.
Definition core_mqtt_agent.h:115
MQTTAgentCommandType_t commandType
Type of command.
Definition core_mqtt_agent.h:112
Struct holding arguments that are common to every command.
Definition core_mqtt_agent.h:214
MQTTAgentCommandContext_t * pCmdCompleteCallbackContext
Context for completion callback.
Definition core_mqtt_agent.h:216
MQTTAgentCommandCallback_t cmdCompleteCallback
Callback to invoke upon completion.
Definition core_mqtt_agent.h:215
uint32_t blockTimeMs
Maximum block time for enqueueing the command.
Definition core_mqtt_agent.h:217
Struct holding arguments for a CONNECT call.
Definition core_mqtt_agent.h:180
bool sessionPresent
Output flag set if a previous session was present.
Definition core_mqtt_agent.h:184
MQTTPublishInfo_t * pWillInfo
Optional Last Will and Testament.
Definition core_mqtt_agent.h:182
const MQTTPropBuilder_t * pWillProperties
Optional MQTT v5 will properties.
Definition core_mqtt_agent.h:186
uint32_t timeoutMs
Maximum timeout for a CONNACK packet.
Definition core_mqtt_agent.h:183
MQTTConnectInfo_t * pConnectInfo
MQTT CONNECT packet information.
Definition core_mqtt_agent.h:181
MQTTPropBuilder_t * pProperties
Optional MQTT v5 connect properties.
Definition core_mqtt_agent.h:185
Information used by each MQTT agent. A context will be initialized by MQTTAgent_Init(),...
Definition core_mqtt_agent.h:153
void * pIncomingCallbackContext
Definition core_mqtt_agent.h:158
MQTTPubAckInfo_t pOutgoingPublishRecords[MQTT_AGENT_MAX_OUTSTANDING_ACKS]
Definition core_mqtt_agent.h:161
MQTTAgentIncomingPublishCallback_t pIncomingCallback
Definition core_mqtt_agent.h:157
MQTTAgentAckInfo_t pPendingAcks[MQTT_AGENT_MAX_OUTSTANDING_ACKS]
Definition core_mqtt_agent.h:156
MQTTPubAckInfo_t pIncomingPublishRecords[MQTT_AGENT_MAX_OUTSTANDING_ACKS]
Definition core_mqtt_agent.h:160
MQTTAgentMessageInterface_t agentInterface
Definition core_mqtt_agent.h:155
MQTTContext_t mqttContext
Definition core_mqtt_agent.h:154
bool packetReceivedInLoop
Definition core_mqtt_agent.h:159
Struct holding arguments for a DISCONNECT call.
Definition core_mqtt_agent.h:204
const MQTTPropBuilder_t * pProperties
Optional MQTT v5 disconnect properties.
Definition core_mqtt_agent.h:205
const MQTTSuccessFailReasonCode_t * reasonCode
Optional MQTT v5 disconnect reason code.
Definition core_mqtt_agent.h:206
Function pointers and contexts used for sending and receiving commands, and allocating memory for the...
Definition core_mqtt_agent_message_interface.h:133
Struct holding arguments for a PUBLISH call.
Definition core_mqtt_agent.h:194
MQTTPublishInfo_t * pPublishInfo
Publish information.
Definition core_mqtt_agent.h:195
const MQTTPropBuilder_t * pProperties
Optional MQTT v5 publish properties.
Definition core_mqtt_agent.h:196
Struct holding return codes and outputs from a command.
Definition core_mqtt_agent.h:71
MQTTStatus_t returnCode
Definition core_mqtt_agent.h:72
uint8_t * pSubackCodes
Definition core_mqtt_agent.h:73
Struct holding arguments for a SUBSCRIBE or UNSUBSCRIBE call.
Definition core_mqtt_agent.h:169
MQTTSubscribeInfo_t * pSubscribeInfo
List of MQTT subscriptions.
Definition core_mqtt_agent.h:170
size_t numSubscriptions
Number of elements in pSubscribeInfo.
Definition core_mqtt_agent.h:171
const MQTTPropBuilder_t * pProperties
Optional MQTT v5 properties for subscribe/unsubscribe.
Definition core_mqtt_agent.h:172