Added support for device discovery at oic/d.
authorMandeep Shetty <mandeep.shetty@intel.com>
Wed, 20 May 2015 22:33:17 +0000 (15:33 -0700)
committerErich Keane <erich.keane@intel.com>
Tue, 26 May 2015 21:49:59 +0000 (21:49 +0000)
Spec compliance task for adding support for device discovery.

Using a struct for Device info with the device name field that is
expected from the application. Generate device id of type UUID and
insert string representation of uuid in discovery responses.

Updated sample apps and unit tests to support changes.
Also updated android jni, OCDeviceInfo.java class and a test in
SmokeTest.java.

Change-Id: Ib2d676d2a504fb9ff177487899f74bd121dc1d59
Signed-off-by: Mandeep Shetty <mandeep.shetty@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1057
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Joseph Morrow <joseph.l.morrow@intel.com>
Reviewed-by: Erich Keane <erich.keane@intel.com>
16 files changed:
android/android_api/base/jni/JniOcPlatform.cpp
android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java
android/android_api/base/src/main/java/org/iotivity/base/OcDeviceInfo.java
android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java
resource/csdk/stack/include/internal/ocresourcehandler.h
resource/csdk/stack/include/octypes.h
resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp
resource/csdk/stack/samples/linux/SimpleClientServer/occlient.h
resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp
resource/csdk/stack/src/ocresource.c
resource/csdk/stack/src/ocstack.c
resource/examples/devicediscoveryclient.cpp
resource/examples/devicediscoveryserver.cpp
resource/include/OCPlatform.h
resource/include/OCPlatform_impl.h
resource/unittests/OCPlatformTest.cpp

index 0a50d8e..40b5898 100644 (file)
@@ -798,18 +798,7 @@ jobject jListener, jint jResourceProperty)
 JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerDeviceInfo0\r
 (JNIEnv *env,\r
 jclass clazz,\r
-jstring jDeviceName,\r
-jstring jHostName,\r
-jstring jDeviceUUID,\r
-jstring jContentType,\r
-jstring jVersion,\r
-jstring jManufacturerName,\r
-jstring jManufacturerUrl,\r
-jstring jModelNumber,\r
-jstring jDateOfManufacture,\r
-jstring jPlatformVersion,\r
-jstring jFirmwareVersion,\r
-jstring jSupportUrl)\r
+jstring jDeviceName)\r
 {\r
     LOGI("OcPlatform_registerDeviceInfo");\r
 \r
@@ -818,81 +807,15 @@ jstring jSupportUrl)
     {\r
         deviceName = env->GetStringUTFChars(jDeviceName, NULL);\r
     }\r
-    std::string hostName;\r
-    if (jHostName)\r
-    {\r
-        hostName = env->GetStringUTFChars(jHostName, NULL);\r
-    }\r
-    std::string deviceUUID;\r
-    if (jDeviceUUID)\r
-    {\r
-        deviceUUID = env->GetStringUTFChars(jDeviceUUID, NULL);\r
-    }\r
-    std::string contentType;\r
-    if (jContentType)\r
-    {\r
-        contentType = env->GetStringUTFChars(jContentType, NULL);\r
-    }\r
-    std::string version;\r
-    if (jVersion)\r
-    {\r
-        version = env->GetStringUTFChars(jVersion, NULL);\r
-    }\r
-    std::string manufacturerName;\r
-    if (jManufacturerName)\r
-    {\r
-        manufacturerName = env->GetStringUTFChars(jManufacturerName, NULL);\r
-    }\r
-    std::string manufacturerUrl;\r
-    if (jManufacturerUrl)\r
-    {\r
-        manufacturerUrl = env->GetStringUTFChars(jManufacturerUrl, NULL);\r
-    }\r
-    std::string modelNumber;\r
-    if (jModelNumber)\r
-    {\r
-        modelNumber = env->GetStringUTFChars(jModelNumber, NULL);\r
-    }\r
-    std::string dateOfManufacture;\r
-    if (jDateOfManufacture)\r
-    {\r
-        dateOfManufacture = env->GetStringUTFChars(jDateOfManufacture, NULL);\r
-    }\r
-    std::string platformVersion;\r
-    if (jPlatformVersion)\r
-    {\r
-        platformVersion = env->GetStringUTFChars(jPlatformVersion, NULL);\r
-    }\r
-    std::string firmwareVersion;\r
-    if (jFirmwareVersion)\r
-    {\r
-        firmwareVersion = env->GetStringUTFChars(jFirmwareVersion, NULL);\r
-    }\r
-    std::string supportUrl;\r
-    if (jSupportUrl)\r
-    {\r
-        supportUrl = env->GetStringUTFChars(jSupportUrl, NULL);\r
-    }\r
 \r
     OCDeviceInfo deviceInfo;\r
     try\r
     {\r
-        DuplicateString(&deviceInfo.contentType, contentType);\r
-        DuplicateString(&deviceInfo.dateOfManufacture, dateOfManufacture);\r
         DuplicateString(&deviceInfo.deviceName, deviceName);\r
-        DuplicateString(&deviceInfo.deviceUUID, deviceUUID);\r
-        DuplicateString(&deviceInfo.firmwareVersion, firmwareVersion);\r
-        DuplicateString(&deviceInfo.hostName, hostName);\r
-        DuplicateString(&deviceInfo.manufacturerName, manufacturerName);\r
-        DuplicateString(&deviceInfo.manufacturerUrl, manufacturerUrl);\r
-        DuplicateString(&deviceInfo.modelNumber, modelNumber);\r
-        DuplicateString(&deviceInfo.platformVersion, platformVersion);\r
-        DuplicateString(&deviceInfo.supportUrl, supportUrl);\r
-        DuplicateString(&deviceInfo.version, version);\r
     }\r
     catch (std::exception &e)\r
     {\r
-        ThrowOcException(JNI_EXCEPTION, "Failed to register device info");\r
+        ThrowOcException(JNI_EXCEPTION, "Failed to construct device info");\r
         return;\r
     }\r
 \r
