AWS IoT Device SDK C: MQTT
MQTT 3.1.1 client library
Return to main page ↑
iot_mqtt_operation.c File Reference

Implements functions that process MQTT operations. More...

#include "iot_config.h"
#include <string.h>
#include "private/iot_mqtt_internal.h"
#include "platform/iot_clock.h"
#include "platform/iot_threads.h"
#include "iot_atomic.h"

Data Structures

struct  _operationMatchParam_t
 First parameter to _mqttOperation_match. More...
 

Functions

static bool _mqttOperation_match (const IotLink_t *const pOperationLink, void *pMatch)
 Match an MQTT operation by type and packet identifier. More...
 
static bool _checkRetryLimit (_mqttOperation_t *pOperation)
 Check if an operation with retry has exceeded its retry limit. More...
 
static bool _scheduleNextRetry (_mqttOperation_t *pOperation)
 Schedule the next send of an operation with retry. More...
 
static IotMqttError_t _scheduleCallback (_mqttOperation_t *pOperation)
 Schedule a callback for a completed MQTT operation. More...
 
static bool _completePendingSend (_mqttOperation_t *pOperation, bool *pDestroyOperation)
 Complete a pending send operation. More...
 
static IotMqttError_t _initializeOperation (_mqttConnection_t *pMqttConnection, _mqttOperation_t *pOperation, uint32_t flags, const IotMqttCallbackInfo_t *pCallbackInfo)
 Initialize newly created MQTT operation. More...
 
static bool _sendPingRequest (_mqttConnection_t *pMqttConnection)
 Send MQTT Ping Request to the broker. More...
 
IotMqttError_t _IotMqtt_CreateOperation (_mqttConnection_t *pMqttConnection, uint32_t flags, const IotMqttCallbackInfo_t *pCallbackInfo, _mqttOperation_t **pNewOperation)
 Create a record for a new in-progress MQTT operation. More...
 
bool _IotMqtt_DecrementOperationReferences (_mqttOperation_t *pOperation, bool cancelJob)
 Decrement the job reference count of an MQTT operation and optionally cancel its job. More...
 
void _IotMqtt_DestroyOperation (_mqttOperation_t *pOperation)
 Free resources used to record an MQTT operation. This is called when the operation completes. More...
 
void _IotMqtt_ProcessKeepAlive (IotTaskPool_t pTaskPool, IotTaskPoolJob_t pKeepAliveJob, void *pContext)
 Task pool routine for processing an MQTT connection's keep-alive. More...
 
void _IotMqtt_ProcessIncomingPublish (IotTaskPool_t pTaskPool, IotTaskPoolJob_t pPublishJob, void *pContext)
 Task pool routine for processing an incoming PUBLISH message. More...
 
void _IotMqtt_ProcessSend (IotTaskPool_t pTaskPool, IotTaskPoolJob_t pSendJob, void *pContext)
 Task pool routine for processing an MQTT operation to send. More...
 
void _IotMqtt_ProcessCompletedOperation (IotTaskPool_t pTaskPool, IotTaskPoolJob_t pOperationJob, void *pContext)
 Task pool routine for processing a completed MQTT operation. More...
 
IotMqttError_t _IotMqtt_ScheduleOperation (_mqttOperation_t *pOperation, IotTaskPoolRoutine_t jobRoutine, uint32_t delay)
 Schedule an operation for immediate processing. More...
 
_mqttOperation_t_IotMqtt_FindOperation (_mqttConnection_t *pMqttConnection, IotMqttOperationType_t type, const uint16_t *pPacketIdentifier)
 Search a list of MQTT operations pending responses using an operation name and packet identifier. Removes a matching operation from the list if found. More...
 
void _IotMqtt_Notify (_mqttOperation_t *pOperation)
 Notify of a completed MQTT operation. More...
 

Detailed Description

Implements functions that process MQTT operations.

Function Documentation

◆ _mqttOperation_match()

