Removed href from device and platform payload
authorHabib Virji <habib.virji@samsung.com>
Wed, 30 Nov 2016 22:09:30 +0000 (22:09 +0000)
committerUze Choi <uzchoi@samsung.com>
Thu, 1 Dec 2016 08:49:21 +0000 (08:49 +0000)
- Created a separate function to handle Device and Platform payload.
- rt, if and attribute information are the only included in the payload.
- BuildResponseRepresentation updated to avoid information about device and platform payload.
- Updated dmv value from res.1.1.0,sh.1.2.0 to res.1.1.0,sh.1.1.0.

Change-Id: I59059997f170d177663e87eddea9df32275ca882
Signed-off-by: Habib Virji <habib.virji@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/14979
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
resource/csdk/stack/include/internal/ocresourcehandler.h
resource/csdk/stack/include/octypes.h
resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp
resource/csdk/stack/samples/tizen/SimpleClientServer/ocserver.cpp
resource/csdk/stack/src/occollection.c
resource/csdk/stack/src/ocresource.c
resource/examples/devicediscoveryserver.cpp
resource/examples/simpleserver.cpp

index ab7a9c8..5d2ac03 100644 (file)
@@ -186,7 +186,7 @@ void DeleteDeviceInfo();
  * Prepare payload for resource representation.
  */
 OCStackResult BuildResponseRepresentation(const OCResource *resourcePtr,
-                    OCRepPayload** payload, OCDevAddr *devAddr, bool addDeviceId);
+                    OCRepPayload** payload, OCDevAddr *devAddr);
 
 /**
  * A helper function that Maps an @ref OCEntityHandlerResult type to an
index e57cd30..e36a9b9 100755 (executable)
@@ -286,7 +286,7 @@ extern "C" {
 #define OC_SPEC_VERSION                 "core.1.1.0"
 
 /** Device Data Model version.*/
-#define OC_DATA_MODEL_VERSION           "res.1.1.0,sh.1.2.0"
+#define OC_DATA_MODEL_VERSION           "res.1.1.0,sh.1.1.0"
 /**
  *  These provide backward compatibility - their use is deprecated.
  */
index e69db24..e203bb5 100644 (file)
@@ -86,7 +86,7 @@ const char *supportLink = "https://www.iotivity.org";
 const char *version = "myVersion";
 const char *systemTime = "2015-05-15T11.04";
 const char *specVersion = "core.1.1.0";
-const char *dataModelVersions = "res.1.1.0,sh.1.2.0";
+const char *dataModelVersions = "res.1.1.0,sh.1.1.0";
 
 // Entity handler should check for resourceTypeName and ResourceInterface in order to GET
 // the existence of a known resource
index f54e682..4305399 100644 (file)
@@ -78,7 +78,7 @@ const char *supportLink = "https://www.iotivity.org";
 const char *version = "myVersion";
 const char *systemTime = "2015-05-15T11.04";
 const char *specVersion = "core.1.1.0";
-const char *dataModelVersions = "res.1.1.0,sh.1.2.0";
+const char *dataModelVersions = "res.1.1.0,sh.1.1.0";
 
 // Entity handler should check for resourceTypeName and ResourceInterface in order to GET
 // the existence of a known resource
index 814c5bd..9769a93 100755 (executable)
@@ -247,7 +247,7 @@ HandleLinkedListInterface(OCEntityHandlerRequest *ehRequest,
         return OC_STACK_INVALID_PARAM;
     }
 
