Deprecate OCSetDeviceInfo and registerDeviceInfo
authorDan Mihai <Daniel.Mihai@microsoft.com>
Tue, 10 Jan 2017 04:16:39 +0000 (20:16 -0800)
committerMike Fenelon <mike.fenelon@microsoft.com>
Thu, 12 Jan 2017 00:36:33 +0000 (00:36 +0000)
Mark OCSetDeviceInfo and registerDeviceInfo as deprecated and replace
sample apps' calls to these APIs.

Change-Id: I7c318010d893df94bfe2b4599281b02f44dfcf16
Signed-off-by: Dan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16207
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Mike Fenelon <mike.fenelon@microsoft.com>
19 files changed:
cloud/samples/client/airconditioner/aircon_controlee.cpp
cloud/samples/client/thin_light/thin_room_light.cpp
plugins/samples/linux/IotivityandZigbeeServer.c
resource/csdk/stack/include/ocstack.h
resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp
resource/csdk/stack/samples/tizen/SimpleClientServer/ocserver.cpp
resource/examples/devicediscoveryserver.cpp
resource/examples/fridgeserver.cpp
resource/examples/garageserver.cpp
resource/examples/lightserver.cpp
resource/examples/mediaserver.cpp
resource/examples/presenceserver.cpp
resource/examples/roomserver.cpp
resource/examples/simpleserver.cpp
resource/examples/simpleserverHQ.cpp
resource/include/IServerWrapper.h
resource/include/InProcServerWrapper.h
resource/include/OCPlatform.h
resource/include/OCPlatform_impl.h

index fc9a1e9..201f89e 100644 (file)
@@ -500,6 +500,37 @@ static FILE *client_open(const char * /*path*/, const char *mode)
     return fopen("./aircon_controlee.dat", mode);
 }
 
+OCStackResult SetDeviceInfo()
+{
+    OCStackResult result = OC_STACK_ERROR;
+
+    OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
+
+    if (handle == NULL)
+    {
+        cout << "Failed to find resource " << OC_RSRVD_DEVICE_URI << endl;
+        return result;
+    }
+
+    result = OCBindResourceTypeToResource(handle, "oic.d.airconditioner");
+
+    if (result != OC_STACK_OK)
+    {
+        cout << "Failed to add device type" << endl;
+        return result;
+    }
+
+    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, "FAC_2016");
+
+    if (result != OC_STACK_OK)
+    {
+        cout << "Failed to set device name" << endl;
+        return result;
+    }
+
+    return OC_STACK_OK;
+}
+
 int main(int argc, char *argv[])
 {
     if (argc != 4 && argc != 5)
@@ -606,6 +637,11 @@ int main(int argc, char *argv[])
                                                   , &binarySwitch, placeholders::_1),
                                           OC_OBSERVABLE);
 
+    if (result != OC_STACK_OK)
+    {
+        exit(EXIT_FAILURE);
+    }
+
     uri = temperature.getResourceUri();
     rt = temperature.getResourceType()[0];
     itf = temperature.getInterfaces()[0];
@@ -618,26 +654,35 @@ int main(int argc, char *argv[])
                                                   , &temperature, placeholders::_1),
                                           OC_OBSERVABLE);
 
+    if (result != OC_STACK_OK)
+    {
+        exit(EXIT_FAILURE);
+    }
+
     result = airConditioner.addChildResource(&binarySwitch);
 
-    result = airConditioner.addChildResource(&temperature);
+    if (result != OC_STACK_OK)
+    {
+        exit(EXIT_FAILURE);
+    }
 
-    cout << "Publishing resources to cloud ";
+    result = airConditioner.addChildResource(&temperature);
 
+    if (result != OC_STACK_OK)
+    {
+        exit(EXIT_FAILURE);
+    }
 
-    ResourceHandles resourceHandles;
+    cout << "Publishing resources to cloud ";
 
-    OCDeviceInfo        devInfoAirConditioner;
-    OCStringLL          deviceType;
+    result = SetDeviceInfo();
 
-    deviceType.value = "oic.d.airconditioner";
-    deviceType.next = NULL;
-    devInfoAirConditioner.deviceName = "FAC_2016";
-    devInfoAirConditioner.types = &deviceType;
-    devInfoAirConditioner.specVersion = NULL;
-    devInfoAirConditioner.dataModelVersions = NULL;
+    if (result != OC_STACK_OK)
+    {
+        exit(EXIT_FAILURE);
+    }
 
