Commit d0a9a6c5 authored by Mushfiqul Islam Antu's avatar Mushfiqul Islam Antu Committed by Mushfiqul Islam

[IOT-3121] Fix rts values of Collection Resource

For baseline response of collection, value of rt & rts
are same for current implementation, which is wrong.
rts should reflect the resource types of the chlidren
of the collection.

Change-Id: Ib4e768c7401247dc9dd4917ff5a611396e8e07a2
Signed-off-by: default avatarMushfiqul Islam Antu <i.mushfiq@samsung.com>
parent 62dc2adb
...@@ -37,24 +37,21 @@ ...@@ -37,24 +37,21 @@
#include "cainterface.h" #include "cainterface.h"
#define TAG "OIC_RI_COLLECTION" #define TAG "OIC_RI_COLLECTION"
static bool AddRTSBaselinePayload(OCRepPayload **linkArray, int size, OCRepPayload **colPayload) static bool AddRTSBaselinePayload(const OCResource* collResource, OCRepPayload **colPayload)
{ {
size_t arraySize = 0; size_t arraySize = 0;
for (int j = 0; j < size; j++) for (OCChildResource *tempChildResource = collResource->rsrcChildResourcesHead;
tempChildResource; tempChildResource = tempChildResource->next)
{ {
size_t rtDim[MAX_REP_ARRAY_DEPTH] = {0}; OCResource* currentResource = tempChildResource->rsrcResource;
char **rt = NULL; OCResourceType* currentType = currentResource->rsrcType;
OCRepPayloadGetStringArray(linkArray[j], OC_RSRVD_RESOURCE_TYPE, &rt, rtDim); while(currentType)
arraySize += rtDim[0];
for (size_t l = 0; l < rtDim[0]; l++)
{ {
OICFree(rt[l]); arraySize++;
currentType = currentType->next;
} }
OICFree(rt);
} }
for (OCStringLL *rsrcType = (*colPayload)->types; rsrcType; rsrcType = rsrcType->next, arraySize++);
OIC_LOG_V(DEBUG, TAG, "Number of RTS elements : %zd", arraySize); OIC_LOG_V(DEBUG, TAG, "Number of RTS elements : %zd", arraySize);
size_t dim[MAX_REP_ARRAY_DEPTH] = {arraySize, 0, 0}; size_t dim[MAX_REP_ARRAY_DEPTH] = {arraySize, 0, 0};
char **rts = (char **)OICMalloc(sizeof(char *) * arraySize); char **rts = (char **)OICMalloc(sizeof(char *) * arraySize);
...@@ -64,21 +61,16 @@ static bool AddRTSBaselinePayload(OCRepPayload **linkArray, int size, OCRepPaylo ...@@ -64,21 +61,16 @@ static bool AddRTSBaselinePayload(OCRepPayload **linkArray, int size, OCRepPaylo
return OC_STACK_NO_MEMORY; return OC_STACK_NO_MEMORY;
} }
int k = 0; int k = 0;
for (int j = 0; j < size; j++) for (OCChildResource *tempChildResource = collResource->rsrcChildResourcesHead;
tempChildResource; tempChildResource = tempChildResource->next)
{ {
size_t rtDim[MAX_REP_ARRAY_DEPTH] = {0}; OCResource* currentResource = tempChildResource->rsrcResource;
char **rt = NULL; OCResourceType* currentType = currentResource->rsrcType;
OCRepPayloadGetStringArray(linkArray[j], OC_RSRVD_RESOURCE_TYPE, &rt, rtDim); while(currentType)
for (size_t l = 0; l < rtDim[0]; l++)
{ {
rts[k++] = OICStrdup(rt[l]); rts[k++] = OICStrdup(currentType->resourcetypename);
OICFree(rt[l]); currentType = currentType->next;
} }
OICFree(rt);
}
for (OCStringLL *rsrcType = (*colPayload)->types; rsrcType; rsrcType = rsrcType->next, size++)
{
rts[k++] = OICStrdup(rsrcType->value);
} }
bool b = OCRepPayloadSetStringArrayAsOwner(*colPayload, OC_RSRVD_RTS, rts, dim); bool b = OCRepPayloadSetStringArrayAsOwner(*colPayload, OC_RSRVD_RTS, rts, dim);
...@@ -184,7 +176,7 @@ static OCStackResult HandleLinkedListInterface(OCEntityHandlerRequest *ehRequest ...@@ -184,7 +176,7 @@ static OCStackResult HandleLinkedListInterface(OCEntityHandlerRequest *ehRequest
{ {
OCRepPayloadAddInterface(colPayload, itf->name); OCRepPayloadAddInterface(colPayload, itf->name);
} }
AddRTSBaselinePayload(linkArr, size, &colPayload); AddRTSBaselinePayload(collResource, &colPayload);
} }
OCRepPayloadSetPropObjectArrayAsOwner(colPayload, OC_RSRVD_LINKS, linkArr, dim); OCRepPayloadSetPropObjectArrayAsOwner(colPayload, OC_RSRVD_LINKS, linkArr, dim);
ret = OC_STACK_OK; ret = OC_STACK_OK;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment