IoT_Error_t iot_shadow_action(const char *pThingName, ShadowActions_t action,
		const char *pJsonDocumentToBeSent, fpActionCallback_t callback, void *pCallbackContext,
		uint32_t timeout_seconds, bool isSticky) {

	IoT_Error_t ret_val = SUCCESS;
	bool isCallbackPresent = false;
	bool isClientTokenPresent = false;
	bool isAckWaitListFree = false;
	uint8_t indexAckWaitList;

	if(pThingName == NULL || pJsonDocumentToBeSent == NULL){
		return NULL_VALUE_ERROR;
	}

	if (callback != NULL) {
		isCallbackPresent = true;
	}

	char extractedClientToken[MAX_SIZE_CLIENT_ID_WITH_SEQUENCE];
	isClientTokenPresent = extractClientToken(pJsonDocumentToBeSent, extractedClientToken);

	if (isClientTokenPresent && isCallbackPresent) {
		if (getNextFreeIndexOfAckWaitList(&indexAckWaitList)) {
			isAckWaitListFree = true;
		}

		if(isAckWaitListFree) {
			if (!isSubscriptionPresent(pThingName, action)) {
				ret_val = subscribeToShadowActionAcks(pThingName, action, isSticky);
			} else {
				incrementSubscriptionCnt(pThingName, action, isSticky);
			}
		}
		else {
			ret_val = FAILURE;
		}
	}


	if (ret_val == SUCCESS) {
		ret_val = publishToShadowAction(pThingName, action, pJsonDocumentToBeSent);
	}

	if (isClientTokenPresent && isCallbackPresent && ret_val == SUCCESS && isAckWaitListFree) {
		addToAckWaitList(indexAckWaitList, pThingName, action, extractedClientToken, callback, pCallbackContext,
				timeout_seconds);
	}
	return ret_val;
}
IoT_Error_t aws_iot_shadow_internal_action(const char *pThingName, ShadowActions_t action,
										   const char *pJsonDocumentToBeSent, fpActionCallback_t callback,
										   void *pCallbackContext, uint32_t timeout_seconds, bool isSticky) {
	IoT_Error_t ret_val = AWS_SUCCESS;
	bool isClientTokenPresent = false;
	bool isAckWaitListFree = false;
	uint8_t indexAckWaitList;
	char extractedClientToken[MAX_SIZE_CLIENT_ID_WITH_SEQUENCE];

	FUNC_ENTRY;

	if(NULL == pThingName || NULL == pJsonDocumentToBeSent) {
		FUNC_EXIT_RC(NULL_VALUE_ERROR);
	}

	isClientTokenPresent = extractClientToken(pJsonDocumentToBeSent, extractedClientToken);

	if(isClientTokenPresent && (NULL != callback)) {
		if(getNextFreeIndexOfAckWaitList(&indexAckWaitList)) {
			isAckWaitListFree = true;
		}

		if(isAckWaitListFree) {
			if(!isSubscriptionPresent(pThingName, action)) {
				ret_val = subscribeToShadowActionAcks(pThingName, action, isSticky);
			} else {
				incrementSubscriptionCnt(pThingName, action, isSticky);
			}
		}
		else {
			ret_val = AWS_FAILURE;
		}
	}

	if(AWS_SUCCESS == ret_val) {
		ret_val = publishToShadowAction(pThingName, action, pJsonDocumentToBeSent);
	}

	if(isClientTokenPresent && (NULL != callback) && (AWS_SUCCESS == ret_val) && isAckWaitListFree) {
		addToAckWaitList(indexAckWaitList, pThingName, action, extractedClientToken, callback, pCallbackContext,
						 timeout_seconds);
	}

	FUNC_EXIT_RC(ret_val);
}