AWS IoT Device SDK C: Jobs
AWS IoT Jobs library
Return to main page ↑
aws_iot_jobs_operation.c File Reference

Implements functions that process Jobs operations. More...

#include "iot_config.h"
#include <string.h>
#include "private/aws_iot_jobs_internal.h"
#include "platform/iot_threads.h"
#include "iot_error.h"
#include "iot_mqtt.h"

Data Structures

struct  _operationMatchParams_t
 First parameter to _jobsOperation_match. More...
 

Functions

static bool _jobsOperation_match (const IotLink_t *pOperationLink, void *pMatch)
 Match a received Jobs response with a Jobs operation awaiting a response. More...
 
static void _getPendingCallback (void *pArgument, IotMqttCallbackParam_t *pMessage)
 Invoked when a Jobs response is received for Jobs GET PENDING. More...
 
static void _startNextCallback (void *pArgument, IotMqttCallbackParam_t *pMessage)
 Invoked when a Jobs response is received for a Jobs START NEXT. More...
 
static void _describeCallback (void *pArgument, IotMqttCallbackParam_t *pMessage)
 Invoked when a Jobs response is received for Jobs DESCRIBE. More...
 
static void _updateCallback (void *pArgument, IotMqttCallbackParam_t *pMessage)
 Invoked when a Jobs response is received for a Jobs UPDATE. More...
 
static void _commonOperationCallback (_jobsOperationType_t type, IotMqttCallbackParam_t *pMessage)
 Common function for processing received Jobs responses. More...
 
static void _notifyCompletion (_jobsOperation_t *pOperation)
 Notify of a completed Jobs operation. More...
 
static AwsIotJobsError_t _findSubscription (const AwsIotJobsRequestInfo_t *pRequestInfo, char *pTopicBuffer, uint16_t operationTopicLength, _jobsOperation_t *pOperation, bool *pFreeTopicBuffer)
 Get a Jobs subscription to use with a Jobs operation. More...
 
AwsIotJobsError_t _AwsIotJobs_CreateOperation (_jobsOperationType_t type, const AwsIotJobsRequestInfo_t *pRequestInfo, const _jsonRequestContents_t *pRequestContents, uint32_t flags, const AwsIotJobsCallbackInfo_t *pCallbackInfo, _jobsOperation_t **pNewOperation)
 Create a record for a new in-progress Jobs operation. More...
 
void _AwsIotJobs_DestroyOperation (void *pData)
 Free resources used to record a Jobs operation. This is called when the operation completes. More...
 
AwsIotJobsError_t _AwsIotJobs_GenerateJobsTopic (_jobsOperationType_t type, const AwsIotJobsRequestInfo_t *pRequestInfo, char **pTopicBuffer, uint16_t *pOperationTopicLength)
 Fill a buffer with a Jobs topic. More...
 
AwsIotJobsError_t _AwsIotJobs_ProcessOperation (const AwsIotJobsRequestInfo_t *pRequestInfo, _jobsOperation_t *pOperation)
 Process a Jobs operation by sending the necessary MQTT packets. More...
 

Variables

IotListDouble_t _AwsIotJobsPendingOperations = { 0 }
 List of active Jobs operations awaiting a response from the Jobs service.
 
IotMutex_t _AwsIotJobsPendingOperationsMutex
 Protects _AwsIotJobsPendingOperations from concurrent access.
 

Detailed Description

Implements functions that process Jobs operations.

Function Documentation

◆ _jobsOperation_match()

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

Match a received Jobs response with a Jobs operation awaiting a response.

Parameters
[in]pOperationLinkPointer to the link member of the _jobsOperation_t to check.
[in]pMatchPointer to an _operationMatchParams_t.
Returns
true if pMatch matches the received response; false otherwise.

◆ _getPendingCallback()

static void _getPendingCallback ( void *  pArgument,
IotMqttCallbackParam_t pMessage 
)
static

Invoked when a Jobs response is received for Jobs GET PENDING.

Parameters
[in]pArgumentIgnored.
[in]pMessageReceived Jobs response (as an MQTT PUBLISH message).

◆ _startNextCallback()

static void _startNextCallback ( void *  pArgument,
IotMqttCallbackParam_t pMessage 
)
static

Invoked when a Jobs response is received for a Jobs START NEXT.

Parameters
[in]pArgumentIgnored.
[in]pMessageReceived Jobs response (as an MQTT PUBLISH message).

◆ _describeCallback()

static void _describeCallback ( void *  pArgument,
IotMqttCallbackParam_t pMessage 
)
static

Invoked when a Jobs response is received for Jobs DESCRIBE.

Parameters
[in]pArgumentIgnored.
[in]pMessageReceived Jobs response (as an MQTT PUBLISH message).

◆ _updateCallback()

