OCStackResult HandleKeepAliveResponse(const CAEndpoint_t *endPoint, OCStackResult responseCode, const OCRepPayload *respPayload) { VERIFY_NON_NULL(endPoint, FATAL, OC_STACK_INVALID_PARAM); OIC_LOG(DEBUG, TAG, "HandleKeepAliveResponse IN"); // Get entry from KeepAlive table. uint32_t index = 0; KeepAliveEntry_t *entry = GetEntryFromEndpoint(endPoint, &index); if (!entry) { // Receive response message about find /oic/ping request. OIC_LOG(ERROR, TAG, "There is no connection info in KeepAlive table"); if (OC_STACK_NO_RESOURCE == responseCode) { OIC_LOG(ERROR, TAG, "Server doesn't have a ping resource"); return OC_STACK_ERROR; } else if (OC_STACK_OK == responseCode) { int64_t *recvInterval = NULL; size_t dimensions[MAX_REP_ARRAY_DEPTH] = { 0 }; OCRepPayloadGetIntArray(respPayload, INTERVAL_ARRAY, &recvInterval, dimensions); size_t serverIntervalSize = calcDimTotal(dimensions); entry = AddKeepAliveEntry(endPoint, OC_CLIENT, recvInterval); if (!entry) { OIC_LOG(ERROR, TAG, "Failed to add new KeepAlive entry"); return OC_STACK_ERROR; } if (serverIntervalSize) { // update interval size with received size of server. entry->intervalSize = serverIntervalSize; } // Send first ping message return SendPingMessage(entry); } } else { // Set sentPingMsg values with false. entry->sentPingMsg = false; } OIC_LOG(DEBUG, TAG, "HandleKeepAliveResponse OUT"); return OC_STACK_OK; }
bool things_get_int_arrayvalue(struct things_representation_s *mother, char *key, int *length, int64_t **array) { bool find_value = false; OCRepPayloadValue *payload_value = things_rep_payload_find_values((OCRepPayload *)(mother->payload), key); if (NULL != payload_value) { size_t dimension_size = calcDimTotal(payload_value->arr.dimensions); size_t dimensions[3] = { dimension_size, 0, 0 }; THINGS_LOG_D(TAG, "Dimension size in the Payload : %d", dimension_size); find_value = OCRepPayloadGetIntArray((OCRepPayload *)(mother->payload), key, array, dimensions); THINGS_LOG_D(TAG, "Find Value : %d", find_value); if (find_value) { *length = dimension_size; } } else { THINGS_LOG_E(TAG, "DATA NOT EXIST~!!!!"); } return find_value; }
static bool add_property_in_post_req_msg(st_things_set_request_message_s *req_msg, OCRepPayload *req_payload, things_attribute_info_s *prop) { RET_FALSE_IF_PARAM_IS_NULL(TAG, req_msg); RET_FALSE_IF_PARAM_IS_NULL(TAG, req_msg->rep); RET_FALSE_IF_PARAM_IS_NULL(TAG, req_msg->rep->payload); RET_FALSE_IF_PARAM_IS_NULL(TAG, req_payload); RET_FALSE_IF_PARAM_IS_NULL(TAG, prop); OCRepPayload *resp_payload = req_msg->rep->payload; THINGS_LOG_D(TAG, "Property Key is %s", prop->key); THINGS_LOG_D(TAG, "Property type is %d", prop->type); // Based on the property type, call appropriate methods to copy // the property from request payload to request representation. bool result = false; switch (prop->type) { case BOOL_ID: { bool value = false; if (OCRepPayloadGetPropBool(req_payload, prop->key, &value)) { result = OCRepPayloadSetPropBool(resp_payload, prop->key, value); if (!result) { THINGS_LOG_E(TAG, "Failed to set the boolean value of '%s' in request message.", prop->key); } } else { THINGS_LOG_E(TAG, "Failed to get the boolean value of '%s' for request message.", prop->key); } } break; case INT_ID: { int64_t value = 0; if (OCRepPayloadGetPropInt(req_payload, prop->key, &value)) { result = OCRepPayloadSetPropInt(resp_payload, prop->key, value); if (!result) { THINGS_LOG_E(TAG, "Failed to set the integer value of '%s' in request message", prop->key); } } else { THINGS_LOG_E(TAG, "Failed to get the integer value of '%s' for request message", prop->key); } } break; case DOUBLE_ID: { double value = 0.0; if (OCRepPayloadGetPropDouble(req_payload, prop->key, &value)) { result = OCRepPayloadSetPropDouble(resp_payload, prop->key, value); if (!result) { THINGS_LOG_E(TAG, "Failed to set the double value of '%s' in request message", prop->key); } } else { THINGS_LOG_E(TAG, "Failed to get the double value of '%s' for request message", prop->key); } } break; case STRING_ID: { char *value = NULL; if (OCRepPayloadGetPropString(req_payload, prop->key, &value)) { result = OCRepPayloadSetPropString(resp_payload, prop->key, value); if (!result) { THINGS_LOG_E(TAG, "Failed to set the string value of '%s' in request message", prop->key); } things_free(value); } else { THINGS_LOG_E(TAG, "Failed to get the string value of '%s' for request message", prop->key); } } break; case OBJECT_ID: { OCRepPayload *value = NULL; if (OCRepPayloadGetPropObject(req_payload, prop->key, &value)) { result = OCRepPayloadSetPropObject(resp_payload, prop->key, value); if (!result) { THINGS_LOG_E(TAG, "Failed to set the object value of '%s' in request message", prop->key); } OCRepPayloadDestroy(value); } else { THINGS_LOG_E(TAG, "Failed to get the object value of '%s' for request message", prop->key); } } break; case BYTE_ID: { OCByteString byte_value; if (OCRepPayloadGetPropByteString(req_payload, prop->key, &byte_value)) { result = OCRepPayloadSetPropByteString(resp_payload, prop->key, byte_value); if (!result) { THINGS_LOG_E(TAG, "Failed to set the byte string value of '%s' in request message", prop->key); } things_free(byte_value.bytes); } else { THINGS_LOG_E(TAG, "Failed to get the byte string value of '%s' for request message", prop->key); } } break; case INT_ARRAY_ID: { int64_t *value = NULL; size_t dimensions[MAX_REP_ARRAY_DEPTH] = { 0 }; if (OCRepPayloadGetIntArray(req_payload, prop->key, &value, dimensions)) { result = OCRepPayloadSetIntArray(resp_payload, prop->key, value, dimensions); if (!result) { THINGS_LOG_E(TAG, "Failed to set the integer array value of '%s' in request message", prop->key); } things_free(value); } else { THINGS_LOG_E(TAG, "Failed to get the integer array value of '%s' for request message", prop->key); } } break; case DOUBLE_ARRAY_ID: { double *value = NULL; size_t dimensions[MAX_REP_ARRAY_DEPTH] = { 0 }; if (OCRepPayloadGetDoubleArray(req_payload, prop->key, &value, dimensions)) { result = OCRepPayloadSetDoubleArray(resp_payload, prop->key, value, dimensions); if (!result) { THINGS_LOG_E(TAG, "Failed to set the double array value of '%s' in request message", prop->key); } things_free(value); } else { THINGS_LOG_E(TAG, "Failed to get the double array value of '%s' for request message", prop->key); } } break; case STRING_ARRAY_ID: { char **value = NULL; size_t dimensions[MAX_REP_ARRAY_DEPTH] = { 0 }; if (OCRepPayloadGetStringArray(req_payload, prop->key, &value, dimensions)) { result = OCRepPayloadSetStringArray(resp_payload, prop->key, value, dimensions); if (!result) { THINGS_LOG_E(TAG, "Failed to set the string array value of '%s' in request message", prop->key); } size_t len = calcDimTotal(dimensions); things_free_str_array(value, len); } else { THINGS_LOG_E(TAG, "Failed to get the string array value of '%s' for request message", prop->key); } } break; case OBJECT_ARRAY_ID: { OCRepPayload **value = NULL; size_t dimensions[MAX_REP_ARRAY_DEPTH] = { 0 }; if (OCRepPayloadGetPropObjectArray(req_payload, prop->key, &value, dimensions)) { result = OCRepPayloadSetPropObjectArray(resp_payload, prop->key, value, dimensions); if (!result) { THINGS_LOG_E(TAG, "Failed to set the object array value of '%s' in request message", prop->key); } size_t len = calcDimTotal(dimensions); for (size_t index = 0; index < len; index++) { OCRepPayloadDestroy(value[index]); } things_free(value); } else { THINGS_LOG_E(TAG, "Failed to get the object array value of '%s' for request message", prop->key); } } break; default: THINGS_LOG_E(TAG, "Invalid property type (%d).", prop->type); break; } return result; }