29 #ifndef AWS_IOT_SHADOW_INTERNAL_H_ 30 #define AWS_IOT_SHADOW_INTERNAL_H_ 33 #include "iot_config.h" 56 #if AWS_IOT_SHADOW_ENABLE_ASSERTS == 1 57 #ifndef AwsIotShadow_Assert 58 #ifdef Iot_DefaultAssert 59 #define AwsIotShadow_Assert( expression ) Iot_DefaultAssert( expression ) 61 #error "Asserts are enabled for Shadow, but AwsIotShadow_Assert is not defined" 65 #define AwsIotShadow_Assert( expression ) 69 #ifdef AWS_IOT_LOG_LEVEL_SHADOW 70 #define LIBRARY_LOG_LEVEL AWS_IOT_LOG_LEVEL_SHADOW 72 #ifdef IOT_LOG_LEVEL_GLOBAL 73 #define LIBRARY_LOG_LEVEL IOT_LOG_LEVEL_GLOBAL 75 #define LIBRARY_LOG_LEVEL IOT_LOG_NONE 79 #define LIBRARY_LOG_NAME ( "Shadow" ) 86 #if IOT_STATIC_MEMORY_ONLY == 1 108 #define AwsIotShadow_MallocString Iot_MallocMessageBuffer 115 #define AwsIotShadow_FreeString Iot_FreeMessageBuffer 131 #ifndef AwsIotShadow_MallocOperation 132 #ifdef Iot_DefaultMalloc 133 #define AwsIotShadow_MallocOperation Iot_DefaultMalloc 135 #error "No malloc function defined for AwsIotShadow_MallocOperation" 139 #ifndef AwsIotShadow_FreeOperation 140 #ifdef Iot_DefaultFree 141 #define AwsIotShadow_FreeOperation Iot_DefaultFree 143 #error "No free function defined for AwsIotShadow_FreeOperation" 147 #ifndef AwsIotShadow_MallocString 148 #ifdef Iot_DefaultMalloc 149 #define AwsIotShadow_MallocString Iot_DefaultMalloc 151 #error "No malloc function defined for AwsIotShadow_MallocString" 155 #ifndef AwsIotShadow_FreeString 156 #ifdef Iot_DefaultFree 157 #define AwsIotShadow_FreeString Iot_DefaultFree 159 #error "No free function defined for AwsIotShadow_FreeString" 163 #ifndef AwsIotShadow_MallocSubscription 164 #ifdef Iot_DefaultMalloc 165 #define AwsIotShadow_MallocSubscription Iot_DefaultMalloc 167 #error "No malloc function defined for AwsIotShadow_MallocSubscription" 171 #ifndef AwsIotShadow_FreeSubscription 172 #ifdef Iot_DefaultFree 173 #define AwsIotShadow_FreeSubscription Iot_DefaultFree 175 #error "No free function defined for AwsIotShadow_FreeSubscription" 186 #ifndef AWS_IOT_SHADOW_DEFAULT_MQTT_TIMEOUT_MS 187 #define AWS_IOT_SHADOW_DEFAULT_MQTT_TIMEOUT_MS ( 5000 ) 196 #define SHADOW_OPERATION_COUNT ( 3U ) 204 #define SHADOW_CALLBACK_COUNT ( 2 ) 209 #define SHADOW_DELETE_OPERATION_STRING "/shadow/delete" 214 #define SHADOW_DELETE_OPERATION_STRING_LENGTH ( ( uint16_t ) ( sizeof( SHADOW_DELETE_OPERATION_STRING ) - 1U ) ) 219 #define SHADOW_GET_OPERATION_STRING "/shadow/get" 224 #define SHADOW_GET_OPERATION_STRING_LENGTH ( ( uint16_t ) ( sizeof( SHADOW_GET_OPERATION_STRING ) - 1U ) ) 229 #define SHADOW_UPDATE_OPERATION_STRING "/shadow/update" 234 #define SHADOW_UPDATE_OPERATION_STRING_LENGTH ( ( uint16_t ) ( sizeof( SHADOW_UPDATE_OPERATION_STRING ) - 1U ) ) 239 #define SHADOW_DELTA_SUFFIX "/delta" 244 #define SHADOW_DELTA_SUFFIX_LENGTH ( ( uint16_t ) ( sizeof( SHADOW_DELTA_SUFFIX ) - 1U ) ) 249 #define SHADOW_UPDATED_SUFFIX "/documents" 254 #define SHADOW_UPDATED_SUFFIX_LENGTH ( ( uint16_t ) ( sizeof( SHADOW_UPDATED_SUFFIX ) - 1U ) ) 259 #define SHADOW_LONGEST_SUFFIX_LENGTH SHADOW_UPDATED_SUFFIX_LENGTH 268 #define SHADOW_CONVERT_STATUS_CODE_MQTT_TO_SHADOW( X ) \ 269 ( ( X ) == IOT_MQTT_SUCCESS ) ? AWS_IOT_SHADOW_SUCCESS : \ 270 ( ( X ) == IOT_MQTT_NO_MEMORY ) ? AWS_IOT_SHADOW_NO_MEMORY : \ 271 AWS_IOT_SHADOW_MQTT_ERROR 278 typedef enum _shadowOperationType
293 typedef enum _shadowCallbackType
304 typedef struct _shadowSubscription
329 typedef struct _shadowOperation
351 void *( *mallocDocument )( size_t );
374 #if LIBRARY_LOG_LEVEL > IOT_LOG_NONE 375 extern const char *
const _pAwsIotShadowOperationNames[];
376 extern const char *
const _pAwsIotShadowCallbackNames[];
433 const char * pThingName,
434 size_t thingNameLength,
435 char ** pTopicBuffer,
436 uint16_t * pOperationTopicLength );
452 const char * pThingName,
453 size_t thingNameLength,
495 size_t thingNameLength,
496 bool createIfNotFound );
545 uint16_t operationTopicLength,
546 AwsIotMqttCallbackFunction_t callback );
583 size_t errorDocumentLength );
Represents a Shadow subscriptions object.
Definition: aws_iot_shadow_internal.h:304
size_t clientTokenLength
Length of client token.
Definition: aws_iot_shadow_internal.h:361
Definition: aws_iot_shadow_internal.h:287
IotSemaphore_t waitSemaphore
Semaphore to be used with AwsIotShadow_Wait.
Definition: aws_iot_shadow_internal.h:368
void AwsIotShadow_FreeOperation(void *ptr)
Free a _shadowOperation_t. This function should have the same signature as free.
Definition: aws_iot_shadow_static_memory.c:114
AwsIotShadowError_t _AwsIotShadow_IncrementReferences(_shadowOperation_t *pOperation, char *pTopicBuffer, uint16_t operationTopicLength, AwsIotMqttCallbackFunction_t callback)
Increment the reference count of a Shadow subscriptions object.
Definition: aws_iot_shadow_subscription.c:270
Definition: aws_iot_shadow_internal.h:281
void _AwsIotShadow_DecrementReferences(_shadowOperation_t *pOperation, char *pTopicBuffer, _shadowSubscription_t **pRemovedSubscription)
Decrement the reference count of a Shadow subscriptions object.
Definition: aws_iot_shadow_subscription.c:345
void * AwsIotShadow_MallocSubscription(size_t size)
Allocate a _shadowSubscription_t. This function should have the same signature as malloc...
Definition: aws_iot_shadow_static_memory.c:126
_shadowOperationType_t type
Operation type.
Definition: aws_iot_shadow_internal.h:334
IotMutex_t _AwsIotShadowPendingOperationsMutex
Protects _AwsIotShadowPendingOperations from concurrent access.
Definition: aws_iot_shadow_operation.c:183
IotLink_t link
List link member.
Definition: aws_iot_shadow_internal.h:331
char * pTopicBuffer
Buffer allocated for removing Shadow topics.
Definition: aws_iot_shadow_internal.h:317
Definition: aws_iot_shadow_internal.h:295
_shadowSubscription_t * _AwsIotShadow_FindSubscription(const char *pThingName, size_t thingNameLength, bool createIfNotFound)
Find a Shadow subscription object. May create a new subscription object and adds it to the subscripti...
Definition: aws_iot_shadow_subscription.c:99
_shadowOperationType_t
Enumerations representing each of the Shadow library's API functions.
Definition: aws_iot_shadow_internal.h:278
const char * pDocument
Retrieved Shadow document.
Definition: aws_iot_shadow_internal.h:353
AwsIotShadowError_t _AwsIotShadow_ParseErrorDocument(const char *pErrorDocument, size_t errorDocumentLength)
Parse a Shadow error document.
Definition: aws_iot_shadow_parser.c:130
AwsIotShadowError_t
Return codes of Shadow functions.
Definition: aws_iot_shadow_types.h:88
_shadowSubscription_t * pSubscription
Shadow subscriptions object associated with this operation.
Definition: aws_iot_shadow_internal.h:339
Definition: aws_iot_shadow_internal.h:296
uint32_t _AwsIotShadowMqttTimeoutMs
Timeout used for MQTT operations.
Definition: aws_iot_shadow_api.c:168
IotListDouble_t _AwsIotShadowPendingOperations
List of active Shadow operations awaiting a response from the Shadow service.
Definition: aws_iot_shadow_operation.c:178
struct _mqttConnection * IotMqttConnection_t
User-facing functions of the Shadow library.
uint32_t flags
Flags passed to operation API function.
Definition: aws_iot_shadow_internal.h:335
Information on a user-provided Shadow callback function.
Definition: aws_iot_shadow_types.h:436
void _AwsIotShadow_DestroyOperation(void *pData)
Free resources used to record a Shadow operation. This is called when the operation completes...
Definition: aws_iot_shadow_operation.c:736
AwsIotShadowError_t _AwsIotShadow_CreateOperation(_shadowOperation_t **pNewOperation, _shadowOperationType_t type, uint32_t flags, const AwsIotShadowCallbackInfo_t *pCallbackInfo)
Create a record for a new in-progress Shadow operation.
Definition: aws_iot_shadow_operation.c:672
Definition: aws_iot_shadow_internal.h:283
Internal structure representing a single Shadow operation (DELETE, GET, or UPDATE).
Definition: aws_iot_shadow_internal.h:329
IotListDouble_t _AwsIotShadowSubscriptions
List of active Shadow subscriptions objects.
Definition: aws_iot_shadow_subscription.c:63
IotMutex_t _AwsIotShadowSubscriptionsMutex
Protects _AwsIotShadowSubscriptions from concurrent access.
Definition: aws_iot_shadow_subscription.c:68
const char * pClientToken
Client token in update document.
Definition: aws_iot_shadow_internal.h:360
#define SHADOW_OPERATION_COUNT
The number of currently available Shadow operations.
Definition: aws_iot_shadow_internal.h:196
Information on a Shadow document for AwsIotShadow_GetAsync or AwsIotShadow_UpdateAsync.
Definition: aws_iot_shadow_types.h:469
AwsIotShadowError_t status
Status of operation.
Definition: aws_iot_shadow_internal.h:336
AwsIotShadowError_t _AwsIotShadow_GenerateShadowTopic(_shadowOperationType_t type, const char *pThingName, size_t thingNameLength, char **pTopicBuffer, uint16_t *pOperationTopicLength)
Fill a buffer with a Shadow topic.
Definition: aws_iot_shadow_operation.c:768
Definition: aws_iot_shadow_internal.h:282
size_t documentLength
Length of retrieved Shadow document.
Definition: aws_iot_shadow_internal.h:354
void _AwsIotShadow_DestroySubscription(void *pData)
Free resources used for a Shadow subscription object.
Definition: aws_iot_shadow_subscription.c:254
AwsIotShadowError_t _AwsIotShadow_ProcessOperation(IotMqttConnection_t mqttConnection, const char *pThingName, size_t thingNameLength, _shadowOperation_t *pOperation, const AwsIotShadowDocumentInfo_t *pDocumentInfo)
Process a Shadow operation by sending the necessary MQTT packets.
Definition: aws_iot_shadow_operation.c:819
size_t thingNameLength
Length of Thing Name.
Definition: aws_iot_shadow_internal.h:319
Definition: aws_iot_shadow_internal.h:286
AwsIotShadowCallbackInfo_t callback
User-provided callback function and parameter.
Definition: aws_iot_shadow_internal.h:369
_shadowCallbackType_t
Enumerations representing each of the Shadow callback functions.
Definition: aws_iot_shadow_internal.h:293
IotMqttConnection_t mqttConnection
MQTT connection associated with this operation.
Definition: aws_iot_shadow_internal.h:338
_shadowOperationType_t _AwsIotShadow_IntToShadowOperationType(uint32_t n)
Convert an integer to the shadow operation type.
Definition: aws_iot_shadow_operation.c:187
AwsIotShadowCallbackType_t _AwsIotShadow_IntToShadowCallbackType(uint32_t n)
Convert an integer to the shadow callback type.
Definition: aws_iot_shadow_operation.c:223
void AwsIotShadow_FreeSubscription(void *ptr)
Free a _shadowSubscription_t. This function should have the same signature as free.
Definition: aws_iot_shadow_static_memory.c:148
#define SHADOW_CALLBACK_COUNT
The number of currently available Shadow callbacks.
Definition: aws_iot_shadow_internal.h:204
AwsIotShadowCallbackType_t
Types of Shadow library callbacks.
Definition: aws_iot_shadow_types.h:345
void _AwsIotShadow_RemoveSubscription(_shadowSubscription_t *pSubscription, _shadowSubscription_t **pRemovedSubscription)
Remove a Shadow subscription object from the subscription list if unreferenced.
Definition: aws_iot_shadow_subscription.c:163
IotLink_t link
List link member.
Definition: aws_iot_shadow_internal.h:306
void * AwsIotShadow_MallocOperation(size_t size)
Allocate a _shadowOperation_t. This function should have the same signature as malloc.
Definition: aws_iot_shadow_static_memory.c:91