-    OCPlatform::registerDeviceInfo(devInfoAirConditioner);
+    ResourceHandles resourceHandles;
 
     result = RDClient::Instance().publishResourceToRD(host, OCConnectivityType::CT_ADAPTER_TCP,
              resourceHandles,
index 17cec71..9927362 100644 (file)
 #include "ocstack.h"
 #include "ocpayload.h"
 #include "rd_client.h"
+#include "OCPlatform.h"
 
 using namespace std;
 
+#define VERIFY_SUCCESS(op)                          \
+{                                                   \
+    if (op != OC_STACK_OK)                          \
+    {                                               \
+        cout << #op << " failed!!" << endl;         \
+        goto exit;                                  \
+    }                                               \
+}
+
 #define DEFAULT_CONTEXT_VALUE 0x99
 #define DEFAULT_AUTH_SIGNUP "/oic/account"
 #define DEFAULT_AUTH_SESSION "/oic/account/session"
@@ -447,6 +457,32 @@ OCStackApplicationResult handlePublishCB(void *ctx, OCDoHandle /*handle*/,
     return OC_STACK_KEEP_TRANSACTION;
 }
 
+OCStackResult SetDeviceInfo()
+{
+    OCResourceHandle resourceHandle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
+    if (resourceHandle == NULL)
+    {
+        cout << "Device Resource does not exist." << endl;
+        goto exit;
+    }
+
+    VERIFY_SUCCESS(OCBindResourceTypeToResource(resourceHandle, "oic.d.light"));
+
+    if (OCGetServerInstanceIDString() == NULL)
+    {
+        cout << "Device ID generation failed"  << endl;
+        goto exit;
+    }
+
+    VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, "Living Room Light"));
+
+    cout << "Device information published successfully." << endl;
+    return OC_STACK_OK;
+
+exit:
+    return OC_STACK_ERROR;
+}
+
 void PublishResources(string host)
 {
     cout << "Publishing resources..." << endl;
@@ -463,23 +499,13 @@ void PublishResources(string host)
     cbData.context = (void *) DEFAULT_CONTEXT_VALUE;
     cbData.cd = NULL;
 
-    cout << "Publish default resources" << endl;
-
-    OCDeviceInfo devInfoRoomLight;
-    OCStringLL deviceType;
-
-    deviceType.value = "oic.d.light";
-    deviceType.next = NULL;
-    devInfoRoomLight.deviceName = "Living Room Light";
-    devInfoRoomLight.types = &deviceType;
-    devInfoRoomLight.specVersion = NULL;
-    devInfoRoomLight.dataModelVersions = NULL;
+    cout << "Publishing default resources" << endl;
 
-    OCStackResult res = OCSetDeviceInfo(devInfoRoomLight);
+    OCStackResult res = SetDeviceInfo();
 
     if (res != OC_STACK_OK)
     {
-        cout << "Setting device info failed" << endl;
+        cout << "Publishing device info failed" << endl;
     }
 
     res = OCRDPublish(host.c_str(), CT_ADAPTER_TCP, NULL, 0, &cbData, OC_LOW_QOS);
@@ -488,7 +514,7 @@ void PublishResources(string host)
         cout << "Unable to publish default resources to cloud" << endl;
     }
 
-    cout << "Publish user resources" << endl;
+    cout << "Publishing user resources" << endl;
 
     res = OCRDPublish(host.c_str(), CT_ADAPTER_TCP, resourceHandles, 1, &cbData, OC_LOW_QOS);
     if (res != OC_STACK_OK)
index 8caa729..da7a793 100644 (file)
 
 #define TAG "IoTivityZigbeeServer"
 #define defaultComPort "/dev/ttyUSB0"
+
+#define VERIFY_SUCCESS(op)                          \
+{                                                   \
+    if (op !=  OC_STACK_OK)                         \
+    {                                               \
+        OIC_LOG_V(FATAL, TAG, "%s failed!!", #op);  \
+        goto exit;                                  \
+    }                                               \
+}
+
 int main()
 {
     OIC_LOG(INFO, TAG, "Initializing IoTivity...");
@@ -136,18 +146,21 @@ OCStackResult SetPlatformInfo()
 
 OCStackResult SetDeviceInfo()
 {
-    static OCDeviceInfo deviceInfo =
-        {
-            .deviceName = "IoTivity/Zigbee Server Sample",
-            .specVersion = "IoTivity/Zigbee Device Spec Version",
-        };
-    char *dmv = OICStrdup("IoTivity/Zigbee Data Model Version");
-    deviceInfo.dataModelVersions = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
-    deviceInfo.dataModelVersions->value = dmv;
-    char *dup = OICStrdup("oic.wk.d");
-    deviceInfo.types = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
-    deviceInfo.types->value = dup;
-    return OCSetDeviceInfo(deviceInfo);
+    VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
+                                      "IoTivity/Zigbee Server Sample"));
+
+    VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION,
+                                      "IoTivity/Zigbee Device Spec Version"));
+
+    VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+                                      "IoTivity/Zigbee Data Model Version"));
+
+    OIC_LOG(INFO, TAG, "Device information initialized successfully.");
+    return OC_STACK_OK;
+
+exit:
+    return OC_STACK_ERROR;
+
 }
 
 bool processSignal(bool set)
index 159684f..92d9e0a 100644 (file)
@@ -238,6 +238,8 @@ OCStackResult OCSetDefaultDeviceEntityHandler(OCDeviceEntityHandler entityHandle
  * list. The default Device Type is mandatory and always specified by this Device as the first
  * Device Type.
  *
+ * @deprecated Use OCSetPropertyValue instead.
+ *
  * @param deviceInfo   Structure passed by the server application containing the device
  *                     information.
  *
index f1b1abe..0e53bdc 100644 (file)
 #include "common.h"
 #include "oic_string.h"
 
-//string length of "/a/light/" + std::numeric_limits<int>::digits10 + '\0'"
+#define VERIFY_SUCCESS(op)                          \
+{                                                   \
+    if (op !=  OC_STACK_OK)                         \
+    {                                               \
+        OIC_LOG_V(FATAL, TAG, "%s failed!!", #op);  \
+        goto exit;                                  \
+    }                                               \
+}
+
+// string length of "/a/light/" + std::numeric_limits<int>::digits10 + '\0'"
 // 9 + 9 + 1 = 19
 const int URI_MAXSIZE = 19;
 
@@ -69,10 +78,10 @@ pthread_t threadId_presence;
 static bool observeThreadStarted = false;
 
 #ifdef WITH_PRESENCE
-#define numPresenceResources (2)
+#define NUM_PRESENCE_RESOURCES 2
 #endif
 
-char *gResourceUri= (char *)"/a/light";
+char *gResourceUri = (char *)"/a/light";
 const char *dateOfManufacture = "2016-01-15";
 const char *deviceName = "myDeviceName";
 const char *deviceUUID = "51b55ddc-ccbb-4cb3-a57f-494eeca13a21";
@@ -89,14 +98,9 @@ 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.1.0";
-
-// Entity handler should check for resourceTypeName and ResourceInterface in order to GET
-// the existence of a known resource
-const char *resourceTypeName = "core.light";
-const char *resourceInterface = OC_RSRVD_INTERFACE_DEFAULT;
+const char *deviceType = "oic.d.tv";
 
 OCPlatformInfo platformInfo;
-OCDeviceInfo deviceInfo;
 
 OCRepPayload* getPayload(const char* uri, int64_t power, bool state)
 {
@@ -178,8 +182,8 @@ bool checkIfQueryForPowerPassed(char * query)
             int powerRequested = atoi(pointerToOperator + 1);
             if (Light.power > powerRequested)
             {
-                OIC_LOG_V(INFO, TAG, "Current power: %d. Requested: <%d", Light.power
-                            , powerRequested);
+                OIC_LOG_V(INFO, TAG, "Current power: %d. Requested: <%d", Light.power,
+                          powerRequested);
                 return false;
             }
         }
@@ -434,7 +438,9 @@ void ProcessObserveDeregister (OCEntityHandlerRequest *ehRequest)
         }
     }
     if (clientStillObserving == false)
