Add API support to get and set device spec version and data model version.
authorZiran Sun <ziran.sun@samsung.com>
Wed, 25 May 2016 10:12:32 +0000 (11:12 +0100)
committerUze Choi <uzchoi@samsung.com>
Wed, 1 Jun 2016 10:06:27 +0000 (10:06 +0000)
JIRA: https://jira.iotivity.org/browse/IOT-1100

Change-Id: I0afb56cd1f1f104113e58371b6e6b00c20c1ad7b
Signed-off-by: Ziran Sun <ziran.sun@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8325
Reviewed-by: Phil Coval <philippe.coval@osg.samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
plugins/samples/linux/IotivityandZigbeeServer.c
resource/csdk/stack/include/octypes.h
resource/csdk/stack/include/payload_logging.h
resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp
resource/csdk/stack/samples/tizen/SimpleClientServer/ocserver.cpp
resource/csdk/stack/src/ocresource.c
resource/examples/devicediscoveryserver.cpp
resource/unittests/OCPlatformTest.cpp

index dc011aa..84db1fa 100644 (file)
@@ -139,6 +139,8 @@ OCStackResult SetDeviceInfo()
     static OCDeviceInfo deviceInfo =
         {
             .deviceName = "IoTivity/Zigbee Server Sample",
+            .specVersion = "IoTivity/Zigbee Device Spec Version",
+            .dataModleVersion = "IoTivity/Zigbee Data Model Version",
         };
     char *dup = OICStrdup("oic.wk.d");
     deviceInfo.types = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
index 2dd6224..7b706c2 100644 (file)
@@ -947,6 +947,10 @@ typedef struct
     char *deviceName;
     /** Pointer to the types.*/
     OCStringLL *types;
+    /** Pointer to the device specification version.*/
+    char *specVersion;
+    /** Pointer to the device data model version.*/
+    char *dataModleVersion;
 } OCDeviceInfo;
 
 #ifdef RA_ADAPTER
index b695d89..2a9f091 100644 (file)
@@ -232,7 +232,7 @@ static inline void OCPayloadLogDevice(LogLevel level, OCDevicePayload* payload)
     OIC_LOG(level, PL_TAG, "Payload Type: Device");
     OIC_LOG_V(level, PL_TAG, "\tSID:%s", payload->sid);
     OIC_LOG_V(level, PL_TAG, "\tDevice Name:%s", payload->deviceName);
-    OIC_LOG_V(level, PL_TAG, "\tSpec Version%s", payload->specVersion);
+    OIC_LOG_V(level, PL_TAG, "\tSpec Version:%s", payload->specVersion);
     OIC_LOG_V(level, PL_TAG, "\tData Model Version:%s", payload->dataModelVersion);
     if (payload->types)
     {
index cc5e968..22f6810 100644 (file)
@@ -74,6 +74,8 @@ const char *platformVersion = "myPlatformVersion";
 const char *supportUrl = "mySupportUrl";
 const char *version = "myVersion";
 const char *systemTime = "2015-05-15T11.04";
+const char *specVersion = "myDeviceSpecVersion";
+const char* dataModleVersion = "myDeviceModleVersion";
 
 // Entity handler should check for resourceTypeName and ResourceInterface in order to GET
 // the existence of a known resource
@@ -814,6 +816,8 @@ void DeletePlatformInfo()
 void DeleteDeviceInfo()
 {
     free (deviceInfo.deviceName);
+    free (deviceInfo.specVersion);
+    free (deviceInfo.dataModleVersion);
 }
 
 bool DuplicateString(char** targetString, const char* sourceString)
@@ -917,12 +921,20 @@ OCStackResult SetPlatformInfo(const char* platformID, const char *manufacturerNa
     return OC_STACK_ERROR;
 }
 
-OCStackResult SetDeviceInfo(const char* deviceName)
+OCStackResult SetDeviceInfo(const char* deviceName, const char* specVersion, const char* dataModleVersion)
 {
     if(!DuplicateString(&deviceInfo.deviceName, deviceName))
     {
         return OC_STACK_ERROR;
     }
+    if(!DuplicateString(&deviceInfo.specVersion, specVersion))
+    {
+        return OC_STACK_ERROR;
+    }
+    if(!DuplicateString(&deviceInfo.dataModleVersion, dataModleVersion))
+    {
+        return OC_STACK_ERROR;
+    }
     return OC_STACK_OK;
 }
 
@@ -1043,7 +1055,7 @@ int main(int argc, char* argv[])
         exit (EXIT_FAILURE);
     }
 
