this is fork and i will modify for STM32

Fork of AWS-test by Pierre-Marie Ancèle

Committer:
bcjun@aname.co.kr
Date:
Fri Aug 04 15:34:19 2017 +0900
Revision:
3:1ef624d94403
Parent:
2:db59f45ad3d3
add esp82660-driver for NUCLEO_F401RE target.

Who changed what in which revision?

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