Changes to enabled on-line compiler

Committer:
JMF
Date:
Wed May 30 20:59:51 2018 +0000
Revision:
0:082731ede69f
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JMF 0:082731ede69f 1 /*
JMF 0:082731ede69f 2 * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
JMF 0:082731ede69f 3 *
JMF 0:082731ede69f 4 * Licensed under the Apache License, Version 2.0 (the "License").
JMF 0:082731ede69f 5 * You may not use this file except in compliance with the License.
JMF 0:082731ede69f 6 * A copy of the License is located at
JMF 0:082731ede69f 7 *
JMF 0:082731ede69f 8 * http://aws.amazon.com/apache2.0
JMF 0:082731ede69f 9 *
JMF 0:082731ede69f 10 * or in the "license" file accompanying this file. This file is distributed
JMF 0:082731ede69f 11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
JMF 0:082731ede69f 12 * express or implied. See the License for the specific language governing
JMF 0:082731ede69f 13 * permissions and limitations under the License.
JMF 0:082731ede69f 14 */
JMF 0:082731ede69f 15
JMF 0:082731ede69f 16 /**
JMF 0:082731ede69f 17 * @file aws_iot_shadow_actions.c
JMF 0:082731ede69f 18 * @brief Shadow client Action API definitions
JMF 0:082731ede69f 19 */
JMF 0:082731ede69f 20
JMF 0:082731ede69f 21 #ifdef __cplusplus
JMF 0:082731ede69f 22 extern "C" {
JMF 0:082731ede69f 23 #endif
JMF 0:082731ede69f 24
JMF 0:082731ede69f 25 #include "aws_iot_shadow_actions.h"
JMF 0:082731ede69f 26
JMF 0:082731ede69f 27 #include "aws_iot_log.h"
JMF 0:082731ede69f 28 #include "aws_iot_shadow_json.h"
JMF 0:082731ede69f 29 #include "aws_iot_shadow_records.h"
JMF 0:082731ede69f 30 #include "aws_iot_config.h"
JMF 0:082731ede69f 31
JMF 0:082731ede69f 32 IoT_Error_t aws_iot_shadow_internal_action(const char *pThingName, ShadowActions_t action,
JMF 0:082731ede69f 33 const char *pJsonDocumentToBeSent, size_t jsonSize, fpActionCallback_t callback,
JMF 0:082731ede69f 34 void *pCallbackContext, uint32_t timeout_seconds, bool isSticky) {
JMF 0:082731ede69f 35 IoT_Error_t ret_val = AWS_SUCCESS;
JMF 0:082731ede69f 36 bool isClientTokenPresent = false;
JMF 0:082731ede69f 37 bool isAckWaitListFree = false;
JMF 0:082731ede69f 38 uint8_t indexAckWaitList;
JMF 0:082731ede69f 39 char extractedClientToken[MAX_SIZE_CLIENT_ID_WITH_SEQUENCE];
JMF 0:082731ede69f 40
JMF 0:082731ede69f 41 FUNC_ENTRY;
JMF 0:082731ede69f 42
JMF 0:082731ede69f 43 if(NULL == pThingName || NULL == pJsonDocumentToBeSent) {
JMF 0:082731ede69f 44 FUNC_EXIT_RC(NULL_VALUE_ERROR);
JMF 0:082731ede69f 45 }
JMF 0:082731ede69f 46
JMF 0:082731ede69f 47 isClientTokenPresent = extractClientToken(pJsonDocumentToBeSent, jsonSize, extractedClientToken, MAX_SIZE_CLIENT_ID_WITH_SEQUENCE );
JMF 0:082731ede69f 48
JMF 0:082731ede69f 49 if(isClientTokenPresent && (NULL != callback)) {
JMF 0:082731ede69f 50 if(getNextFreeIndexOfAckWaitList(&indexAckWaitList)) {
JMF 0:082731ede69f 51 isAckWaitListFree = true;
JMF 0:082731ede69f 52 }
JMF 0:082731ede69f 53
JMF 0:082731ede69f 54 if(isAckWaitListFree) {
JMF 0:082731ede69f 55 if(!isSubscriptionPresent(pThingName, action)) {
JMF 0:082731ede69f 56 ret_val = subscribeToShadowActionAcks(pThingName, action, isSticky);
JMF 0:082731ede69f 57 } else {
JMF 0:082731ede69f 58 incrementSubscriptionCnt(pThingName, action, isSticky);
JMF 0:082731ede69f 59 }
JMF 0:082731ede69f 60 }
JMF 0:082731ede69f 61 else {
JMF 0:082731ede69f 62 ret_val = FAILURE;
JMF 0:082731ede69f 63 }
JMF 0:082731ede69f 64 }
JMF 0:082731ede69f 65
JMF 0:082731ede69f 66 if(AWS_SUCCESS == ret_val) {
JMF 0:082731ede69f 67 ret_val = publishToShadowAction(pThingName, action, pJsonDocumentToBeSent);
JMF 0:082731ede69f 68 }
JMF 0:082731ede69f 69
JMF 0:082731ede69f 70 if(isClientTokenPresent && (NULL != callback) && (AWS_SUCCESS == ret_val) && isAckWaitListFree) {
JMF 0:082731ede69f 71 addToAckWaitList(indexAckWaitList, pThingName, action, extractedClientToken, callback, pCallbackContext,
JMF 0:082731ede69f 72 timeout_seconds);
JMF 0:082731ede69f 73 }
JMF 0:082731ede69f 74
JMF 0:082731ede69f 75 FUNC_EXIT_RC(ret_val);
JMF 0:082731ede69f 76 }
JMF 0:082731ede69f 77
JMF 0:082731ede69f 78 #ifdef __cplusplus
JMF 0:082731ede69f 79 }
JMF 0:082731ede69f 80 #endif