+    {
         gLightUnderObservation = 0;
+    }
 }
 
 OCEntityHandlerResult
@@ -763,17 +769,17 @@ void *presenceNotificationGenerator(void *param)
     OIC_LOG_V(INFO, TAG, "Will send out presence in %u seconds", secondsBeforePresence);
     sleep(secondsBeforePresence);
     (void)param;
-    OCDoHandle presenceNotificationHandles[numPresenceResources];
+    OCDoHandle presenceNotificationHandles[NUM_PRESENCE_RESOURCES];
     OCStackResult res = OC_STACK_OK;
 
-    std::array<std::string, numPresenceResources> presenceNotificationResources { {
+    std::array<std::string, NUM_PRESENCE_RESOURCES> presenceNotificationResources { {
         std::string("core.fan"),
         std::string("core.led") } };
-    std::array<std::string, numPresenceResources> presenceNotificationUris { {
+    std::array<std::string, NUM_PRESENCE_RESOURCES> presenceNotificationUris { {
         std::string("/a/fan"),
         std::string("/a/led") } };
 
-    for(int i=0; i<numPresenceResources; i++)
+    for(int i=0; i<NUM_PRESENCE_RESOURCES; i++)
     {
         if(res == OC_STACK_OK)
         {
@@ -797,7 +803,7 @@ void *presenceNotificationGenerator(void *param)
                                 presenceNotificationUris[i].c_str());
     }
     sleep(5);
-    for(int i=0; i<numPresenceResources; i++)
+    for(int i=0; i<NUM_PRESENCE_RESOURCES; i++)
     {
         if(res == OC_STACK_OK)
         {
@@ -872,24 +878,17 @@ int createLightResource (char *uri, LightResource *lightResource)
 
 void DeletePlatformInfo()
 {
-    free (platformInfo.platformID);
-    free (platformInfo.manufacturerName);
-    free (platformInfo.manufacturerUrl);
-    free (platformInfo.modelNumber);
-    free (platformInfo.dateOfManufacture);
-    free (platformInfo.platformVersion);
-    free (platformInfo.operatingSystemVersion);
-    free (platformInfo.hardwareVersion);
-    free (platformInfo.firmwareVersion);
-    free (platformInfo.supportUrl);
-    free (platformInfo.systemTime);
-}
-
-void DeleteDeviceInfo()
-{
-    free (deviceInfo.deviceName);
-    free (deviceInfo.specVersion);
-    OCFreeOCStringLL (deviceInfo.dataModelVersions);
+    free(platformInfo.platformID);
+    free(platformInfo.manufacturerName);
+    free(platformInfo.manufacturerUrl);
+    free(platformInfo.modelNumber);
+    free(platformInfo.dateOfManufacture);
+    free(platformInfo.platformVersion);
+    free(platformInfo.operatingSystemVersion);
+    free(platformInfo.hardwareVersion);
+    free(platformInfo.firmwareVersion);
+    free(platformInfo.supportUrl);
+    free(platformInfo.systemTime);
 }
 
 bool DuplicateString(char** targetString, const char* sourceString)
@@ -993,23 +992,26 @@ OCStackResult SetPlatformInfo(const char* platformID, const char *manufacturerNa
     return OC_STACK_ERROR;
 }
 
-OCStackResult SetDeviceInfo(const char* deviceName, const char* specVersion, const char* dataModelVersions)
+OCStackResult SetDeviceInfo()
 {
-    if(!DuplicateString(&deviceInfo.deviceName, deviceName))
-    {
-        return OC_STACK_ERROR;
-    }
-    if(!DuplicateString(&deviceInfo.specVersion, specVersion))
+    OCResourceHandle resourceHandle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
+    if (resourceHandle == NULL)
     {
-        return OC_STACK_ERROR;
-    }
-    OCFreeOCStringLL(deviceInfo.dataModelVersions);
-    deviceInfo.dataModelVersions = OCCreateOCStringLL(dataModelVersions);
-    if (!deviceInfo.dataModelVersions)
-    {
-        return OC_STACK_ERROR;
+        OIC_LOG(ERROR, TAG, "Device Resource does not exist.");
+        goto exit;
     }
+
+    VERIFY_SUCCESS(OCBindResourceTypeToResource(resourceHandle, deviceType));
+    VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, deviceName));
+    VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion));
+    VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+                                      dataModelVersions));
+
+    OIC_LOG(INFO, TAG, "Device information initialized successfully.");
     return OC_STACK_OK;
+
+exit:
+    return OC_STACK_ERROR;
 }
 
 static void PrintUsage()
@@ -1163,8 +1165,8 @@ int main(int argc, char* argv[])
 
     OCStackResult registrationResult =
         SetPlatformInfo(platformID, manufacturerName, manufacturerLink, modelNumber,
-            dateOfManufacture, platformVersion,  operatingSystemVersion,  hardwareVersion,
-            firmwareVersion,  supportLink, systemTime);
+                        dateOfManufacture, platformVersion,  operatingSystemVersion,
+                        hardwareVersion, firmwareVersion, supportLink, systemTime);
 
     if (registrationResult != OC_STACK_OK)
     {
@@ -1180,24 +1182,14 @@ int main(int argc, char* argv[])
         exit (EXIT_FAILURE);
     }
 
