AWS IoT Device SDK C: Shadow
AWS IoT Device Shadow library
Return to main page ↑
AwsIotShadow_Wait

Wait for a Shadow operation to complete.

uint32_t timeoutMs,
const char ** const pShadowDocument,
size_t * const pShadowDocumentLength );

This function blocks to wait for a delete, get, or update to complete. These operations are by default asynchronous; the function calls queue an operation for processing, and a callback is invoked once the operation is complete.

To use this function, the flag AWS_IOT_SHADOW_FLAG_WAITABLE must have been set in the operation's function call. Additionally, this function must always be called with any waitable operation to clean up resources.

Regardless of its return value, this function always clean up resources used by the waitable operation. This means operation is invalidated as soon as this function returns, even if it returns AWS_IOT_SHADOW_TIMEOUT or another error.

Parameters
[in]operationReference to the Shadow operation to wait for. The flag AWS_IOT_SHADOW_FLAG_WAITABLE must have been set for this operation.
[in]timeoutMsHow long to wait before returning AWS_IOT_SHADOW_TIMEOUT.
[out]pShadowDocumentA pointer to a buffer containing the Shadow document retrieved by a Shadow get is placed here. The buffer was allocated with the function AwsIotShadowDocumentInfo_t.mallocDocument passed to AwsIotShadow_GetAsync. This parameter is only valid for a Shadow get and ignored for other Shadow operations. This output parameter is only valid if this function returns AWS_IOT_SHADOW_SUCCESS.
[out]pShadowDocumentLengthThe length of the Shadow document in pShadowDocument is placed here. This parameter is only valid for a Shadow get and ignored for other Shadow operations. This output parameter is only valid if this function returns AWS_IOT_SHADOW_SUCCESS.
Returns
One of the following:

Example 1 (Shadow Update)

AwsIotShadowDocumentInfo_t updateInfo = { ... };
// Reference and timeout.
uint32_t timeout = 5000; // 5 seconds
// Shadow update operation.
result = AwsIotShadow_UpdateAsync( mqttConnection,
&updateInfo,
NULL,
&updateOperation );
// Update should have returned AWS_IOT_SHADOW_STATUS_PENDING. The call to wait
// returns once the result of the update is available or the timeout expires.
{
// The last two parameters are ignored for a Shadow update.
result = AwsIotShadow_Wait( updateOperation, timeout, NULL, NULL );
// After the call to wait, the result of the update is known
// (not AWS_IOT_SHADOW_STATUS_PENDING).
assert( result != AWS_IOT_SHADOW_STATUS_PENDING );
}

Example 2 (Shadow Get)

AwsIotShadowDocumentInfo_t getInfo = { ... };
// Reference and timeout.
uint32_t timeout = 5000; // 5 seconds
// Buffer pointer and size for retrieved Shadow document.
const char * pShadowDocument = NULL;
size_t documentLength = 0;
// Buffer allocation function must be set for a waitable Shadow get.
getInfo.get.mallocDocument = malloc;
// Shadow get operation.
result = AwsIotShadow_GetAsync( mqttConnection,
&getInfo,
NULL,
&getOperation );
// Get should have returned AWS_IOT_SHADOW_STATUS_PENDING. The call to wait
// returns once the result of the get is available or the timeout expires.
{
// The last two parameters must be set for a Shadow get.
result = AwsIotShadow_Wait( getOperation, timeout, &pShadowDocument, &documentLength );
// After the call to wait, the result of the get is known
// (not AWS_IOT_SHADOW_STATUS_PENDING).
assert( result != AWS_IOT_SHADOW_STATUS_PENDING );
// The retrieved Shadow document is only valid for a successful Shadow get.
if( result == AWS_IOT_SHADOW_SUCCESS )
{
// Do something with the Shadow document...
// Free the Shadow document when finished.
free( pShadowDocument );
}
}