@@ -900,18 +823,7 @@ jstring jSupportUrl)
     {\r
         OCStackResult result = OCPlatform::registerDeviceInfo(deviceInfo);\r
 \r
-        delete deviceInfo.contentType;\r
-        delete deviceInfo.dateOfManufacture;\r
         delete deviceInfo.deviceName;\r
-        delete deviceInfo.deviceUUID;\r
-        delete deviceInfo.firmwareVersion;\r
-        delete deviceInfo.hostName;\r
-        delete deviceInfo.manufacturerName;\r
-        delete deviceInfo.manufacturerUrl;\r
-        delete deviceInfo.modelNumber;\r
-        delete deviceInfo.platformVersion;\r
-        delete deviceInfo.supportUrl;\r
-        delete deviceInfo.version;\r
 \r
         if (OC_STACK_OK != result)\r
         {\r
index 956cbf7..31a1a1d 100644 (file)
@@ -992,12 +992,12 @@ public class SmokeTest extends InstrumentationTestCase {
 //            @Override
 //            public void onDeviceFound(OcRepresentation ocRepresentation) {
 //                try {
-//                    Log.i(TAG, "Device Name: " + ocRepresentation.getValue("dn"));
+//                    Log.i(TAG, "Device Name: " + ocRepresentation.getValue("n"));
 //                } catch (OcException e) {
 //                    Log.e(TAG, e.toString());
 //                    assertTrue(false);
 //                }
-//                boolean hasDeviceNameAtr = ocRepresentation.hasAttribute("dn");
+//                boolean hasDeviceNameAtr = ocRepresentation.hasAttribute("n");
 //                assertTrue(hasDeviceNameAtr);
 //                boolean hasNonExistingAtr = ocRepresentation.hasAttribute("NonExisting");
 //                assertFalse(hasNonExistingAtr);
@@ -1028,7 +1028,7 @@ public class SmokeTest extends InstrumentationTestCase {
 //            //client
 //            OcPlatform.getDeviceInfo(
 //                    "",
-//                    OcPlatform.MULTICAST_PREFIX + "/oc/d",
+//                      OcPlatform.MULTICAST_PREFIX + DEVICE_URI,
 //                    OcConnectivityType.IPV4,
 //                    deviceFoundListener);
 //
index 65e1497..99d8c7c 100644 (file)
@@ -25,153 +25,24 @@ package org.iotivity.base;
 public class OcDeviceInfo {\r
 \r
     private String deviceName;\r
-    private String hostName;\r
-    private String deviceUuid;\r
-    private String contentType;\r
-    private String version;\r
-    private String manufacturerName;\r
-    private String manufacturerUrl;\r
-    private String modelNumber;\r
-    private String dateOfManufacture;\r
-    private String platformVersion;\r
-    private String firmwareVersion;\r
-    private String supportUrl;\r
 \r
     public OcDeviceInfo() {\r
+\r
         deviceName = "";\r
-        hostName = "";\r
-        deviceUuid = "";\r
-        contentType = "";\r
-        version = "";\r
-        manufacturerName = "";\r
-        manufacturerUrl = "";\r
-        modelNumber = "";\r
-        dateOfManufacture = "";\r
-        platformVersion = "";\r
-        firmwareVersion = "";\r
-        supportUrl = "";\r
     }\r
 \r
-    public OcDeviceInfo(\r
-            String deviceName,\r
-            String hostName,\r
-            String deviceUuid,\r
-            String contentType,\r
-            String version,\r
-            String manufacturerName,\r
-            String manufacturerUrl,\r
-            String modelNumber,\r
-            String dateOfManufacture,\r
-            String platformVersion,\r
-            String firmwareVersion,\r
-            String supportUrl) {\r
+    public OcDeviceInfo(String deviceName) {\r
+\r
         this.deviceName = deviceName;\r
-        this.hostName = hostName;\r
-        this.deviceUuid = deviceUuid;\r
-        this.contentType = contentType;\r
-        this.version = version;\r
-        this.manufacturerName = manufacturerName;\r
-        this.manufacturerUrl = manufacturerUrl;\r
-        this.modelNumber = modelNumber;\r
-        this.dateOfManufacture = dateOfManufacture;\r
-        this.platformVersion = platformVersion;\r
-        this.firmwareVersion = firmwareVersion;\r
-        this.supportUrl = supportUrl;\r
     }\r
 \r
     public String getDeviceName() {\r
+\r
         return deviceName;\r
     }\r
 \r
     public void setDeviceName(String deviceName) {\r
-        this.deviceName = deviceName;\r
-    }\r
-\r
-    public String getHostName() {\r
-        return hostName;\r
-    }\r
-\r
-    public void setHostName(String hostName) {\r
-        this.hostName = hostName;\r
-    }\r
-\r
-    public String getDeviceUuid() {\r
-        return deviceUuid;\r
-    }\r
-\r
-    public void setDeviceUuid(String deviceUuid) {\r
-        this.deviceUuid = deviceUuid;\r
-    }\r
-\r
-    public String getContentType() {\r
-        return contentType;\r
-    }\r
-\r
-    public void setContentType(String contentType) {\r
-        this.contentType = contentType;\r
-    }\r
-\r
-    public String getVersion() {\r
-        return version;\r
-    }\r
-\r
-    public void setVersion(String version) {\r
-        this.version = version;\r
-    }\r
-\r
-    public String getManufacturerName() {\r
-        return manufacturerName;\r
-    }\r
-\r
-    public void setManufacturerName(String manufacturerName) {\r
-        this.manufacturerName = manufacturerName;\r
-    }\r
-\r
-    public String getManufacturerUrl() {\r
-        return manufacturerUrl;\r
-    }\r
-\r
-    public void setManufacturerUrl(String manufacturerUrl) {\r
-        this.manufacturerUrl = manufacturerUrl;\r
-    }\r
-\r
-    public String getModelNumber() {\r
-        return modelNumber;\r
-    }\r
-\r
-    public void setModelNumber(String modelNumber) {\r
-        this.modelNumber = modelNumber;\r
-    }\r
-\r
-    public String getDateOfManufacture() {\r
-        return dateOfManufacture;\r
-    }\r
-\r
-    public void setDateOfManufacture(String dateOfManufacture) {\r
-        this.dateOfManufacture = dateOfManufacture;\r
-    }\r
-\r
-    public String getPlatformVersion() {\r
-        return platformVersion;\r
-    }\r
-\r
-    public void setPlatformVersion(String platformVersion) {\r
-        this.platformVersion = platformVersion;\r
-    }\r
-\r
-    public String getFirmwareVersion() {\r
-        return firmwareVersion;\r
-    }\r
-\r
-    public void setFirmwareVersion(String firmwareVersion) {\r
-        this.firmwareVersion = firmwareVersion;\r
-    }\r
 \r
-    public String getSupportUrl() {\r
-        return supportUrl;\r
-    }\r
-\r
-    public void setSupportUrl(String supportUrl) {\r
-        this.supportUrl = supportUrl;\r
+        this.deviceName = deviceName;\r
     }\r
 }\r
index ec9711f..c96ea43 100644 (file)
@@ -68,8 +68,8 @@ public final class OcPlatform {
     public static final String MULTICAST_IP = "224.0.1.187";\r
     public static final int MULTICAST_PORT = 5683;\r
     public static final int DEFAULT_PRESENCE_TTL = 60;\r
+    public static final String DEVICE_URI = "/oic/d";\r
     public static final String PRESENCE_URI = "/oic/ad";\r
-\r
     private static volatile boolean sIsPlatformInitialized = false;\r
 \r
     private OcPlatform() {\r
@@ -406,34 +406,13 @@ public final class OcPlatform {
             OcDeviceInfo ocDeviceInfo) throws OcException {\r
         OcPlatform.initCheck();\r
         OcPlatform.registerDeviceInfo0(\r
-                ocDeviceInfo.getDeviceName(),\r
-                ocDeviceInfo.getHostName(),\r
-                ocDeviceInfo.getDeviceUuid(),\r
-                ocDeviceInfo.getContentType(),\r
-                ocDeviceInfo.getVersion(),\r
-                ocDeviceInfo.getManufacturerName(),\r
-                ocDeviceInfo.getManufacturerUrl(),\r
-                ocDeviceInfo.getModelNumber(),\r
-                ocDeviceInfo.getDateOfManufacture(),\r
-                ocDeviceInfo.getPlatformVersion(),\r
-                ocDeviceInfo.getFirmwareVersion(),\r
-                ocDeviceInfo.getSupportUrl()\r
+                ocDeviceInfo.getDeviceName()\r
         );\r
     }\r
 \r
     private static native void registerDeviceInfo0(\r
-            String deviceName,\r
-            String hostName,\r
-            String deviceUUID,\r
-            String contentType,\r
-            String version,\r
-            String manufacturerName,\r
-            String manufacturerUrl,\r
-            String modelNumber,\r
-            String dateOfManufacture,\r
-            String platformVersion,\r
-            String firmwareVersion,\r
-            String supportUrl) throws OcException;\r
+            String deviceName\r
+            ) throws OcException;\r
 \r
     /**\r
      * This API unregisters a resource with the server NOTE: This API applies to server side only.\r
index c0744c1..9a9a30b 100644 (file)
@@ -116,6 +116,14 @@ OCStackResult ProcessRequest(ResourceHandling resHandling,
 OCStackResult SavePlatformInfo(OCPlatformInfo info);
 
 /**
+ * Internal API used to save all of the device's information for use in platform
+ * discovery requests.
+ * The device name is received from the appliation.
+ * The deviceID, spec version and data model verson are initialized by the stack.
+ */
+OCStackResult SaveDeviceInfo(OCDeviceInfo info);
+
+/**
  * Internal API used to clear the platform information.
  */
 void DeletePlatformInfo();
index 77e9b01..0ab1301 100644 (file)
@@ -37,7 +37,7 @@ extern "C" {
 /// Authority + URI string to prefix well known queries
 #define OC_WELL_KNOWN_QUERY                  "224.0.1.187:5683/oic/res"
 #define OC_MULTICAST_DISCOVERY_URI           "/oic/res"
-#define OC_EXPLICIT_DEVICE_DISCOVERY_URI     "224.0.1.187:5683/oic/res/d?rt=core.led"
+#define OC_EXPLICIT_DEVICE_DISCOVERY_URI     "224.0.1.187:5683/oic/d?rt=core.led"
 /// Multicast address and port string to prefix multicast queries
 #define OC_MULTICAST_PREFIX                  "224.0.1.187:5683"
 /// IP Multicast address to use for multicast requests
@@ -65,8 +65,8 @@ extern "C" {
 #define OC_RSRVD_RESOURCE_TYPE          "rt"
 #define OC_RSRVD_RESOURCE_TYPE_PRESENCE "oic.wk.ad"
 #define OC_RSRVD_INTERFACE              "if"
-#define OC_RSRVD_DEVICE_ID              "di"
-#define OC_RSRVD_DEVICE_NAME            "dn"
+
+
 #define OC_RSRVD_INTERFACE_DEFAULT      "oic.if.baseline"
 #define OC_RSRVD_INTERFACE_LL           "oic.if.ll"
 #define OC_RSRVD_INTERFACE_BATCH        "oic.if.b"
@@ -94,6 +94,17 @@ extern "C" {
 #define OC_RSRVD_SYSTEM_TIME             "st"
 //*******************
 
+  //**** Device ****
+#define OC_RSRVD_DEVICE_ID              "di"
+#define OC_RSRVD_DEVICE_NAME            "n"
+#define OC_RSRVD_SPEC_VERSION           "lcv"
+#define OC_RSRVD_DATA_MODEL_VERSION     "dmv"
+
+#define OC_SPEC_VERSION                "0.9.0"
+#define OC_DATA_MODEL_VERSION          "sec.0.95"
+//*******************
+
+
 //-----------------------------------------------------------------------------
 // Typedefs
 //-----------------------------------------------------------------------------
@@ -113,7 +124,7 @@ typedef struct OCDevAddr
 typedef enum
 {
     OC_WELL_KNOWN_URI= 0,       ///< "/oic/res"
-    OC_DEVICE_URI,              ///< "/oic/res/d"
+    OC_DEVICE_URI,              ///< "/oic/d"
     OC_PLATFORM_URI,            ///< "/oic/p"
     OC_RESOURCE_TYPES_URI,      ///< "/oic/res/d/type"
     #ifdef WITH_PRESENCE
@@ -399,22 +410,14 @@ typedef struct
 } OCPlatformInfo;
 
 /**
- * TODO : Modify these. This is just so sample apps compile.
+ * This structure is expected as input for device properties.
+ * device name is mandatory and expected from the application.
+ * device id of type UUID will be generated by the stack.
  */
 typedef struct
 {
     char *deviceName;
-    char *hostName;
-    char *deviceUUID;
-    char *contentType;
-    char *version;
-    char *manufacturerName;
-    char *manufacturerUrl;
-    char *modelNumber;
-    char *dateOfManufacture;
-    char *platformVersion;
-    char *firmwareVersion;
-    char *supportUrl;
+
 } OCDeviceInfo;
 
 typedef struct
index 9bfaae7..48718ee 100644 (file)
 static int UNICAST_DISCOVERY = 0;
 static int TEST_CASE = 0;
 
-static const char * UNICAST_DISCOVERY_QUERY = "coap://%s:6298/oic/res";
-static const char * UNICAST_DEVICE_DISCOVERY_QUERY = "coap://%s:6298/oic/res/d";
+static const char * UNICAST_DEVICE_DISCOVERY_QUERY = "coap://%s:6298/oic/d";
 static const char * UNICAST_PLATFORM_DISCOVERY_QUERY = "coap://%s:6298/oic/p";
-static const char * MULTICAST_DEVICE_DISCOVERY_QUERY = "/oic/res/d";
+
+static const char * MULTICAST_DEVICE_DISCOVERY_QUERY = "/oic/d";
 static const char * MULTICAST_PLATFORM_DISCOVERY_QUERY = "/oic/p";
+
+static const char * UNICAST_RESOURCE_DISCOVERY_QUERY = "coap://%s:6298/oic/res";
 static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oic/res";
 //The following variable determines the interface protocol (IPv4, IPv6, etc)
 //to be used for sending unicast messages. Default set to IPv4.
@@ -47,7 +49,7 @@ static std::string coapServerIP = "255.255.255.255";
 static std::string coapServerPort = "5683";
 static std::string coapServerResource = "/a/light";
 static const int IPV4_ADDR_SIZE = 16;
-//Use ipv4addr for both InitDiscovery and InitDeviceDiscovery
+//Use ipv4addr for both InitDiscovery and InitPlatformOrDeviceDiscovery
 char ipv4addr[IPV4_ADDR_SIZE];
 void StripNewLineChar(char* str);
 
@@ -109,6 +111,7 @@ static void PrintUsage()
     OC_LOG(INFO, TAG, "-t 18 :  Discover Resources and Initiate Nonconfirmable Get Request and "\
             "add  vendor specific header options");
     OC_LOG(INFO, TAG, "-t 19 :  Discover Platform");
+    OC_LOG(INFO, TAG, "-t 20 :  Discover Devices");
 }
 
 OCStackResult InvokeOCDoResource(std::ostringstream &query,
@@ -412,6 +415,9 @@ OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
             case TEST_GET_REQ_NON_WITH_VENDOR_HEADER_OPTIONS:
                 InitGetRequest(OC_LOW_QOS, 1, 0);
                 break;
+            case TEST_DISCOVER_PLATFORM_REQ:
+                InitPlatformDiscovery(OC_LOW_QOS);
+                break;
             case TEST_DISCOVER_DEV_REQ:
                 InitDeviceDiscovery(OC_LOW_QOS);
                 break;
@@ -449,6 +455,28 @@ OCStackApplicationResult PlatformDiscoveryReqCB (void* ctx, OCDoHandle handle,
     return (UNICAST_DISCOVERY) ? OC_STACK_DELETE_TRANSACTION : OC_STACK_KEEP_TRANSACTION;
 }
 
+OCStackApplicationResult DeviceDiscoveryReqCB (void* ctx, OCDoHandle handle,
+        OCClientResponse * clientResponse)
+{
+    if (ctx == (void*) DEFAULT_CONTEXT_VALUE)
+    {
+        OC_LOG(INFO, TAG, "Callback Context for Device DISCOVER query recvd successfully");
+    }
+
+    if(clientResponse)
+    {
+        //OC_LOG truncates the response as it is too long.
+        fprintf(stderr, "Discovery response: \n %s\n", clientResponse->resJSONPayload);
+        fflush(stderr);
+    }
+    else
+    {
+        OC_LOG_V(INFO, TAG, "PlatformDiscoveryReqCB received Null clientResponse");
+    }
+
+    return (UNICAST_DISCOVERY) ? OC_STACK_DELETE_TRANSACTION : OC_STACK_KEEP_TRANSACTION;
+}
+
 #ifdef WITH_PRESENCE
 int InitPresence()
 {
@@ -654,8 +682,10 @@ int InitGetRequest(OCQualityOfService qos, uint8_t withVendorSpecificHeaderOptio
     }
 }
 
-int InitDeviceDiscovery(OCQualityOfService qos)
+int InitPlatformDiscovery(OCQualityOfService qos)
 {
+    OC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
+
     OCStackResult ret;
     OCCallbackData cbData;
     char szQueryUri[64] = { 0 };
@@ -670,10 +700,50 @@ int InitDeviceDiscovery(OCQualityOfService qos)
     }
     else
     {
-        strncpy(szQueryUri, MULTICAST_PLATFORM_DISCOVERY_QUERY,
-                sizeof(szQueryUri) -1 );
-        szQueryUri[sizeof(szQueryUri) -1] = '\0';
+        strncpy(szQueryUri, MULTICAST_PLATFORM_DISCOVERY_QUERY, sizeof(szQueryUri) -1 );
     }
+    szQueryUri[sizeof(szQueryUri) -1] = '\0';
+
+    if(UNICAST_DISCOVERY)
+    {
+        ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, OC_CONNTYPE,
+                (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, &cbData, NULL, 0);
+    }
+    else
+    {
+        ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, (OC_ALL),
+                (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, &cbData, NULL, 0);
+    }
+
+    if (ret != OC_STACK_OK)
+    {
+        OC_LOG(ERROR, TAG, "OCStack device error");
+    }
+
+    return ret;
+}
+
+int InitDeviceDiscovery(OCQualityOfService qos)
+{
+    OC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
+
+    OCStackResult ret;
+    OCCallbackData cbData;
+    char szQueryUri[64] = { 0 };
+
+    cbData.cb = DeviceDiscoveryReqCB;
+    cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
+    cbData.cd = NULL;
+
+    if(UNICAST_DISCOVERY)
+    {
+        snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_DEVICE_DISCOVERY_QUERY, ipv4addr);
+    }
+    else
+    {
+        strncpy(szQueryUri, MULTICAST_DEVICE_DISCOVERY_QUERY, sizeof(szQueryUri) -1 );
+    }
+    szQueryUri[sizeof(szQueryUri) -1] = '\0';
 
     if(UNICAST_DISCOVERY)
     {
@@ -703,7 +773,7 @@ int InitDiscovery(OCQualityOfService qos)
 
     if (UNICAST_DISCOVERY)
     {
-        snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_DISCOVERY_QUERY, ipv4addr);
+        snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_RESOURCE_DISCOVERY_QUERY, ipv4addr);
     }
     else
     {
@@ -788,6 +858,10 @@ int main(int argc, char* argv[])
     {
         InitDeviceDiscovery(OC_LOW_QOS);
     }
+    else if(UNICAST_DISCOVERY  == 0  && TEST_CASE == TEST_DISCOVER_PLATFORM_REQ)
+    {
+        InitPlatformDiscovery(OC_LOW_QOS);
+    }
     else
     {
         InitDiscovery(OC_LOW_QOS);
index 1570a94..6e955b7 100644 (file)
@@ -61,6 +61,7 @@ typedef enum {
 #endif
     TEST_OBS_REQ_NON_CANCEL_IMM,
     TEST_GET_REQ_NON_WITH_VENDOR_HEADER_OPTIONS,
+    TEST_DISCOVER_PLATFORM_REQ,
     TEST_DISCOVER_DEV_REQ,
     MAX_TESTS
 } CLIENT_TEST;
@@ -97,6 +98,7 @@ int InitPostRequest(OCQualityOfService qos);
 int InitDeleteRequest(OCQualityOfService qos);
 int InitGetRequest(OCQualityOfService qos);
 int InitDeviceDiscovery(OCQualityOfService qos);
+int InitPlatformDiscovery(OCQualityOfService qos);
 int InitDiscovery(OCQualityOfService qos);
 
 /* Function to retrieve ip address, port no. of the server
index 177914b..0aeb885 100644 (file)
@@ -67,12 +67,10 @@ const char responsePayloadDeleteResourceNotSupported[] =
 
 
 char *gResourceUri= (char *)"/a/light";
-const char *contentType = "myContentType";
 const char *dateOfManufacture = "myDateOfManufacture";
 const char *deviceName = "myDeviceName";
 const char *deviceUUID = "myDeviceUUID";
 const char *firmwareVersion = "myFirmwareVersion";
-const char *hostName = "myHostName";
 const char *manufacturerName = "myName";
 const char *operatingSystemVersion = "myOS";
 const char *hardwareVersion = "myHardwareVersion";
@@ -90,6 +88,7 @@ const char *resourceTypeName = "core.light";
 const char *resourceInterface = OC_RSRVD_INTERFACE_DEFAULT;
 
 OCPlatformInfo platformInfo;
+OCDeviceInfo deviceInfo;
 
 //This function takes the request as an input and returns the response
 //in JSON format.
@@ -888,6 +887,11 @@ void DeletePlatformInfo()
     free (platformInfo.systemTime);
 }
 
+void DeleteDeviceInfo()
+{
+    free (deviceInfo.deviceName);
+}
+
 bool DuplicateString(char** targetString, const char* sourceString)
 {
     if(!sourceString)
@@ -989,6 +993,15 @@ OCStackResult SetPlatformInfo(const char* platformID, const char *manufacturerNa
     return OC_STACK_ERROR;
 }
 
+OCStackResult SetDeviceInfo(const char* deviceName)
+{
+    if(!DuplicateString(&deviceInfo.deviceName, deviceName))
+    {
+        return OC_STACK_ERROR;
+    }
+    return OC_STACK_OK;
+}
+
 static void PrintUsage()
 {
     OC_LOG(INFO, TAG, "Usage : ocserver -o <0|1>");
@@ -1038,25 +1051,41 @@ int main(int argc, char* argv[])
 
     OCSetDefaultDeviceEntityHandler(OCDeviceEntityHandlerCb);
 
-    OCStackResult platformRegistrationResult =
+    OCStackResult registrationResult =
         SetPlatformInfo(platformID, manufacturerName, manufacturerUrl, modelNumber,
             dateOfManufacture, platformVersion,  operatingSystemVersion,  hardwareVersion,
             firmwareVersion,  supportUrl, systemTime);
 
-    if (platformRegistrationResult != OC_STACK_OK)
+    if (registrationResult != OC_STACK_OK)
     {
         OC_LOG(INFO, TAG, "Platform info setting failed locally!");
         exit (EXIT_FAILURE);
     }
 
-    platformRegistrationResult = OCSetPlatformInfo(platformInfo);
+    registrationResult = OCSetPlatformInfo(platformInfo);
 
-    if (platformRegistrationResult != OC_STACK_OK)
+    if (registrationResult != OC_STACK_OK)
     {
         OC_LOG(INFO, TAG, "Platform Registration failed!");
         exit (EXIT_FAILURE);
     }
 
+    registrationResult = SetDeviceInfo(deviceName);
+
+    if (registrationResult != OC_STACK_OK)
+    {
+        OC_LOG(INFO, TAG, "Device info setting failed locally!");
+        exit (EXIT_FAILURE);
+    }
+
+    registrationResult = OCSetDeviceInfo(deviceInfo);
+
+    if (registrationResult != OC_STACK_OK)
+    {
+        OC_LOG(INFO, TAG, "Device Registration failed!");
+        exit (EXIT_FAILURE);
+    }
+
     /*
      * Declare and create the example resource: Light
      */
@@ -1084,8 +1113,12 @@ int main(int argc, char* argv[])
 
     // Break from loop with Ctrl-C
     OC_LOG(INFO, TAG, "Entering ocserver main loop...");
+
     DeletePlatformInfo();
+    DeleteDeviceInfo();
+
     signal(SIGINT, handleSigInt);
+
     while (!gQuitFlag)
     {
         if (OCProcess() != OC_STACK_OK)
index db9f34c..7736e3b 100644 (file)
 
 extern OCResource *headResource;
 static OCPlatformInfo savedPlatformInfo = {};
-static cJSON *savedDeviceInfo = NULL;
+static OCDeviceInfo savedDeviceInfo = {};
+
 static const char * VIRTUAL_RSRCS[] =
 {
-       "/oic/p",
-       "/oic/res",
-       "/oic/res/d",
-       "/oic/res/types/d",
-       #ifdef WITH_PRESENCE
-       "/oic/ad"
-       #endif
+    "/oic/res",
+    "/oic/d",
+    "/oic/p",
+    "/oic/res/types/d",
+    #ifdef WITH_PRESENCE
+    "/oic/ad"
+    #endif
 };
 
 //-----------------------------------------------------------------------------
@@ -181,6 +182,42 @@ static char* GetJSONStringFromPlatformInfo(OCPlatformInfo info)
     return jsonEncodedInfo;
 }
 
+static char* GetJSONStringFromDeviceInfo(OCDeviceInfo info)
+{
+    cJSON *rootObj = cJSON_CreateObject();
+
+    if (!rootObj)
+    {
+        return NULL;
+    }
+
+    cJSON *repObj = NULL;
+    char *jsonEncodedInfo = NULL;
+
+    cJSON_AddItemToObject (rootObj, OC_RSRVD_HREF,
+            cJSON_CreateString(GetVirtualResourceUri(OC_DEVICE_URI)));
+
+    cJSON_AddItemToObject (rootObj, OC_RSRVD_REPRESENTATION, repObj = cJSON_CreateObject());
+
+    cJSON_AddItemToObject (repObj, OC_RSRVD_DEVICE_ID,
+                    cJSON_CreateString(OCGetServerInstanceIDString()));
+
+    cJSON_AddItemToObject (repObj, OC_RSRVD_DEVICE_NAME,
+                        cJSON_CreateString(info.deviceName));
+
+    cJSON_AddItemToObject (repObj, OC_RSRVD_SPEC_VERSION,
+                        cJSON_CreateString(OC_SPEC_VERSION));
+
+    cJSON_AddItemToObject (repObj, OC_RSRVD_DATA_MODEL_VERSION,
+                        cJSON_CreateString(OC_DATA_MODEL_VERSION));
+
+    jsonEncodedInfo = cJSON_PrintUnformatted (rootObj);
+
+    cJSON_Delete(rootObj);
+
+    return jsonEncodedInfo;
+}
+
 static OCStackResult ValidateUrlQuery (char *url, char *query,
                                 uint8_t *filterOn, char **filterValue)
 {
@@ -402,81 +439,33 @@ OCStackResult BuildVirtualResourceResponseForDevice(uint8_t filterOn, char *filt
     }
 
     OCStackResult ret = OC_STACK_ERROR;
+    char *jsonStr = NULL;
+    uint16_t jsonLen = 0;
 
-    if (savedDeviceInfo != NULL)
-    {
-        char *jsonStr = NULL;
-        uint16_t jsonLen = 0;
-        cJSON *repObj = cJSON_GetObjectItem(savedDeviceInfo, OC_RSRVD_REPRESENTATION);
+    jsonStr = GetJSONStringFromDeviceInfo(savedDeviceInfo);
 
-        OC_LOG(INFO, TAG, PCF("Entering BuildVirtualResourceResponseForDevice"));
+    if(jsonStr)
+    {
+        jsonLen = strlen(jsonStr);
 
-        if ((filterOn == STACK_DEVICE_DISCOVERY_DI_FILTER) && filterValue)
-        {
-            if((cJSON_GetObjectItem(repObj,OC_RSRVD_DEVICE_ID) != NULL) &&
-                    strcmp(cJSON_GetObjectItem(repObj,OC_RSRVD_DEVICE_ID)->valuestring, filterValue)
-                    == 0)
-            {
-                ret = OC_STACK_OK;
-            }
-        }
-        else if ((filterOn == STACK_DEVICE_DISCOVERY_DN_FILTER) && filterValue)
-        {
-            if((cJSON_GetObjectItem(repObj,OC_RSRVD_DEVICE_NAME) != NULL) &&
-                    strcmp(cJSON_GetObjectItem(repObj,OC_RSRVD_DEVICE_NAME)->valuestring,
-                        filterValue) == 0)
-            {
-                ret = OC_STACK_OK;
-            }
-        }
-        else if (filterOn == STACK_RES_DISCOVERY_NOFILTER)
+        if (jsonLen < *remaining)
         {
+            strncpy(out, jsonStr, (jsonLen + 1));
+            *remaining = *remaining - jsonLen;
             ret = OC_STACK_OK;
         }
         else
         {
-            ret = OC_STACK_INVALID_QUERY;
+            ret = OC_STACK_ERROR;
         }
 
-        if (ret == OC_STACK_OK)
-        {
-            jsonStr = cJSON_PrintUnformatted (savedDeviceInfo);
-
-            if(jsonStr)
-            {
-                jsonLen = strlen(jsonStr);
-
-                if (jsonLen < *remaining)
-                {
-                    strncpy(out, jsonStr, (jsonLen + 1));
-                    *remaining = *remaining - jsonLen;
-                    ret = OC_STACK_OK;
-                }
-                else
-                {
-                    ret = OC_STACK_ERROR;
-                }
-
-                OCFree(jsonStr);
-            }
-            else
-            {
-                ret = OC_STACK_ERROR;
-            }
-        }
-        else
-        {
-            ret = OC_STACK_INVALID_DEVICE_INFO;
-        }
+        OCFree(jsonStr);
     }
     else
     {
-        OC_LOG(ERROR, TAG, PCF("No device info found."));
-        //error so that stack won't respond with empty payload
-        ret = OC_STACK_INVALID_DEVICE_INFO;
+        OC_LOG(ERROR, TAG, PCF("Error encoding save device info."));
+        ret = OC_STACK_ERROR;
     }
-
-    OC_LOG(INFO, TAG, PCF("Exiting BuildVirtualResourceResponseForDevice"));
     return ret;
 }
 
@@ -1064,14 +1053,6 @@ ProcessRequest(ResourceHandling resHandling, OCResource *resource, OCServerReque
     return ret;
 }
 
-void DeleteDeviceInfo()
-{
-    if(savedDeviceInfo)
-    {
-        cJSON_Delete(savedDeviceInfo);
-    }
-}
-
 void DeletePlatformInfo()
 {
     OC_LOG(INFO, TAG, PCF("Deleting platform info."));
@@ -1127,10 +1108,9 @@ static OCStackResult CloneStringIfNonNull(char **dest, char *src)
     }
     return OC_STACK_OK;
 }
+
 static OCStackResult DeepCopyPlatFormInfo(OCPlatformInfo info)
 {
-    DeletePlatformInfo();
-
     OCStackResult ret = OC_STACK_OK;
     ret = CloneStringIfNonNull(&(savedPlatformInfo.platformID), info.platformID);
     VERIFY_SUCCESS(ret, OC_STACK_OK);
@@ -1175,6 +1155,8 @@ static OCStackResult DeepCopyPlatFormInfo(OCPlatformInfo info)
 
 OCStackResult SavePlatformInfo(OCPlatformInfo info)
 {
+    DeletePlatformInfo();
+
     OCStackResult res = DeepCopyPlatFormInfo(info);
 
     if (res != OC_STACK_OK)
@@ -1188,3 +1170,51 @@ OCStackResult SavePlatformInfo(OCPlatformInfo info)
 
     return res;
 }
+
+void DeleteDeviceInfo()
+{
+    OC_LOG(INFO, TAG, PCF("Deleting device info."));
+
+    OCFree(savedDeviceInfo.deviceName);
+    savedDeviceInfo.deviceName = NULL;
+}
+
+static OCStackResult DeepCopyDeviceInfo(OCDeviceInfo info)
+{
+    OCStackResult ret = OC_STACK_OK;
+
+    ret = CloneStringIfNonNull(&(savedDeviceInfo.deviceName), info.deviceName);
+    VERIFY_SUCCESS(ret, OC_STACK_OK);
+
+    return OC_STACK_OK;
+
+    exit:
+        DeleteDeviceInfo();
+        return ret;
+}
+
+OCStackResult SaveDeviceInfo(OCDeviceInfo info)
+{
+    OCStackResult res = OC_STACK_OK;
+
+    DeleteDeviceInfo();
+
+    res = DeepCopyDeviceInfo(info);
+
+    VERIFY_SUCCESS(res, OC_STACK_OK);
+
+    if(OCGetServerInstanceID() == NULL)
+    {
+        OC_LOG(INFO, TAG, PCF("Device ID generation failed"));
+        res =  OC_STACK_ERROR;
+        goto exit;
+    }
+
+    OC_LOG(INFO, TAG, PCF("Device initialized successfully."));
+    return OC_STACK_OK;
+
+    exit:
+        DeleteDeviceInfo();
+        return res;
+
+}
index 8ef78b6..25d3681 100644 (file)
@@ -2469,11 +2469,15 @@ OCStackResult OCSetPlatformInfo(OCPlatformInfo platformInfo)
 
 OCStackResult OCSetDeviceInfo(OCDeviceInfo deviceInfo)
 {
-    // TODO: Implement this.
-    OC_LOG(ERROR, TAG, "Implement OCSetDeviceInfo !!");
+    OC_LOG(INFO, TAG, PCF("Entering OCSetDeviceInfo"));
 
-    // Returning ok to make samples work.
-    return OC_STACK_OK;
+    if (!deviceInfo.deviceName || deviceInfo.deviceName[0] == '\0')
+    {
+        OC_LOG(ERROR, TAG, PCF("Null or empty device name."));
+        return OC_STACK_INVALID_PARAM;
+    }
+
+    return SaveDeviceInfo(deviceInfo);
 }
 
 OCStackResult OCCreateResource(OCResourceHandle *handle,
index 90d22d8..ffc5ab2 100644 (file)
@@ -37,7 +37,7 @@ void receivedPlatformInfo(const OCRepresentation& rep)
 {
     std::cout << "\nPlatform Information received ---->\n";
     std::string value;
-    std::string values[22] =
+    std::string values[] =
     {
         "pi",   "Platform ID                    ",
         "mnmn", "Manufacturer name              ",
@@ -52,7 +52,7 @@ void receivedPlatformInfo(const OCRepresentation& rep)
         "st",   "Manufacturer system time       "
     };
 
-    for (int i = 0; i < 22; i += 2)
+    for (unsigned int i = 0; i < sizeof(values) / sizeof(values[0]) ; i += 2)
     {
         if(rep.getValue(values[i], value))
         {
@@ -63,7 +63,23 @@ void receivedPlatformInfo(const OCRepresentation& rep)
 
 void receivedDeviceInfo(const OCRepresentation& rep)
 {
-    std::cout << "Implement me !" << std::endl;
+    std::cout << "\nDevice Information received ---->\n";
+    std::string value;
+    std::string values[] =
+    {
+        "di",   "Device ID        ",
+        "n",    "Device name      ",
+        "lcv",  "Spec version url ",
+        "dmv",  "Data Model Model ",
+    };
+
+    for (unsigned int i = 0; i < sizeof(values) / sizeof(values[0]) ; i += 2)
+    {
+        if(rep.getValue(values[i], value))
+        {
+            std::cout << values[i + 1] << " : "<< value << std::endl;
+        }
+    }
 }
 
 int main(int argc, char* argv[]) {
@@ -150,23 +166,20 @@ int main(int argc, char* argv[]) {
             std::cout << "failed." << std::endl;
         }
 
-        bool is_oic_d_implemented = false;
-        if (is_oic_d_implemented)
-        {
-            std::cout<< "Querying for device information... ";
+        std::cout<< "Querying for device information... ";
 
-            ret = OCPlatform::getDeviceInfo("", deviceDiscoveryRequest.str(), connectivityType,
-                    &receivedDeviceInfo);
+        ret = OCPlatform::getDeviceInfo("", deviceDiscoveryRequest.str(), connectivityType,
+                &receivedDeviceInfo);
 
-            if (ret == OC_STACK_OK)
-            {
-                std::cout << "done." << std::endl;
-            }
-            else
-            {
-                std::cout << "failed." << std::endl;
-            }
+        if (ret == OC_STACK_OK)
+        {
+            std::cout << "done." << std::endl;
+        }
+        else
+        {
+            std::cout << "failed." << std::endl;
         }
+
         // A condition variable will free the mutex it is given, then do a non-
         // intensive block until 'notify' is called on it.  In this case, since we
         // don't ever call cv.notify, this should be a non-processor intensive version
index 3c09140..8f9ec9b 100644 (file)
@@ -19,8 +19,8 @@
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
 ///
-///This sample demonstrates the device discovery feature
-///The server sets the device related info. which can
+///This sample demonstrates platform and device discovery feature
+///The server sets the platform and device related info. which can
 ///be later retrieved by a client.
 ///
 
@@ -45,9 +45,15 @@ std::string platformVersion = "platformVersion";
 std::string supportUrl = "www.mysupporturl.com";
 std::string systemTime = "mySystemTime";
 
+//Set of strings for each of platform info fields
+std::string deviceName = "Bill's Battlestar";
+
 //OCPlatformInfo Contains all the platform info to be stored
 OCPlatformInfo platformInfo;
 
+//OCDeviceInfo Contains all the device info to be stored
+OCDeviceInfo deviceInfo;
+
 void DeletePlatformInfo()
 {
     delete[] platformInfo.platformID;
@@ -63,6 +69,12 @@ void DeletePlatformInfo()
     delete[] platformInfo.systemTime;
 }
 
+
+void DeleteDeviceInfo()
+{
+    delete[] deviceInfo.deviceName;
+}
+
 void DuplicateString(char ** targetString, std::string sourceString)
 {
     *targetString = new char[sourceString.length() + 1];
@@ -89,10 +101,15 @@ OCStackResult SetPlatformInfo(std::string platformID, std::string manufacturerNa
 }
 
 
+OCStackResult SetDeviceInfo(std::string deviceName)
+{
+    DuplicateString(&deviceInfo.deviceName, deviceName);
+    return OC_STACK_OK;
+}
+
 
 int main()
 {
-
     // Create PlatformConfig object
     PlatformConfig cfg {
         OC::ServiceType::InProc,
@@ -110,21 +127,27 @@ int main()
             modelNumber, dateOfManufacture, platformVersion,  operatingSystemVersion,
             hardwareVersion, firmwareVersion,  supportUrl, systemTime);
 
+    result = OCPlatform::registerPlatformInfo(platformInfo);
+
     if(result != OC_STACK_OK)
     {
         std::cout << "Platform Registration failed\n";
         return -1;
     }
 
-    result = OCPlatform::registerPlatformInfo(platformInfo);
+
+    result = SetDeviceInfo(deviceName);
+
+    result = OCPlatform::registerDeviceInfo(deviceInfo);
 
     if(result != OC_STACK_OK)
     {
-        std::cout << "Platform Registration failed\n";
+        std::cout << "Device Registration failed\n";
         return -1;
     }
 
     DeletePlatformInfo();
+    DeleteDeviceInfo();
 
     // A condition variable will free the mutex it is given, then do a non-
     // intensive block until 'notify' is called on it.  In this case, since we
index c56f51e..34b092d 100644 (file)
@@ -130,7 +130,7 @@ namespace OC
         *
         * @param host - Host IP Address. If null or empty, Multicast is performed.
         * @param deviceURI - Uri containing address to the virtual device in C Stack
-                                ("/oic/res/d")
+                                ("/oic/d")
         * @param connectivityType - @ref OCConnectivityType type of connectivity indicating the
         *                           interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
         * @param deviceInfoHandler - device discovery callback
index bc85e30..7b23a56 100644 (file)
@@ -98,7 +98,7 @@ namespace OC
          *
          * @param host - Host IP Address. If null or empty, Multicast is performed.
          * @param resourceURI - Uri containing address to the virtual device in C Stack
-         *                       ("/oic/res/d")
+         *                       ("/oic/d")
          *
          * @param QualityOfService the quality of communication
          *
index 83f5868..89034d3 100644 (file)
@@ -54,18 +54,8 @@ namespace OCPlatformTest
     //Helper methods
     void DeleteDeviceInfo(OCDeviceInfo deviceInfo)
     {
-        delete[] deviceInfo.contentType;
-        delete[] deviceInfo.dateOfManufacture;
         delete[] deviceInfo.deviceName;
-        delete[] deviceInfo.deviceUUID;
-        delete[] deviceInfo.firmwareVersion;
-        delete[] deviceInfo.hostName;
-        delete[] deviceInfo.manufacturerName;
-        delete[] deviceInfo.manufacturerUrl;
-        delete[] deviceInfo.modelNumber;
-        delete[] deviceInfo.platformVersion;
-        delete[] deviceInfo.supportUrl;
-        delete[] deviceInfo.version;
+
     }
 
     void DuplicateString(char ** targetString, std::string sourceString)
@@ -632,18 +622,7 @@ namespace OCPlatformTest
     {
         OCDeviceInfo deviceInfo;
 
-        DuplicateString(&deviceInfo.contentType, "myContentType");
-        DuplicateString(&deviceInfo.dateOfManufacture, "myDateOfManufacture");
         DuplicateString(&deviceInfo.deviceName, "myDeviceName");
-        DuplicateString(&deviceInfo.deviceUUID, "myDeviceUUID");
-        DuplicateString(&deviceInfo.firmwareVersion, "myFirmwareVersion");
-        DuplicateString(&deviceInfo.hostName, "myHostName");
-        DuplicateString(&deviceInfo.manufacturerName, "myManufacturerNa");
-        DuplicateString(&deviceInfo.manufacturerUrl, "myManufacturerUrl");
-        DuplicateString(&deviceInfo.modelNumber, "myModelNumber");
-        DuplicateString(&deviceInfo.platformVersion, "myPlatformVersion");
-        DuplicateString(&deviceInfo.supportUrl, "mySupportUrl");
-        DuplicateString(&deviceInfo.version, "myVersion");
 
         EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo));
         EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo));
@@ -652,7 +631,7 @@ namespace OCPlatformTest
     TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject)
     {
         OCDeviceInfo di = {};
-        EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(di));
+        EXPECT_ANY_THROW(OCPlatform::registerDeviceInfo(di));
     }
 
     //SubscribePresence Test