-    registrationResult = SetDeviceInfo(deviceName);
+    registrationResult = SetDeviceInfo(deviceName, specVersion, dataModleVersion);
 
     if (registrationResult != OC_STACK_OK)
     {
index 31f26fe..4195a6b 100644 (file)
@@ -76,6 +76,8 @@ const char *platformVersion = "myPlatformVersion";
 const char *supportUrl = "mySupportUrl";
 const char *version = "myVersion";
 const char *systemTime = "2015-05-15T11.04";
+const char *specVersion = "myDeviceSpecVersion";
+const char* dataModleVersion = "myDeviceModleVersion";
 
 // Entity handler should check for resourceTypeName and ResourceInterface in order to GET
 // the existence of a known resource
@@ -807,6 +809,8 @@ void DeletePlatformInfo()
 void DeleteDeviceInfo()
 {
     free (deviceInfo.deviceName);
+    free (deviceInfo.specVersion);
+    free (deviceInfo.dataModleVersion);
 }
 
 bool DuplicateString(char** targetString, const char* sourceString)
@@ -910,12 +914,20 @@ OCStackResult SetPlatformInfo(const char* platformID, const char *manufacturerNa
     return OC_STACK_ERROR;
 }
 
-OCStackResult SetDeviceInfo(const char* deviceName)
+OCStackResult SetDeviceInfo(const char* deviceName, const char* specVersion, const char* dataModleVersion)
 {
     if(!DuplicateString(&deviceInfo.deviceName, deviceName))
     {
         return OC_STACK_ERROR;
     }
+    if(!DuplicateString(&deviceInfo.specVersion, specVersion))
+    {
+        return OC_STACK_ERROR;
+    }
+    if(!DuplicateString(&deviceInfo.dataModleVersion, dataModleVersion))
+    {
+        return OC_STACK_ERROR;
+    }
     return OC_STACK_OK;
 }
 
@@ -1017,7 +1029,7 @@ int main(int argc, char* argv[])
         exit (EXIT_FAILURE);
     }
 
-    registrationResult = SetDeviceInfo(deviceName);
+    registrationResult = SetDeviceInfo(deviceName, specVersion, dataModleVersion);
 
     if (registrationResult != OC_STACK_OK)
     {
index 29dff7f..b503ab7 100755 (executable)
@@ -869,7 +869,7 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource
         else
         {
             payload = (OCPayload*) OCDevicePayloadCreate(deviceId, savedDeviceInfo.deviceName,
-                savedDeviceInfo.types, OC_SPEC_VERSION, OC_DATA_MODEL_VERSION);
+                savedDeviceInfo.types, savedDeviceInfo.specVersion, savedDeviceInfo.dataModleVersion);
             if (!payload)
             {
                 discoveryResult = OC_STACK_NO_MEMORY;
@@ -1340,8 +1340,11 @@ void DeleteDeviceInfo()
 
     OICFree(savedDeviceInfo.deviceName);
     OCFreeOCStringLL(savedDeviceInfo.types);
+    OICFree(savedDeviceInfo.specVersion);
+    OICFree(savedDeviceInfo.dataModleVersion);
     savedDeviceInfo.deviceName = NULL;
-
+    savedDeviceInfo.specVersion = NULL;
+    savedDeviceInfo.dataModleVersion = NULL;
 }
 
 static OCStackResult DeepCopyDeviceInfo(OCDeviceInfo info)
@@ -1363,6 +1366,45 @@ static OCStackResult DeepCopyDeviceInfo(OCDeviceInfo info)
             return OC_STACK_NO_MEMORY;
         }
     }