-    registrationResult = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
-
-    if (registrationResult != OC_STACK_OK)
-    {
-        OIC_LOG(INFO, TAG, "Device info setting failed locally!");
-        exit (EXIT_FAILURE);
-    }
-
-    OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv");
-
-    registrationResult = OCSetDeviceInfo(deviceInfo);
+    registrationResult = SetDeviceInfo();
 
     if (registrationResult != OC_STACK_OK)
     {
         OIC_LOG(INFO, TAG, "Device Registration failed!");
         exit (EXIT_FAILURE);
     }
-
+  
     /*
      * Declare and create the example resource: Light
      */
@@ -1214,7 +1206,6 @@ int main(int argc, char* argv[])
      * Create a thread for generating changes that cause presence notifications
      * to be sent to clients
      */
-
     #ifdef WITH_PRESENCE
     pthread_create(&threadId_presence, NULL, presenceNotificationGenerator, (void *)NULL);
     #endif
@@ -1223,7 +1214,6 @@ int main(int argc, char* argv[])
     OIC_LOG(INFO, TAG, "Entering ocserver main loop...");
 
     DeletePlatformInfo();
-    DeleteDeviceInfo();
 
     signal(SIGINT, handleSigInt);
 
index 2ec021d..ae36f7a 100644 (file)
 #include "ocserver.h"
 using namespace std;
 
+#define VERIFY_SUCCESS(op)                          \
+{                                                   \
+    if (op != OC_STACK_OK)                          \
+    {                                               \
+        cout << #op << " failed!!" << endl;         \
+        goto exit;                                  \
+    }                                               \
+}
+
 //string length of "/a/light/" + std::numeric_limits<int>::digits10 + '\0'"
 // 9 + 9 + 1 = 19
 const int URI_MAXSIZE = 19;
@@ -79,6 +88,7 @@ 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.1.0";
+const char *deviceType = "oic.d.tv";
 
 // Entity handler should check for resourceTypeName and ResourceInterface in order to GET
 // the existence of a known resource
@@ -86,7 +96,6 @@ const char *resourceTypeName = "core.light";
 const char *resourceInterface = OC_RSRVD_INTERFACE_DEFAULT;
 
 OCPlatformInfo platformInfo;
-OCDeviceInfo deviceInfo;
 
 OCRepPayload* getPayload(const char* uri, int64_t power, bool state)
 {
@@ -808,13 +817,6 @@ void DeletePlatformInfo()
     free (platformInfo.systemTime);
 }
 
-void DeleteDeviceInfo()
-{
-    free (deviceInfo.deviceName);
-    free (deviceInfo.specVersion);
-    OCFreeOCStringLL (deviceInfo.dataModelVersions);
-}
-
 bool DuplicateString(char** targetString, const char* sourceString)
 {
     if(!sourceString)
@@ -916,23 +918,26 @@ OCStackResult SetPlatformInfo(const char* platformID, const char *manufacturerNa
     return OC_STACK_ERROR;
 }
 
-OCStackResult SetDeviceInfo(const char* deviceName, const char* specVersion, const char* dataModelVersions)
+OCStackResult SetDeviceInfo()
 {
-    if(!DuplicateString(&deviceInfo.deviceName, deviceName))
+    OCResourceHandle resourceHandle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
+    if (resourceHandle == NULL)
     {
-        return OC_STACK_ERROR;
-    }
-    if(!DuplicateString(&deviceInfo.specVersion, specVersion))
-    {
-        return OC_STACK_ERROR;
-    }
-    OCFreeOCStringLL(deviceInfo.dataModelVersions);
-    deviceInfo.dataModelVersions = OCCreateOCStringLL(dataModelVersions);
-    if (!deviceInfo.dataModelVersions)
-    {
-        return OC_STACK_ERROR;
+        OIC_LOG(ERROR, TAG, "Device Resource does not exist.");
+        goto exit;
     }
+
+    VERIFY_SUCCESS(OCBindResourceTypeToResource(resourceHandle, deviceType));
+    VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, deviceName));
+    VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion));
+    VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+                                      dataModelVersions));
+
+    OIC_LOG(INFO, TAG, "Device information initialized successfully.");
     return OC_STACK_OK;
+
+exit:
+    return OC_STACK_ERROR;
 }
 
 static void PrintUsage()
@@ -1033,17 +1038,7 @@ int main(int argc, char* argv[])
         exit (EXIT_FAILURE);
     }
 
-    registrationResult = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
-
-    if (registrationResult != OC_STACK_OK)
-    {
-        cout << "\nDevice info setting failed locally!";
-        exit (EXIT_FAILURE);
-    }
-
-    OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv");
-
-    registrationResult = OCSetDeviceInfo(deviceInfo);
+    registrationResult = SetDeviceInfo();
 
     if (registrationResult != OC_STACK_OK)
     {
@@ -1080,7 +1075,6 @@ int main(int argc, char* argv[])
     cout << "\nEntering ocserver main loop...";
 
     DeletePlatformInfo();
-    DeleteDeviceInfo();
 
     signal(SIGINT, handleSigInt);
 
index 1c3404a..7bb24a2 100644 (file)
@@ -49,14 +49,14 @@ 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.1.0";
+std::vector<std::string> dataModelVersions = {"res.1.1.0", "sh.1.1.0"};
+
+// Device type
+std::string  deviceType = "oic.d.tv";
 
 // 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;
@@ -72,14 +72,6 @@ void DeletePlatformInfo()
     delete[] platformInfo.systemTime;
 }
 