-    OCStackResult ret = BuildResponseRepresentation(collResource, &payload, &ehRequest->devAddr, false);
+    OCStackResult ret = BuildResponseRepresentation(collResource, &payload, &ehRequest->devAddr);
     if (ret == OC_STACK_OK)
     {
         tempChildResource = collResource->rsrcChildResourcesHead;
@@ -258,7 +258,7 @@ HandleLinkedListInterface(OCEntityHandlerRequest *ehRequest,
             {
                 //TODO : Add resource type filtering once collections
                 // start supporting queries.
-                ret = BuildResponseRepresentation(temp, &payload, &ehRequest->devAddr, false);
+                ret = BuildResponseRepresentation(temp, &payload, &ehRequest->devAddr);
             }
 
             tempChildResource = tempChildResource->next;
index aad78ec..fb1597f 100755 (executable)
@@ -339,8 +339,7 @@ exit:
     return false;
 }
 
-OCStackResult BuildResponseRepresentation(const OCResource *resourcePtr,
-                    OCRepPayload** payload, OCDevAddr *devAddr, bool addDeviceId)
+static OCStackResult BuildDevicePlatformPayload(const OCResource *resourcePtr, OCRepPayload** payload, bool addDeviceId)
 {
     OCRepPayload *tempPayload = OCRepPayloadCreate();
 
@@ -350,12 +349,11 @@ OCStackResult BuildResponseRepresentation(const OCResource *resourcePtr,
         return OC_STACK_INVALID_PARAM;
     }
 
-    if(!tempPayload)
+    if (!tempPayload)
     {
         return OC_STACK_NO_MEMORY;
     }
 
-    OCRepPayloadSetUri(tempPayload, resourcePtr->uri);
     if (addDeviceId)
     {
         const char *deviceId = OCGetServerInstanceIDString();
@@ -366,6 +364,72 @@ OCStackResult BuildResponseRepresentation(const OCResource *resourcePtr,
         }
         OCRepPayloadSetPropString(tempPayload, OC_RSRVD_DEVICE_ID, deviceId);
     }
+
+    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)
+    {
+        if (resAttrib->attrName && resAttrib->attrValue)
+        {
+            if (0 == strcmp(OC_RSRVD_DATA_MODEL_VERSION, resAttrib->attrName))
+            {
+                char *dmv = OCCreateString((OCStringLL *)resAttrib->attrValue);
+                if (dmv)
+                {
+                    OCRepPayloadSetPropString(tempPayload, resAttrib->attrName, dmv);
+                    OICFree(dmv);
+                }
+            }
+            else
+            {
+                OCRepPayloadSetPropString(tempPayload, resAttrib->attrName, (char *)resAttrib->attrValue);
+            }
+        }
+        resAttrib = resAttrib->next;
+    }
+
+    if(!*payload)
+    {
+        *payload = tempPayload;
+    }
+    else
+    {
+        OCRepPayloadAppend(*payload, tempPayload);
+    }
+
+    return OC_STACK_OK;
+}
+
+OCStackResult BuildResponseRepresentation(const OCResource *resourcePtr,
+                    OCRepPayload** payload, OCDevAddr *devAddr)
+{
+    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)
     {
@@ -927,14 +991,13 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource
     {
         OCResource *resourcePtr = FindResourceByUri(OC_RSRVD_DEVICE_URI);
         VERIFY_PARAM_NON_NULL(TAG, resourcePtr, "Device URI not found.");
-        discoveryResult = BuildResponseRepresentation(resourcePtr, (OCRepPayload **)&payload, NULL, true);
-
+        discoveryResult = BuildDevicePlatformPayload(resourcePtr, (OCRepPayload **)&payload, true);
     }
     else if (virtualUriInRequest == OC_PLATFORM_URI)
     {
         OCResource *resourcePtr = FindResourceByUri(OC_RSRVD_PLATFORM_URI);
         VERIFY_PARAM_NON_NULL(TAG, resourcePtr, "Platform URI not found.");
-        discoveryResult = BuildResponseRepresentation(resourcePtr, (OCRepPayload **)&payload, NULL, false);
+        discoveryResult = BuildDevicePlatformPayload(resourcePtr, (OCRepPayload **)&payload, false);
     }
 #ifdef ROUTING_GATEWAY
     else if (OC_GATEWAY_URI == virtualUriInRequest)
index 87fd5bf..1c3404a 100644 (file)
@@ -49,7 +49,7 @@ std::string  systemTime = "2016-01-15T11.01";
 // Set of strings for each of device info fields
 std::string  deviceName = "Bill's Battlestar";
 std::string  specVersion = "core.1.1.0";
-std::string  dataModelVersions = "res.1.1.0,sh.1.2.0";
+std::string  dataModelVersions = "res.1.1.0,sh.1.1.0";
 
 // OCPlatformInfo Contains all the platform info to be stored
 OCPlatformInfo platformInfo;
index 371bbf8..898bca9 100644 (file)
@@ -67,7 +67,7 @@ std::string  systemTime = "2016-01-15T11.01";
 // Set of strings for each of device info fields
 std::string  deviceName = "IoTivity Simple Server";
 std::string  specVersion = "core.1.1.0";
-std::string  dataModelVersions = "res.1.1.0,sh.1.2.0";
+std::string  dataModelVersions = "res.1.1.0,sh.1.1.0";
 
 // OCPlatformInfo Contains all the platform info to be stored
 OCPlatformInfo platformInfo;