V.06 11/3
Dependencies: FT6206 SDFileSystem SPI_TFT_ILI9341 TFT_fonts
Fork of ATT_AWS_IoT_demo by
aws_iot_shadow_actions.cpp
00001 /* 00002 * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"). 00005 * You may not use this file except in compliance with the License. 00006 * A copy of the License is located at 00007 * 00008 * http://aws.amazon.com/apache2.0 00009 * 00010 * or in the "license" file accompanying this file. This file is distributed 00011 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 00012 * express or implied. See the License for the specific language governing 00013 * permissions and limitations under the License. 00014 */ 00015 00016 #include "aws_iot_shadow_actions.h" 00017 00018 #include "aws_iot_log.h" 00019 #include "aws_iot_shadow_json.h" 00020 #include "aws_iot_shadow_records.h" 00021 #include "aws_iot_config.h" 00022 00023 IoT_Error_t iot_shadow_action(MQTTClient_t *pClient, const char *pThingName, ShadowActions_t action, 00024 const char *pJsonDocumentToBeSent, fpActionCallback_t callback, void *pCallbackContext, 00025 uint32_t timeout_seconds, bool isSticky) { 00026 00027 IoT_Error_t ret_val = NONE_ERROR; 00028 bool isCallbackPresent = false; 00029 bool isClientTokenPresent = false; 00030 bool isAckWaitListFree = false; 00031 uint8_t indexAckWaitList; 00032 00033 if(pClient == NULL || pThingName == NULL || pJsonDocumentToBeSent == NULL){ 00034 return NULL_VALUE_ERROR; 00035 } 00036 00037 if (callback != NULL) { 00038 isCallbackPresent = true; 00039 } 00040 00041 char extractedClientToken[MAX_SIZE_CLIENT_ID_WITH_SEQUENCE]; 00042 isClientTokenPresent = extractClientToken(pJsonDocumentToBeSent, extractedClientToken); 00043 00044 if (isClientTokenPresent && isCallbackPresent) { 00045 if (getNextFreeIndexOfAckWaitList(&indexAckWaitList)) { 00046 isAckWaitListFree = true; 00047 } 00048 00049 if(isAckWaitListFree) { 00050 if (!isSubscriptionPresent(pThingName, action)) { 00051 ret_val = subscribeToShadowActionAcks(pThingName, action, isSticky); 00052 } else { 00053 incrementSubscriptionCnt(pThingName, action, isSticky); 00054 } 00055 } 00056 else { 00057 ret_val = GENERIC_ERROR; 00058 } 00059 } 00060 00061 00062 if (ret_val == NONE_ERROR) { 00063 ret_val = publishToShadowAction(pThingName, action, pJsonDocumentToBeSent); 00064 } 00065 00066 if (isClientTokenPresent && isCallbackPresent && ret_val == NONE_ERROR && isAckWaitListFree) { 00067 addToAckWaitList(indexAckWaitList, pThingName, action, extractedClientToken, callback, pCallbackContext, 00068 timeout_seconds); 00069 } 00070 return ret_val; 00071 } 00072
Generated on Tue Jul 12 2022 14:16:19 by 1.7.2