-
-void DeleteDeviceInfo()
-{
-    delete[] deviceInfo.deviceName;
-    delete[] deviceInfo.specVersion;
-    OCFreeOCStringLL(deviceInfo.dataModelVersions);
-}
-
 void DuplicateString(char ** targetString, std::string sourceString)
 {
     *targetString = new char[sourceString.length() + 1];
@@ -106,18 +98,44 @@ OCStackResult SetPlatformInfo(std::string platformID, std::string manufacturerNa
     return OC_STACK_OK;
 }
 
-OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
+OCStackResult SetDeviceInfo()
 {
-    DuplicateString(&deviceInfo.deviceName, deviceName);
+    OCStackResult result = OC_STACK_ERROR;
+
+    OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
+    if (handle == NULL)
+    {
+        std::cout << "Failed to find resource " << OC_RSRVD_DEVICE_URI << std::endl;
+        return result;
+    }
 
-    if (!specVersion.empty())
+    result = OCBindResourceTypeToResource(handle, deviceType.c_str());
+    if (result != OC_STACK_OK)
     {
-        DuplicateString(&deviceInfo.specVersion, specVersion);
+        std::cout << "Failed to add device type" << std::endl;
+        return result;
     }
 
-    if (!dataModelVersions.empty())
+    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, deviceName);
+    if (result != OC_STACK_OK)
     {
-        OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+        std::cout << "Failed to set device name" << std::endl;
+        return result;
+    }
+
+    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+                                          dataModelVersions);
+    if (result != OC_STACK_OK)
+    {
+        std::cout << "Failed to set data model versions" << std::endl;
+        return result;
+    }
+
+    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion);
+    if (result != OC_STACK_OK)
+    {
+        std::cout << "Failed to set spec version" << std::endl;
+        return result;
     }
 
     return OC_STACK_OK;
@@ -144,27 +162,21 @@ int main()
 
     result = OCPlatform::registerPlatformInfo(platformInfo);
 
-    if(result != OC_STACK_OK)
+    if (result != OC_STACK_OK)
     {
         std::cout << "Platform Registration failed\n";
         return -1;
     }
 
+    result = SetDeviceInfo();
 
-    result = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
-    OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
-    OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv");
-
-    result = OCPlatform::registerDeviceInfo(deviceInfo);
-
-    if(result != OC_STACK_OK)
+    if (result != OC_STACK_OK)
     {
         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 05ed1d8..d1622b0 100644 (file)
@@ -62,14 +62,11 @@ std::string  systemTime = "2016-01-15T11.01";
 // Set of strings for each of device info fields
 std::string  deviceName = "IoTivity Fridge Server";
 std::string  specVersion = "core.1.1.0";
-std::string  dataModelVersions = "res.1.1.0";
+std::vector<std::string> dataModelVersions = {"res.1.1.0"};
 
 // OCPlatformInfo Contains all the platform info to be stored
 OCPlatformInfo platformInfo;
 
-// OCDeviceInfo Contains all the device info to be stored
-OCDeviceInfo deviceInfo;
-
 class Resource
 {
     protected:
@@ -504,13 +501,6 @@ void DeletePlatformInfo()
     delete[] platformInfo.systemTime;
 }
 
-void DeleteDeviceInfo()
-{
-    delete[] deviceInfo.deviceName;
-    delete[] deviceInfo.specVersion;
-    OCFreeOCStringLL(deviceInfo.dataModelVersions);
-}
-
 void DuplicateString(char ** targetString, std::string sourceString)
 {
     *targetString = new char[sourceString.length() + 1];
@@ -537,18 +527,29 @@ OCStackResult SetPlatformInfo(std::string platformID, std::string manufacturerNa
     return OC_STACK_OK;
 }
 
-OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
+OCStackResult SetDeviceInfo()
 {
-    DuplicateString(&deviceInfo.deviceName, deviceName);
+    OCStackResult result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
+                                                        deviceName);
+    if (result != OC_STACK_OK)
+    {
+        std::cout << "Failed to set device name" << std::endl;
+        return result;
+    }
 
-    if (!specVersion.empty())
+    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+                                          dataModelVersions);
+    if (result != OC_STACK_OK)
     {
-        DuplicateString(&deviceInfo.specVersion, specVersion);
+        std::cout << "Failed to set data model versions" << std::endl;
+        return result;
     }
 
-    if (!dataModelVersions.empty())
+    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion);
+    if (result != OC_STACK_OK)
     {
-        OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+        std::cout << "Failed to set spec version" << std::endl;
+        return result;
     }
 
     return OC_STACK_OK;
@@ -582,10 +583,7 @@ int main ()
         return -1;
     }
 
-    result = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
-    OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
-
-    result = OCPlatform::registerDeviceInfo(deviceInfo);
+    result = SetDeviceInfo();
 
     if (result != OC_STACK_OK)
     {
@@ -594,7 +592,6 @@ int main ()
     }
 
     DeletePlatformInfo();
-    DeleteDeviceInfo();
     // we will keep the server alive for at most 30 minutes
     std::this_thread::sleep_for(std::chrono::minutes(30));
     return 0;
index f176b7f..ab4072d 100644 (file)
@@ -51,14 +51,11 @@ std::string  systemTime = "2016-01-15T11.01";
 // Set of strings for each of device info fields
 std::string  deviceName = "IoTivity Garage Server";
 std::string  specVersion = "core.1.1.0";
-std::string  dataModelVersions = "res.1.1.0";
+std::vector<std::string> dataModelVersions = {"res.1.1.0"};
 
 // OCPlatformInfo Contains all the platform info to be stored
 OCPlatformInfo platformInfo;
 
-// OCDeviceInfo Contains all the device info to be stored
-OCDeviceInfo deviceInfo;
-
 // Forward declaring the entityHandler
 OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request);
 
@@ -280,13 +277,6 @@ void DeletePlatformInfo()
     delete[] platformInfo.systemTime;
 }
 
