+
+OCRepPayload *OCCreateKeepAlivePayload(int64_t interval)
+{
+ OIC_LOG_V(DEBUG, TAG, "Create KeepAlive Payload, interval is [%" PRId64 "]", interval);
+
+ OCRepPayload *payload = OCRepPayloadCreate();
+ if (!payload)
+ {
+ OIC_LOG(ERROR, TAG, "Failed to allocate Payload");
+ return NULL;
+ }
+ payload->base.type = PAYLOAD_TYPE_REPRESENTATION;
+ OCRepPayloadSetPropInt(payload, INTERVAL, interval);
+
+ return payload;
+}
+
+OCStackResult OCAddResourceTypeNameToPayload(OCRepPayload *payload)
+{
+ uint8_t numElement = 0;
+ OCStackResult res = OCGetNumberOfResourceTypes(g_keepAliveHandle, &numElement);
+ if (OC_STACK_OK == res)
+ {
+ size_t rtDim[MAX_REP_ARRAY_DEPTH] = {numElement, 0, 0};
+ char **rt = (char **)OICMalloc(sizeof(char *) * numElement);
+ if (!rt)
+ {
+ OIC_LOG(ERROR, TAG, "Could not allocate memory for rf");
+ return OC_STACK_NO_MEMORY;
+ }
+ for (uint8_t i = 0; i < numElement; ++i)
+ {
+ const char *value = OCGetResourceTypeName(g_keepAliveHandle, i);
+ OIC_LOG_V(DEBUG, TAG, "value: %s", value);
+ rt[i] = OICStrdup(value);
+ if (NULL == rt[i])
+ {
+ OIC_LOG_V(ERROR, TAG, "Creating duplicate string for rt failed!");
+ for (uint8_t j = 0; j < i; ++j)
+ {
+ OICFree(rt[j]);
+ }
+ OICFree(rt);
+ return OC_STACK_NO_MEMORY;
+ }
+ }
+ OCRepPayloadSetStringArray(payload, OC_RSRVD_RESOURCE_TYPE, (const char **) rt, rtDim);
+ for (uint8_t i = 0; i < numElement; ++i)
+ {
+ OICFree(rt[i]);
+ }
+ OICFree(rt);
+ }
+
+ return res;
+}
+
+OCStackResult OCAddResourceInterfaceNameToPayload(OCRepPayload *payload)
+{
+ uint8_t numElement = 0;
+ OCStackResult res = OCGetNumberOfResourceInterfaces(g_keepAliveHandle, &numElement);
+ if (OC_STACK_OK == res)
+ {
+ size_t ifDim[MAX_REP_ARRAY_DEPTH] = {numElement, 0, 0};
+ char **itf = (char **)OICMalloc(sizeof(char *) * numElement);
+ if (!itf)
+ {
+ OIC_LOG(ERROR, TAG, "Could not allocate memory for itf");
+ return OC_STACK_NO_MEMORY;
+ }
+
+ for (uint8_t i = 0; i < numElement; ++i)
+ {
+ const char *value = OCGetResourceInterfaceName(g_keepAliveHandle, i);
+ OIC_LOG_V(DEBUG, TAG, "value: %s", value);
+ itf[i] = OICStrdup(value);
+ if (NULL == itf[i])
+ {
+ OIC_LOG_V(ERROR, TAG, "Creating duplicate string for itf failed!");
+ for (uint8_t j = 0; j < i; ++j)
+ {
+ OICFree(itf[j]);
+ }
+ OICFree(itf);
+ return OC_STACK_NO_MEMORY;
+ }
+ }
+ OCRepPayloadSetStringArray(payload, OC_RSRVD_INTERFACE, (const char **) itf, ifDim);
+ for (uint8_t i = 0; i < numElement; ++i)
+ {
+ OICFree(itf[i]);
+ }
+ OICFree(itf);
+ }
+
+ return res;
+}