+
+    if (info.specVersion)
+    {
+        savedDeviceInfo.specVersion = OICStrdup(info.specVersion);
+        if(!savedDeviceInfo.specVersion && info.specVersion)
+        {
+            DeleteDeviceInfo();
+            return OC_STACK_NO_MEMORY;
+        }
+    }
+    else
+    {
+        savedDeviceInfo.specVersion = OICStrdup(OC_SPEC_VERSION);
+        if(!savedDeviceInfo.specVersion && OC_SPEC_VERSION)
+        {
+            DeleteDeviceInfo();
+            return OC_STACK_NO_MEMORY;
+        }
+    }
+
+    if (info.dataModleVersion)
+    {
+        savedDeviceInfo.dataModleVersion = OICStrdup(info.dataModleVersion);
+        if(!savedDeviceInfo.dataModleVersion && info.dataModleVersion)
+        {
+            DeleteDeviceInfo();
+            return OC_STACK_NO_MEMORY;
+        }
+    }
+    else
+    {
+        savedDeviceInfo.dataModleVersion = OICStrdup(OC_DATA_MODEL_VERSION);
+        if(!savedDeviceInfo.dataModleVersion && OC_DATA_MODEL_VERSION)
+        {
+            DeleteDeviceInfo();
+            return OC_STACK_NO_MEMORY;
+        }
+    }
+
     return OC_STACK_OK;
 }
 
index 2112ae6..b81a15b 100644 (file)
@@ -33,7 +33,7 @@
 
 using namespace OC;
 
-//Set of strings for each of deviceInfo fields
+//Set of strings for each of platform Info fields
 std::string dateOfManufacture = "myDateOfManufacture";
 std::string firmwareVersion = "my.Firmware.Version";
 std::string manufacturerName = "myName";
@@ -46,8 +46,10 @@ std::string platformVersion = "platformVersion";
 std::string supportUrl = "www.mysupporturl.com";
 std::string systemTime = "mySystemTime";
 
-//Set of strings for each of platform info fields
+//Set of strings for each of device info fields
 std::string deviceName = "Bill's Battlestar";
+std::string specVersion = "myDeviceSpecVersion";
+std::string dataModleVersion = "myDeviceModleVersion";
 
 //OCPlatformInfo Contains all the platform info to be stored
 OCPlatformInfo platformInfo;
@@ -74,6 +76,8 @@ void DeletePlatformInfo()
 void DeleteDeviceInfo()
 {
     delete[] deviceInfo.deviceName;
+    delete[] deviceInfo.specVersion;
+    delete[] deviceInfo.dataModleVersion;
 }
 
 void DuplicateString(char ** targetString, std::string sourceString)
@@ -102,9 +106,16 @@ OCStackResult SetPlatformInfo(std::string platformID, std::string manufacturerNa
 }
 
 
-OCStackResult SetDeviceInfo(std::string deviceName)
+OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModleVersion)
 {
     DuplicateString(&deviceInfo.deviceName, deviceName);
+
+    if (!specVersion.empty())
+        DuplicateString(&deviceInfo.specVersion, specVersion);
+
+    if (!dataModleVersion.empty())
+        DuplicateString(&deviceInfo.dataModleVersion, dataModleVersion);
+
     return OC_STACK_OK;
 }
 
@@ -137,7 +148,7 @@ int main()
     }
 
 
-    result = SetDeviceInfo(deviceName);
+    result = SetDeviceInfo(deviceName, specVersion, dataModleVersion);
     OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
     OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv");
 
index f2db5df..fc59f96 100644 (file)
@@ -79,7 +79,8 @@ namespace OCPlatformTest
     {
         delete[] deviceInfo.deviceName;
         DeleteStringLL(deviceInfo.types);
-
+        delete[] deviceInfo.specVersion;
+        delete[] deviceInfo.dataModleVersion;
     }
 
     void DuplicateString(char ** targetString, std::string sourceString)
@@ -740,13 +741,15 @@ namespace OCPlatformTest
         deviceInfo.types = NULL;
         OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
         OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv");
+        DuplicateString(&deviceInfo.specVersion, "mySpecVersion");
+        DuplicateString(&deviceInfo.dataModleVersion, "myDataModleVersion");
         EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo));
         EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo));
     }
 
     TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject)
     {
-        OCDeviceInfo di = {0, 0};
+        OCDeviceInfo di = {0, 0, 0, 0};
         EXPECT_ANY_THROW(OCPlatform::registerDeviceInfo(di));
     }