-void DeleteDeviceInfo()
-{
-    delete[] deviceInfo.deviceName;
-    delete[] deviceInfo.specVersion;
-    OCFreeOCStringLL(deviceInfo.dataModelVersions);
-}
-
 void DuplicateString(char ** targetString, std::string sourceString)
 {
     *targetString = new char[sourceString.length() + 1];
@@ -313,18 +303,29 @@ OCStackResult SetPlatformInfo(std::string platformID, std::string manufacturerNa
     return OC_STACK_OK;
 }
 
-OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
+OCStackResult SetDeviceInfo()
 {
-    DuplicateString(&deviceInfo.deviceName, deviceName);
+    OCStackResult result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
+                                                        deviceName);
+    if (result != OC_STACK_OK)
+    {
+        cout << "Failed to set device name" << endl;
+        return result;
+    }
 
-    if (!specVersion.empty())
+    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+                                          dataModelVersions);
+    if (result != OC_STACK_OK)
     {
-        DuplicateString(&deviceInfo.specVersion, specVersion);
+        cout << "Failed to set data model versions" << endl;
+        return result;
     }
 
-    if (!dataModelVersions.empty())
+    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion);
+    if (result != OC_STACK_OK)
     {
-        OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+        cout << "Failed to set spec version" << endl;
+        return result;
     }
 
     return OC_STACK_OK;
@@ -356,23 +357,19 @@ int main(int /*argc*/, char** /*argv[1]*/)
         return -1;
     }
 
-    result = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
-    OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
-
-    result = OCPlatform::registerDeviceInfo(deviceInfo);
-
+    result = SetDeviceInfo();
     if (result != OC_STACK_OK)
     {
         std::cout << "Device Registration failed\n";
         return -1;
     }
+
     try
     {
         // Invoke createResource function of class light.
         myGarage.createResource();
 
         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
         // don't ever call cv.notify, this should be a non-processor intensive version
index 1e9a2c1..55188e9 100644 (file)
@@ -62,14 +62,11 @@ std::string  systemTime = "2016-01-15T11.01";
 // Set of strings for each of device info fields
 std::string  deviceName = "IoTivity Light Server";
 std::string  specVersion = "core.1.1.0";
-std::string  dataModelVersions = "res.1.1.0";
+std::vector<std::string> dataModelVersions = {"res.1.1.0"};
 
 // OCPlatformInfo Contains all the platform info to be stored
 OCPlatformInfo platformInfo;
 
-// OCDeviceInfo Contains all the device info to be stored
-OCDeviceInfo deviceInfo;
-
 // Specifies secure or non-secure
 // false: non-secure resource
 // true: secure resource
@@ -326,13 +323,6 @@ void DeletePlatformInfo()
     delete[] platformInfo.systemTime;
 }
 
-void DeleteDeviceInfo()
-{
-    delete[] deviceInfo.deviceName;
-    delete[] deviceInfo.specVersion;
-    OCFreeOCStringLL(deviceInfo.dataModelVersions);
-}
-
 void DuplicateString(char ** targetString, std::string sourceString)
 {
     *targetString = new char[sourceString.length() + 1];
@@ -360,18 +350,29 @@ OCStackResult SetPlatformInfo(std::string platformID, std::string manufacturerNa
     return OC_STACK_OK;
 }
 
-OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
+OCStackResult SetDeviceInfo()
 {
-    DuplicateString(&deviceInfo.deviceName, deviceName);
+    OCStackResult result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
+                                                        deviceName);
+    if (result != OC_STACK_OK)
+    {
+        cout << "Failed to set device name" << endl;
+        return result;
+    }
 
-    if (!specVersion.empty())
+    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+                                          dataModelVersions);
+    if (result != OC_STACK_OK)
     {
-        DuplicateString(&deviceInfo.specVersion, specVersion);
+        cout << "Failed to set data model versions" << endl;
+        return result;
     }
 
-    if (!dataModelVersions.empty())
+    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion);
+    if (result != OC_STACK_OK)
     {
-        OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+        cout << "Failed to set spec version" << endl;
+        return result;
     }
 
     return OC_STACK_OK;
@@ -403,10 +404,7 @@ int main(int /*argc*/, char** /*argv[]*/)
         return -1;
     }
 
-    result = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
-    OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
-
-    result = OCPlatform::registerDeviceInfo(deviceInfo);
+    result = SetDeviceInfo();
 
     if (result != OC_STACK_OK)
     {
@@ -427,7 +425,6 @@ int main(int /*argc*/, char** /*argv[]*/)
         myLight.addInterface(std::string(LINK_INTERFACE));
 
         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 849a42c..18f353c 100644 (file)
@@ -113,12 +113,7 @@ public:
         std::string resourceInterface = DEFAULT_INTERFACE;
 
         /* Device Information */
-        char* deviceName = "IoTivity Media Server";
-        char* specVersion = "core.1.1.0";
-        OCStringLL types{ nullptr, const_cast<char*>(resourceTypeName.c_str()) };
-        OCDeviceInfo deviceInfo{ deviceName, &types, specVersion, nullptr };
-
-        result = OCPlatform::registerDeviceInfo(deviceInfo);
+        result = SetDeviceInfo();
         if (OC_STACK_OK != result)
         {
             cout << "Device information registration was unsuccessful\n";
@@ -409,6 +404,26 @@ OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request)
     return ehResult;
 }
 
+OCStackResult SetDeviceInfo()
+{
+    OCStackResult result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
+                                                        "IoTivity Media Server");
+    if (result != OC_STACK_OK)
+    {
+        cout << "Failed to set device name" << endl;
+        return result;
+    }
+
+    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, "core.1.1.0");
+    if (result != OC_STACK_OK)
+    {
+        cout << "Failed to set spec version" << endl;
+        return result;
+    }
+
+    return OC_STACK_OK;
+}
+
 };
 
 // ChangeMediaRepresentaion is an observation function,
index c8c7f9c..2ed2359 100644 (file)
@@ -62,14 +62,11 @@ std::string  systemTime = "2016-01-15T11.01";
 // Set of strings for each of device info fields
 std::string  deviceName = "IoTivity Presence Server";
 std::string  specVersion = "core.1.1.0";
-std::string  dataModelVersions = "res.1.1.0";
+std::vector<std::string> dataModelVersions = {"res.1.1.0"};
 
 // OCPlatformInfo Contains all the platform info to be stored
 OCPlatformInfo platformInfo;
 