static bool _mqttOperation_match ( const IotLink_t *const  pOperationLink,
void *  pMatch 
)
static

Match an MQTT operation by type and packet identifier.

Parameters
[in]pOperationLinkPointer to the link member of an _mqttOperation_t.
[in]pMatchPointer to an _operationMatchParam_t.
Returns
true if the operation matches the parameters in pArgument; false otherwise.

◆ _checkRetryLimit()

static bool _checkRetryLimit ( _mqttOperation_t pOperation)
static

Check if an operation with retry has exceeded its retry limit.

If a PUBLISH operation is available for retry, this function also sets any necessary DUP flags.

Parameters
[in]pOperationThe operation to check.
Returns
true if the operation may be retried; false otherwise.

◆ _scheduleNextRetry()

static bool _scheduleNextRetry ( _mqttOperation_t pOperation)
static

Schedule the next send of an operation with retry.

Parameters
[in]pOperationThe operation to schedule.
Returns
true if the reschedule succeeded; false otherwise.

◆ _scheduleCallback()

static IotMqttError_t _scheduleCallback ( _mqttOperation_t pOperation)
static

Schedule a callback for a completed MQTT operation.

Parameters
[in]pOperationThe completed MQTT operation.
Returns
IOT_MQTT_SUCCESS if the schedule was successful; IOT_MQTT_SCHEDULING_ERROR otherwise.

◆ _completePendingSend()

static bool _completePendingSend ( _mqttOperation_t pOperation,
bool *  pDestroyOperation 
)
static

Complete a pending send operation.

Parameters
[in]pOperationThe pending MQTT send operation.
[out]pDestroyOperationWhether the operation should be destroyed afterwards.
Returns
true if the operation is awaiting a response from the network; false if not.

◆ _initializeOperation()

static IotMqttError_t _initializeOperation ( _mqttConnection_t pMqttConnection,
_mqttOperation_t pOperation,
uint32_t  flags,
const IotMqttCallbackInfo_t pCallbackInfo 
)
static

Initialize newly created MQTT operation.

Parameters
[in]pMqttConnectionThe MQTT connection associated with the operation.
[in]pOperationpointer to the new operation.
[in]flagsFlags variable passed to a user-facing MQTT function.
[in]pCallbackInfoUser-provided callback function and parameter.
Returns
IOT_MQTT_SUCCESS or IOT_MQTT_NO_MEMORY.

◆ _sendPingRequest()

static bool _sendPingRequest ( _mqttConnection_t pMqttConnection)
static

Send MQTT Ping Request to the broker.

Parameters
[in]pMqttConnectionThe MQTT connection associated with the request.
Returns
true if send is successful; false otherwise.

◆ _IotMqtt_CreateOperation()

IotMqttError_t _IotMqtt_CreateOperation ( _mqttConnection_t pMqttConnection,
uint32_t  flags,
const IotMqttCallbackInfo_t pCallbackInfo,
_mqttOperation_t **  pNewOperation 
)

Create a record for a new in-progress MQTT operation.

Parameters
[in]pMqttConnectionThe MQTT connection to associate with the operation.
[in]flagsFlags variable passed to a user-facing MQTT function.
[in]pCallbackInfoUser-provided callback function and parameter.
[out]pNewOperationSet to point to the new operation on success.
Returns
IOT_MQTT_SUCCESS, IOT_MQTT_BAD_PARAMETER, or IOT_MQTT_NO_MEMORY.

◆ _IotMqtt_DecrementOperationReferences()

bool _IotMqtt_DecrementOperationReferences ( _mqttOperation_t pOperation,
bool  cancelJob 
)

Decrement the job reference count of an MQTT operation and optionally cancel its job.

Checks if the operation may be destroyed afterwards.

Parameters
[in]pOperationThe MQTT operation with the job to cancel.
[in]cancelJobWhether to attempt cancellation of the operation's job.
Returns
true if the the operation may be safely destroyed; false otherwise.

