void /*OCRepPayload */ *get_rep_payload(struct things_resource_s *res) { if (res->rep != NULL) { // Create Payload for the mother resource // It applies not only single resource but also the collection resource.. things_resource_s *p_temp; OCRepPayload *rep_payload; if (NULL != res->things_get_children(res) && (NULL != strstr(res->uri, URI_DEVICE_COL)) && (strstr(res->query, OIC_INTERFACE_BATCH) != NULL)) { p_temp = res->next; rep_payload = p_temp->things_create_payload(p_temp, p_temp->query); p_temp = p_temp->next; } else { rep_payload = res->things_create_payload(res, res->query); // Create payload for the children resource(s) p_temp = res->things_get_children(res); } while (NULL != p_temp) { if (NULL != p_temp->rep) { OCRepPayloadAppend(rep_payload, p_temp->things_create_payload(p_temp, p_temp->query)); } p_temp = p_temp->next; } return rep_payload; } else { THINGS_LOG_E(TAG, "ROOT(Parent) Paylaod is NULL."); return NULL; } }
OCStackResult BuildResponseRepresentation(const OCResource *resourcePtr, OCRepPayload** payload) { OCRepPayload *tempPayload = OCRepPayloadCreate(); if (!resourcePtr) { OCRepPayloadDestroy(tempPayload); return OC_STACK_INVALID_PARAM; } if(!tempPayload) { return OC_STACK_NO_MEMORY; } OCRepPayloadSetUri(tempPayload, resourcePtr->uri); OCResourceType *resType = resourcePtr->rsrcType; while(resType) { OCRepPayloadAddResourceType(tempPayload, resType->resourcetypename); resType = resType->next; } OCResourceInterface *resInterface = resourcePtr->rsrcInterface; while(resInterface) { OCRepPayloadAddInterface(tempPayload, resInterface->name); resInterface = resInterface->next; } OCAttribute *resAttrib = resourcePtr->rsrcAttributes; while(resAttrib) { OCRepPayloadSetPropString(tempPayload, resAttrib->attrName, resAttrib->attrValue); resAttrib = resAttrib->next; } if(!*payload) { *payload = tempPayload; } else { OCRepPayloadAppend(*payload, tempPayload); } return OC_STACK_OK; }