-// OCDeviceInfo Contains all the device info to be stored
-OCDeviceInfo deviceInfo;
-
 // Forward declaring the entityHandler
 OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request);
 
@@ -237,13 +234,6 @@ void DeletePlatformInfo()
     delete[] platformInfo.systemTime;
 }
 
-void DeleteDeviceInfo()
-{
-    delete[] deviceInfo.deviceName;
-    delete[] deviceInfo.specVersion;
-    OCFreeOCStringLL(deviceInfo.dataModelVersions);
-}
-
 void DuplicateString(char ** targetString, std::string sourceString)
 {
     *targetString = new char[sourceString.length() + 1];
@@ -271,18 +261,29 @@ OCStackResult SetPlatformInfo(std::string platformID, std::string manufacturerNa
     return OC_STACK_OK;
 }
 
-OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
+OCStackResult SetDeviceInfo()
 {
-    DuplicateString(&deviceInfo.deviceName, deviceName);
+    OCStackResult result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
+                                                        deviceName);
+    if (result != OC_STACK_OK)
+    {
+        cout << "Failed to set device name" << endl;
+        return result;
+    }
 
-    if (!specVersion.empty())
+    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+                                          dataModelVersions);
+    if (result != OC_STACK_OK)
     {
-        DuplicateString(&deviceInfo.specVersion, specVersion);
+        cout << "Failed to set data model versions" << endl;
+        return result;
     }
 
-    if (!dataModelVersions.empty())
+    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion);
+    if (result != OC_STACK_OK)
     {
-        OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+        cout << "Failed to set spec version" << endl;
+        return result;
     }
 
     return OC_STACK_OK;
@@ -314,16 +315,13 @@ int main()
         return -1;
     }
 
-    result = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
-    OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
-
-    result = OCPlatform::registerDeviceInfo(deviceInfo);
-
+    result = SetDeviceInfo();
     if (result != OC_STACK_OK)
     {
         std::cout << "Device Registration failed\n";
         return -1;
     }
+
     try
     {
         using namespace OC::OCPlatform;
@@ -363,7 +361,6 @@ int main()
         createPresenceResources();
 
         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 a3091cc..07e8f51 100644 (file)
@@ -59,14 +59,11 @@ std::string  systemTime = "2016-01-15T11.01";
 // Set of strings for each of device info fields
 std::string  deviceName = "IoTivity Room Server";
 std::string  specVersion = "core.1.1.0";
-std::string  dataModelVersions = "res.1.1.0";
+std::vector<std::string> dataModelVersions = {"res.1.1.0"};
 
 // OCPlatformInfo Contains all the platform info to be stored
 OCPlatformInfo platformInfo;
 
-// OCDeviceInfo Contains all the device info to be stored
-OCDeviceInfo deviceInfo;
-
 class RoomResource
 {
 public:
@@ -568,13 +565,6 @@ void DeletePlatformInfo()
     delete[] platformInfo.systemTime;
 }
 
-void DeleteDeviceInfo()
-{
-    delete[] deviceInfo.deviceName;
-    delete[] deviceInfo.specVersion;
-    OCFreeOCStringLL(deviceInfo.dataModelVersions);
-}
-
 void DuplicateString(char ** targetString, std::string sourceString)
 {
     *targetString = new char[sourceString.length() + 1];
@@ -602,18 +592,30 @@ OCStackResult SetPlatformInfo(std::string platformID, std::string manufacturerNa
     return OC_STACK_OK;
 }
 
-OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
+OCStackResult SetDeviceInfo()
 {
-    DuplicateString(&deviceInfo.deviceName, deviceName);
+    OCStackResult result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
+                                                        deviceName);
+    if (result != OC_STACK_OK)
+    {
+        cout << "Failed to set device name" << endl;
+        return result;
+    }
 
-    if (!specVersion.empty())
+    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+                                          dataModelVersions);
+    if (result != OC_STACK_OK)
     {
-        DuplicateString(&deviceInfo.specVersion, specVersion);
+        cout << "Failed to set data model versions" << endl;
+        return result;
     }
 
-    if (!dataModelVersions.empty())
+    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion);
+
+    if (result != OC_STACK_OK)
     {
-        OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+        cout << "Failed to set spec version" << endl;
+        return result;
     }
 
     return OC_STACK_OK;
@@ -665,10 +667,7 @@ int main(int argc, char* argv[])
         return -1;
     }
 
-    result = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
-    OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
-    
-    result = OCPlatform::registerDeviceInfo(deviceInfo);
+    result = SetDeviceInfo();
 
     if (result != OC_STACK_OK)
     {
@@ -682,7 +681,6 @@ int main(int argc, char* argv[])
         myRoomResource.createResources();
 
         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
         // don't ever call cv.notify, this should be a non-processor intensive version
index 24aea45..04c7649 100644 (file)
@@ -66,15 +66,13 @@ std::string  systemTime = "2016-01-15T11.01";
 
 // Set of strings for each of device info fields
 std::string  deviceName = "IoTivity Simple Server";
+std::string  deviceType = "oic.wk.tv";
 std::string  specVersion = "core.1.1.0";
-std::string  dataModelVersions = "res.1.1.0,sh.1.1.0";
+std::vector<std::string> dataModelVersions = {"res.1.1.0", "sh.1.1.0"};
 
 // OCPlatformInfo Contains all the platform info to be stored
 OCPlatformInfo platformInfo;
 
-// OCDeviceInfo Contains all the device info to be stored
-OCDeviceInfo deviceInfo;
-
 // Specifies where to notify all observers or list of observers
 // false: notifies all observers
 // true: notifies list of observers
@@ -535,6 +533,49 @@ OCStackResult SetPlatformInfo(std::string platformID, std::string manufacturerNa
     return OC_STACK_OK;
 }
 
+OCStackResult SetDeviceInfo()
+{
+    OCStackResult result = OC_STACK_ERROR;
+
+    OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
+    if (handle == NULL)
+    {
+        cout << "Failed to find resource " << OC_RSRVD_DEVICE_URI << endl;
+        return result;
+    }
+
+    result = OCBindResourceTypeToResource(handle, deviceType.c_str());
+    if (result != OC_STACK_OK)
+    {
+        cout << "Failed to add device type" << endl;
+        return result;
+    }
+
+    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, deviceName);
+    if (result != OC_STACK_OK)
+    {
+        cout << "Failed to set device name" << endl;
+        return result;
+    }
+
+    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+                                          dataModelVersions);
+    if (result != OC_STACK_OK)
+    {
+        cout << "Failed to set data model versions" << endl;
+        return result;
+    }
+
+    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion);
+    if (result != OC_STACK_OK)
+    {
+        cout << "Failed to set spec version" << endl;
+        return result;
+    }
+
+    return OC_STACK_OK;
+}
+
 void * handleSlowResponse (void *param, std::shared_ptr<OCResourceRequest> pRequest)
 {
     // This function handles slow response case
@@ -636,16 +677,7 @@ int main(int argc, char* argv[])
         return -1;
     }
 