◆ _IotMqtt_DestroyOperation()

void _IotMqtt_DestroyOperation ( _mqttOperation_t pOperation)

Free resources used to record an MQTT operation. This is called when the operation completes.

Parameters
[in]pOperationThe operation which completed.

◆ _IotMqtt_ProcessKeepAlive()

void _IotMqtt_ProcessKeepAlive ( IotTaskPool_t  pTaskPool,
IotTaskPoolJob_t  pKeepAliveJob,
void *  pContext 
)

Task pool routine for processing an MQTT connection's keep-alive.

Parameters
[in]pTaskPoolPointer to the system task pool.
[in]pKeepAliveJobPointer the an MQTT connection's keep-alive job.
[in]pContextPointer to an MQTT connection, passed as an opaque context.

◆ _IotMqtt_ProcessIncomingPublish()

void _IotMqtt_ProcessIncomingPublish ( IotTaskPool_t  pTaskPool,
IotTaskPoolJob_t  pPublishJob,
void *  pContext 
)

Task pool routine for processing an incoming PUBLISH message.

Parameters
[in]pTaskPoolPointer to the system task pool.
[in]pPublishJobPointer to the incoming PUBLISH operation's job.
[in]pContextPointer to the incoming PUBLISH operation, passed as an opaque context.

◆ _IotMqtt_ProcessSend()

void _IotMqtt_ProcessSend ( IotTaskPool_t  pTaskPool,
IotTaskPoolJob_t  pSendJob,
void *  pContext 
)

Task pool routine for processing an MQTT operation to send.

Parameters
[in]pTaskPoolPointer to the system task pool.
[in]pSendJobPointer to an operation's job.
[in]pContextPointer to the operation to send, passed as an opaque context.

◆ _IotMqtt_ProcessCompletedOperation()

void _IotMqtt_ProcessCompletedOperation ( IotTaskPool_t  pTaskPool,
IotTaskPoolJob_t  pOperationJob,
void *  pContext 
)

Task pool routine for processing a completed MQTT operation.

Parameters
[in]pTaskPoolPointer to the system task pool.
[in]pOperationJobPointer to the completed operation's job.
[in]pContextPointer to the completed operation, passed as an opaque context.

◆ _IotMqtt_ScheduleOperation()

IotMqttError_t _IotMqtt_ScheduleOperation ( _mqttOperation_t pOperation,
IotTaskPoolRoutine_t  jobRoutine,
uint32_t  delay 
)

Schedule an operation for immediate processing.

Parameters
[in]pOperationThe operation to schedule.
[in]jobRoutineThe routine to run for the job. Must be either _IotMqtt_ProcessSend, _IotMqtt_ProcessCompletedOperation, or _IotMqtt_ProcessIncomingPublish.
[in]delayA delay before the operation job should be executed. Pass 0 to execute ASAP.
Returns
IOT_MQTT_SUCCESS or IOT_MQTT_SCHEDULING_ERROR.

◆ _IotMqtt_FindOperation()

_mqttOperation_t* _IotMqtt_FindOperation ( _mqttConnection_t pMqttConnection,
IotMqttOperationType_t  type,
const uint16_t *  pPacketIdentifier 
)

Search a list of MQTT operations pending responses using an operation name and packet identifier. Removes a matching operation from the list if found.

Parameters
[in]pMqttConnectionThe connection associated with the operation.
[in]typeThe operation type to look for.
[in]pPacketIdentifierA packet identifier to match. Pass NULL to ignore.
Returns
Pointer to any matching operation; NULL if no match was found.

◆ _IotMqtt_Notify()

void _IotMqtt_Notify ( _mqttOperation_t pOperation)

Notify of a completed MQTT operation.

Parameters
[in]pOperationThe MQTT operation which completed.

Depending on the parameters passed to a user-facing MQTT function, the notification will cause IotMqtt_Wait to return or invoke a user-provided callback.