static void _updateCallback ( void *  pArgument,
IotMqttCallbackParam_t pMessage 
)
static

Invoked when a Jobs response is received for a Jobs UPDATE.

Parameters
[in]pArgumentIgnored.
[in]pMessageReceived Jobs response (as an MQTT PUBLISH message).

◆ _commonOperationCallback()

static void _commonOperationCallback ( _jobsOperationType_t  type,
IotMqttCallbackParam_t pMessage 
)
static

Common function for processing received Jobs responses.

Parameters
[in]typeGET PENDING, START NEXT, DESCRIBE, or UPDATE.
[in]pMessageReceived Jobs response (as an MQTT PUBLISH message).

◆ _notifyCompletion()

static void _notifyCompletion ( _jobsOperation_t pOperation)
static

Notify of a completed Jobs operation.

Parameters
[in]pOperationThe operation which completed.

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

◆ _findSubscription()

static AwsIotJobsError_t _findSubscription ( const AwsIotJobsRequestInfo_t pRequestInfo,
char *  pTopicBuffer,
uint16_t  operationTopicLength,
_jobsOperation_t pOperation,
bool *  pFreeTopicBuffer 
)
static

Get a Jobs subscription to use with a Jobs operation.

This function may use an existing Jobs subscription, or it may allocate a new one.

Parameters
[in]pRequestInfoCommon Jobs request parameters.
[in]pTopicBufferContains the topic to use for subscribing.
[in]operationTopicLengthThe length of the base topic in pTopicBuffer.
[in]pOperationJobs operation that needs a subscription.
[out]pFreeTopicBufferWhether the caller may free pTopicBuffer (which may be assigned to a subscription).
Returns
AWS_IOT_JOBS_SUCCESS or AWS_IOT_JOBS_NO_MEMORY

◆ _AwsIotJobs_CreateOperation()

AwsIotJobsError_t _AwsIotJobs_CreateOperation ( _jobsOperationType_t  type,
const AwsIotJobsRequestInfo_t pRequestInfo,
const _jsonRequestContents_t pRequestContents,
uint32_t  flags,
const AwsIotJobsCallbackInfo_t pCallbackInfo,
_jobsOperation_t **  pNewOperation 
)

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

Parameters
[in]typeThe type of Jobs operation for the request.
[in]pRequestInfoCommon Jobs request parameters.
[in]pRequestContentsAdditional values to place in the JSON document, depending on type.
[in]flagsFlags variables passed to a user-facing Jobs function.
[in]pCallbackInfoUser-provided callback function and parameter.
[out]pNewOperationSet to point to the new operation on success.
Returns
AWS_IOT_JOBS_SUCCESS or AWS_IOT_JOBS_NO_MEMORY

◆ _AwsIotJobs_DestroyOperation()

void _AwsIotJobs_DestroyOperation ( void *  pData)

Free resources used to record a Jobs operation. This is called when the operation completes.

Parameters
[in]pDataThe operation which completed. This parameter is of type void* to match the signature of free.

◆ _AwsIotJobs_GenerateJobsTopic()

AwsIotJobsError_t _AwsIotJobs_GenerateJobsTopic ( _jobsOperationType_t  type,
const AwsIotJobsRequestInfo_t pRequestInfo,
char **  pTopicBuffer,
uint16_t *  pOperationTopicLength 
)

Fill a buffer with a Jobs topic.

Parameters
[in]typeOne of: GET PENDING, START NEXT, DESCRIBE, or UPDATE.
[in]pRequestInfoCommon Jobs request parameters.
[out]pTopicBufferAddress of the buffer for the Jobs topic. If the pointer at this address is NULL, this function will allocate a new buffer; otherwise, it will use the provided buffer.
[out]pOperationTopicLengthLength of the Jobs operation topic (excluding any suffix) placed in pTopicBuffer.
Warning
This function does not check the length of pTopicBuffer! Any provided buffer must be large enough to accommodate the full Jobs topic, plus JOBS_LONGEST_SUFFIX_LENGTH.
Returns
AWS_IOT_JOBS_SUCCESS or AWS_IOT_JOBS_NO_MEMORY. This function will not return AWS_IOT_JOBS_NO_MEMORY when a buffer is provided.

◆ _AwsIotJobs_ProcessOperation()

AwsIotJobsError_t _AwsIotJobs_ProcessOperation ( const AwsIotJobsRequestInfo_t pRequestInfo,
_jobsOperation_t pOperation 
)

Process a Jobs operation by sending the necessary MQTT packets.

Parameters
[in]pRequestInfoCommon Jobs request parameters.
[in]pOperationOperation data to process.
Returns
AWS_IOT_JOBS_STATUS_PENDING on success. On error, one of AWS_IOT_JOBS_NO_MEMORY or AWS_IOT_JOBS_MQTT_ERROR.