FreeRTOS
aws_shadow.h
Go to the documentation of this file.
1 /*
2  * FreeRTOS
3  * Copyright (C) 2017 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  * http://aws.amazon.com/freertos
23  * http://www.FreeRTOS.org
24  */
25 
31 #ifndef _AWS_SHADOW_H_
32 #define _AWS_SHADOW_H_
33 
34 #include "FreeRTOS.h"
35 
36 #include "aws_mqtt_agent.h"
37 
38 
42 typedef void * ShadowClientHandle_t;
43 
57 #define eShadowJSMNPart ( -3 )
58 #define eShadowJSMNInval ( -2 )
59 #define eShadowJSMNNoMem ( -1 )
60 
63 #define eShadowSuccess ( 0 )
64 
75 #define eShadowTimeout ( 1 )
76 
79 #define eShadowFailure ( 2 )
80 
83 #define eShadowUnknown ( 3 )
84 
88 #define eShadowRejectedBadRequest ( 400 )
89 #define eShadowRejectedUnauthorized ( 401 )
90 #define eShadowRejectedForbidden ( 403 )
91 #define eShadowRejectedNotFound ( 404 )
92 #define eShadowRejectedConflict ( 409 )
93 #define eShadowRejectedPayloadTooLarge ( 413 )
94 #define eShadowRejectedUnsupportedMediaType ( 415 )
95 #define eShadowRejectedTooManyRequests ( 429 )
96 #define eShadowRejectedInternalServerError ( 500 )
97 typedef int16_t ShadowReturnCode_t;
108 {
115 
119 typedef struct ShadowCreateParams
120 {
128 
137 
144 typedef struct ShadowOperationParams
145 {
147  const char * pcThingName;
148 
155  const char * pcData;
156 
167  uint32_t ulDataLength;
168 
176  MQTTBufferHandle_t xBuffer;
177 
190 
196 
221 typedef BaseType_t ( * ShadowUpdatedCallback_t )( void * pvUserData,
222  const char * const pcThingName,
223  const char * const pcUpdateDocument,
224  uint32_t ulDocumentLength,
225  MQTTBufferHandle_t xBuffer );
226 
237 typedef void ( * ShadowDeletedCallback_t )( void * pvUserData,
238  const char * const pcThingName );
239 
264 typedef BaseType_t ( * ShadowDeltaCallback_t )( void * pvUserData,
265  const char * const pcThingName,
266  const char * const pcDeltaDocument,
267  uint32_t ulDocumentLength,
268  MQTTBufferHandle_t xBuffer );
269 
273 typedef struct ShadowCallbackParams
274 {
276  const char * pcThingName;
277 
285 
293 
302 
321 ShadowReturnCode_t SHADOW_ClientCreate( ShadowClientHandle_t * pxShadowClientHandle,
322  const ShadowCreateParams_t * const pxShadowCreateParams );
323 
340 ShadowReturnCode_t SHADOW_ClientConnect( ShadowClientHandle_t xShadowClientHandle,
341  MQTTAgentConnectParams_t * const pxConnectParams,
342  TickType_t xTimeoutTicks );
343 
358 ShadowReturnCode_t SHADOW_ClientDisconnect( ShadowClientHandle_t xShadowClientHandle );
359 
371 ShadowReturnCode_t SHADOW_ClientDelete( ShadowClientHandle_t xShadowClientHandle );
372 
392 ShadowReturnCode_t SHADOW_Update( ShadowClientHandle_t xShadowClientHandle,
393  ShadowOperationParams_t * const pxUpdateParams,
394  TickType_t xTimeoutTicks );
395 
415 ShadowReturnCode_t SHADOW_Get( ShadowClientHandle_t xShadowClientHandle,
416  ShadowOperationParams_t * const pxGetParams,
417  TickType_t xTimeoutTicks );
418 
438 ShadowReturnCode_t SHADOW_Delete( ShadowClientHandle_t xShadowClientHandle,
439  ShadowOperationParams_t * const pxDeleteParams,
440  TickType_t xTimeoutTicks );
441 
463 ShadowReturnCode_t SHADOW_RegisterCallbacks( ShadowClientHandle_t xShadowClientHandle,
464  ShadowCallbackParams_t * const pxCallbackParams,
465  TickType_t xTimeoutTicks );
466 
488 ShadowReturnCode_t SHADOW_ReturnMQTTBuffer( ShadowClientHandle_t xShadowClientHandle,
489  MQTTBufferHandle_t xBufferHandle );
490 
491 #endif /* _AWS_SHADOW_H_ */
MQTTAgentHandle_t xMQTTClientHandle
Handle of a shared MQTT client.
Definition: aws_shadow.h:135
ShadowReturnCode_t SHADOW_Delete(ShadowClientHandle_t xShadowClientHandle, ShadowOperationParams_t *const pxDeleteParams, TickType_t xTimeoutTicks)
Delete a Thing Shadow in the cloud.
const char * pcThingName
Thing name of Shadow.
Definition: aws_shadow.h:147
ShadowDeletedCallback_t xShadowDeletedCallback
Called to notify users that another client has deleted the Thing Shadow.
Definition: aws_shadow.h:292
struct ShadowCreateParams ShadowCreateParams_t
Parameters to pass into SHADOW_ClientCreate.
BaseType_t(* ShadowDeltaCallback_t)(void *pvUserData, const char *const pcThingName, const char *const pcDeltaDocument, uint32_t ulDocumentLength, MQTTBufferHandle_t xBuffer)
Function header of a callback function registered for /update/delta.
Definition: aws_shadow.h:264
enum ShadowMQTTClientType ShadowMQTTClientType_t
Type of MQTT client in a new Shadow Client.
uint8_t ucKeepSubscriptions
Controls whether topic subscriptions remain active after a Shadow operation completes.
Definition: aws_shadow.h:189
ShadowReturnCode_t SHADOW_ClientCreate(ShadowClientHandle_t *pxShadowClientHandle, const ShadowCreateParams_t *const pxShadowCreateParams)
Create a new Shadow Client.
struct ShadowCallbackParams ShadowCallbackParams_t
Parameters to SHADOW_RegisterCallbacks.
ShadowReturnCode_t SHADOW_ReturnMQTTBuffer(ShadowClientHandle_t xShadowClientHandle, MQTTBufferHandle_t xBufferHandle)
Return an MQTT Buffer to the MQTT client.
void * MQTTAgentHandle_t
Opaque handle to represent an MQTT client.
ShadowReturnCode_t SHADOW_ClientDelete(ShadowClientHandle_t xShadowClientHandle)
Free resources used by a Shadow Client.
ShadowMQTTClientType
Type of MQTT client in a new Shadow Client.
Definition: aws_shadow.h:107
MQTTQoS_t
Quality of Service (QoS).
Definition: aws_mqtt_lib.h:153
struct ShadowOperationParams ShadowOperationParams_t
Parameters for a Shadow API operation.
ShadowMQTTClientType_t xMQTTClientType
MQTT Client type.
Definition: aws_shadow.h:127
ShadowReturnCode_t SHADOW_Update(ShadowClientHandle_t xShadowClientHandle, ShadowOperationParams_t *const pxUpdateParams, TickType_t xTimeoutTicks)
Update a Thing Shadow.
MQTTBufferHandle_t xBuffer
Output parameter of SHADOW_Get.
Definition: aws_shadow.h:176
MQTTQoS_t xQoS
MQTT QoS when publishing from the Shadow Client to the Shadow Service.
Definition: aws_shadow.h:194
const char * pcThingName
Thing Name for which callbacks are registered.
Definition: aws_shadow.h:276
BaseType_t(* ShadowUpdatedCallback_t)(void *pvUserData, const char *const pcThingName, const char *const pcUpdateDocument, uint32_t ulDocumentLength, MQTTBufferHandle_t xBuffer)
Function signature of a callback function registered for /update/documents.
Definition: aws_shadow.h:221
ShadowReturnCode_t SHADOW_ClientDisconnect(ShadowClientHandle_t xShadowClientHandle)
Disconnect from the Shadow service.
ShadowReturnCode_t SHADOW_Get(ShadowClientHandle_t xShadowClientHandle, ShadowOperationParams_t *const pxGetParams, TickType_t xTimeoutTicks)
Get a Thing Shadow from the cloud.
ShadowReturnCode_t SHADOW_RegisterCallbacks(ShadowClientHandle_t xShadowClientHandle, ShadowCallbackParams_t *const pxCallbackParams, TickType_t xTimeoutTicks)
Register callback functions.
Parameters passed to the MQTT_AGENT_Connect API.
ShadowUpdatedCallback_t xShadowUpdatedCallback
Called to notify users that a Thing Shadow has been updated.
Definition: aws_shadow.h:284
ShadowDeltaCallback_t xShadowDeltaCallback
Called to notify users that a delta document has been generated.
Definition: aws_shadow.h:300
Parameters to SHADOW_RegisterCallbacks.
Definition: aws_shadow.h:273
uint32_t ulDataLength
Input parameter for SHADOW_Update; output parameter of SHADOW_Get.
Definition: aws_shadow.h:167
Parameters for a Shadow API operation.
Definition: aws_shadow.h:144
const char * pcData
Input parameter for SHADOW_Update; output parameter of SHADOW_Get.
Definition: aws_shadow.h:155
Parameters to pass into SHADOW_ClientCreate.
Definition: aws_shadow.h:119
ShadowReturnCode_t SHADOW_ClientConnect(ShadowClientHandle_t xShadowClientHandle, MQTTAgentConnectParams_t *const pxConnectParams, TickType_t xTimeoutTicks)
Connect to the Shadow service.
void * ShadowClientHandle_t
The handle of a Shadow Client.
Definition: aws_shadow.h:42
void(* ShadowDeletedCallback_t)(void *pvUserData, const char *const pcThingName)
Function header of a callback function registered for /delete/accepted.
Definition: aws_shadow.h:237
MQTT Agent Interface.