-    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, deviceName);
-    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion);
-    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
-        dataModelVersions);
-    OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
-    if (handle)
-    {
-        OCBindResourceTypeToResource(handle, "oic.wk.tv");
-    }
-
+    result = SetDeviceInfo();
     if (result != OC_STACK_OK)
     {
         std::cout << "Device Registration failed\n";
index ecfc2b4..e4db483 100644 (file)
@@ -64,14 +64,11 @@ std::string  systemTime = "2016-01-15T11.01";
 // Set of strings for each of device info fields
 std::string  deviceName = "IoTivity Simple Server HQ";
 std::string  specVersion = "core.1.1.0";
-std::string  dataModelVersions = "res.1.1.0";
+std::vector<std::string> dataModelVersions = {"res.1.1.0"};
 
 // OCPlatformInfo Contains all the platform info to be stored
 OCPlatformInfo platformInfo;
 
-// OCDeviceInfo Contains all the device info to be stored
-OCDeviceInfo deviceInfo;
-
 // Specifies where to notify all observers or list of observers
 // 0 - notifies all observers
 // 1 - notifies list of observers
@@ -451,13 +448,6 @@ void DeletePlatformInfo()
     delete[] platformInfo.systemTime;
 }
 
-void DeleteDeviceInfo()
-{
-    delete[] deviceInfo.deviceName;
-    delete[] deviceInfo.specVersion;
-    OCFreeOCStringLL(deviceInfo.dataModelVersions);
-}
-
 void DuplicateString(char ** targetString, std::string sourceString)
 {
     *targetString = new char[sourceString.length() + 1];
@@ -485,18 +475,29 @@ OCStackResult SetPlatformInfo(std::string platformID, std::string manufacturerNa
     return OC_STACK_OK;
 }
 
-OCStackResult SetDeviceInfo(std::string deviceName, std::string specVersion, std::string dataModelVersions)
+OCStackResult SetDeviceInfo()
 {
-    DuplicateString(&deviceInfo.deviceName, deviceName);
+    OCStackResult result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
+                                                        deviceName);
+    if (result != OC_STACK_OK)
+    {
+        cout << "Failed to set device name" << endl;
+        return result;
+    }
 
-    if (!specVersion.empty())
+    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
+                                          dataModelVersions);
+    if (result != OC_STACK_OK)
     {
-        DuplicateString(&deviceInfo.specVersion, specVersion);
+        cout << "Failed to set data model versions" << endl;
+        return result;
     }
 
-    if (!dataModelVersions.empty())
+    result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion);
+    if (result != OC_STACK_OK)
     {
-        OCResourcePayloadAddStringLL(&deviceInfo.dataModelVersions, dataModelVersions.c_str());
+        cout << "Failed to set spec version" << endl;
+        return result;
     }
 
     return OC_STACK_OK;
@@ -556,11 +557,7 @@ int main(int argc, char* argv[])
         return -1;
     }
 
-    result = SetDeviceInfo(deviceName, specVersion, dataModelVersions);
-    OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d");
-
-    result = OCPlatform::registerDeviceInfo(deviceInfo);
-
+    result = SetDeviceInfo();
     if (result != OC_STACK_OK)
     {
         std::cout << "Device Registration failed\n";
@@ -580,7 +577,6 @@ int main(int argc, char* argv[])
         myLight.addInterface(std::string(LINK_INTERFACE));
 
         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 8aee213..1025a15 100644 (file)
@@ -51,6 +51,7 @@ namespace OC
                     EntityHandler& entityHandler,
                     uint8_t resourceProperty) = 0;
 
+        // @deprecated: Use setPropertyValue instead.
         virtual OCStackResult registerDeviceInfo(
                     const OCDeviceInfo deviceInfo) = 0;
 
index 98587d3..9762818 100644 (file)
@@ -44,6 +44,7 @@ namespace OC
                     EntityHandler& entityHandler,
                     uint8_t resourceProperty);
 
+        // @deprecated: Use setPropertyValue instead.
         virtual OCStackResult registerDeviceInfo(
                     const OCDeviceInfo deviceInfo);
 
index 1242036..f934227 100644 (file)
@@ -328,6 +328,8 @@ namespace OC
         /**
         * Register Device Info
         *
+        * @deprecated: Use setPropertyValue instead.
+        *
         * @param deviceInfo structure containing all the device specific information
         * @return Returns ::OC_STACK_OK  if no errors and ::OC_STACK_ERROR in case of stack process error
         */
index 6e0d9db..4923de0 100644 (file)
@@ -195,6 +195,8 @@ namespace OC
         /**
          * This API registers all the device specific information
          *
+         * @deprecated: Use setPropertyValue instead.
+         *
          * @param deviceInfo Structure containing all the device related information
          *
          * @return Returns ::OC_STACK_OK if success