IPCA: Change to not use deprecated APIs.
authorSoemin Tjong <stjong@microsoft.com>
Mon, 20 Mar 2017 05:57:00 +0000 (22:57 -0700)
committerDan Mihai <Daniel.Mihai@microsoft.com>
Fri, 31 Mar 2017 00:51:25 +0000 (00:51 +0000)
Use setPropertyValue() instead of deprecated registerPlatformInfo() and
registerDeviceInfo().

Also, not calling setPropertyValue(OC_RSRVD_PLATFORM_ID) as platform ID
is automatically generated by OCStack.

Change-Id: Icf51cb27a408027a26eef51401b8b845cda7311d
Signed-off-by: Soemin Tjong <stjong@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/18153
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
resource/IPCA/src/inc/ocfframework.h
resource/IPCA/src/ocfframework.cpp
resource/IPCA/unittests/mockOC.cpp

index 5c8965c..61fa2e6 100644 (file)
@@ -253,6 +253,10 @@ class OCFFramework
         template <typename _T>
         void ThreadSafeCopy(const _T& source, _T& dest);
 
+        // Helper functions to set platform & device info.
+        IPCAStatus SetPlatformInfo(const OCPlatformInfo* platformInfo);
+        IPCAStatus SetDeviceInfo(const OCDeviceInfo* deviceInfo);
+
     private:
         // Lock for sync access to protected members in OCFFramework.
         std::recursive_mutex m_OCFFrameworkMutex;
index f44fc51..643229e 100644 (file)
@@ -53,6 +53,146 @@ OCFFramework::~OCFFramework()
 {
 }
 
+IPCAStatus OCFFramework::SetPlatformInfo(const OCPlatformInfo* pi)
+{
+    // Set platform info properties.
+    // Note: Platform ID is not set as it is automatically generated by the stack.
+
+    if (pi->manufacturerName &&
+        (OC_STACK_OK != OCPlatform::setPropertyValue(PAYLOAD_TYPE_PLATFORM,
+                                            OC_RSRVD_MFG_NAME,
+                                            pi->manufacturerName)))
+    {
+        OIC_LOG(ERROR, TAG, "Failed to set manufacturerName.");
+        return IPCA_FAIL;
+    }
+
+    if (pi->manufacturerUrl &&
+        (OC_STACK_OK != OCPlatform::setPropertyValue(PAYLOAD_TYPE_PLATFORM,
+                                            OC_RSRVD_MFG_URL,
+                                            pi->manufacturerUrl)))
+    {
+        OIC_LOG(ERROR, TAG, "Failed to set manufacturerUrl.");
+        return IPCA_FAIL;
+    }
+
+    if (pi->modelNumber &&
+        (OC_STACK_OK != OCPlatform::setPropertyValue(PAYLOAD_TYPE_PLATFORM,
+                                            OC_RSRVD_MODEL_NUM,
+                                            pi->modelNumber)))
+
+    {
+        OIC_LOG(ERROR, TAG, "Failed to set modelNumber.");
+        return IPCA_FAIL;
+    }
+
+    if (pi->dateOfManufacture &&
+        (OC_STACK_OK != OCPlatform::setPropertyValue(PAYLOAD_TYPE_PLATFORM,
+                                            OC_RSRVD_MFG_DATE,
+                                            pi->dateOfManufacture)))
+    {
+        OIC_LOG(ERROR, TAG, "Failed to set dateOfManufacture.");
+        return IPCA_FAIL;
+    }
+
+    if (pi->platformVersion &&
+        (OC_STACK_OK != OCPlatform::setPropertyValue(PAYLOAD_TYPE_PLATFORM,
+                                            OC_RSRVD_PLATFORM_VERSION,
+                                            pi->platformVersion)))
+    {
+        OIC_LOG(ERROR, TAG, "Failed to set platformVersion.");
+        return IPCA_FAIL;
+    }
+
+
+    if (pi->operatingSystemVersion &&
+        (OC_STACK_OK != OCPlatform::setPropertyValue(PAYLOAD_TYPE_PLATFORM,
+                                            OC_RSRVD_OS_VERSION,
+                                            pi->operatingSystemVersion)))
+    {
+        OIC_LOG(ERROR, TAG, "Failed to set operatingSystemVersion.");
+        return IPCA_FAIL;
+    }
+
+    if (pi->hardwareVersion &&
+        (OC_STACK_OK != OCPlatform::setPropertyValue(PAYLOAD_TYPE_PLATFORM,
+                                            OC_RSRVD_HARDWARE_VERSION,
+                                            pi->hardwareVersion)))
+    {
+        OIC_LOG(ERROR, TAG, "Failed to set hardwareVersion.");
+        return IPCA_FAIL;
+    }
+
+    if (pi->firmwareVersion &&
+        (OC_STACK_OK != OCPlatform::setPropertyValue(PAYLOAD_TYPE_PLATFORM,
+                                            OC_RSRVD_FIRMWARE_VERSION,
+                                            pi->firmwareVersion)))
+    {
+        OIC_LOG(ERROR, TAG, "Failed to set firmwareVersion.");
+        return IPCA_FAIL;
+    }
+
+    if (pi->supportUrl &&
+        (OC_STACK_OK != OCPlatform::setPropertyValue(PAYLOAD_TYPE_PLATFORM,
+                                            OC_RSRVD_SUPPORT_URL,
+                                            pi->supportUrl)))
+    {
+        OIC_LOG(ERROR, TAG, "Failed to set supportUrl.");
+        return IPCA_FAIL;
+    }
+
+    if (pi->systemTime &&
+        (OC_STACK_OK != OCPlatform::setPropertyValue(PAYLOAD_TYPE_PLATFORM,
+                                            OC_RSRVD_SYSTEM_TIME,
+                                            pi->systemTime)))
+    {
+        OIC_LOG(ERROR, TAG, "Failed to set systemTime.");
+        return IPCA_FAIL;
+    }
+
+    return IPCA_OK;
+}
+
+IPCAStatus OCFFramework::SetDeviceInfo(const OCDeviceInfo* di)
+{
+    if (di->deviceName &&
+        (OC_STACK_OK != OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE,
+                                            OC_RSRVD_DEVICE_NAME,
+                                            di->deviceName)))
+    {
+        OIC_LOG(ERROR, TAG, "Failed to set deviceName.");
+        return IPCA_FAIL;
+    }
+
+    std::vector<std::string> dataModelVersions;
+    OCStringLL* ver = di->dataModelVersions;
+    while (ver)
+    {
+        dataModelVersions.push_back(ver->value);
+        ver = ver->next;
+    }
+
+    if (dataModelVersions.size() &&
+        (OC_STACK_OK != OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE,
+                                            OC_RSRVD_DATA_MODEL_VERSION,
+                                            dataModelVersions)))
+    {
+        OIC_LOG(ERROR, TAG, "Failed to set dataModelVersions.");
+        return IPCA_FAIL;
+    }
+
+    if (di->specVersion &&
+        (OC_STACK_OK != OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE,
+                                            OC_RSRVD_SPEC_VERSION,
+                                            di->specVersion)))
+    {
+        OIC_LOG(ERROR, TAG, "Failed to set specVersion.");
+        return IPCA_FAIL;
+    }
+
+    return IPCA_OK;
+}
+
 IPCAStatus OCFFramework::Start(const IPCAAppInfoInternal& appInfo, bool isUnitTestMode)
 {
     std::lock_guard<std::mutex> lock(m_startStopMutex);
@@ -83,7 +223,8 @@ IPCAStatus OCFFramework::Start(const IPCAAppInfoInternal& appInfo, bool isUnitTe
     // Device Info.
     char deviceName[256];
     char deviceSoftwareVersion[256];
-    char manufacturerName[256];
+    char manufacturerName[256];     // @note: set the manufacturer name of device info ("dmn") when
+                                    //        implemented.
     OCStringLL types { nullptr, nullptr };  //  no vertical resource type.
 
     CopyStringToBufferAllowTruncate(
@@ -97,7 +238,6 @@ IPCAStatus OCFFramework::Start(const IPCAAppInfoInternal& appInfo, bool isUnitTe
 
     // Platform Info
     IPCAUuid platformUUID;
-    char platformId[UUID_STRING_SIZE] = { 0 };
     char platformManufacturerName[256] = "";
     char manufacturerUrl[256] = "";
     char modelNumber[] = "";
@@ -109,14 +249,9 @@ IPCAStatus OCFFramework::Start(const IPCAAppInfoInternal& appInfo, bool isUnitTe
     char supportURL[] = "";
 
 #if defined(_WIN32)
-    // @todo: generate per platform UUID (e.g. using input such as hostname).
-    platformUUID = {0xd9, 0x9c, 0x23, 0x50, 0xd9, 0x5e, 0x11, 0xe6,
-                    0xbf, 0x26, 0xce, 0xc0, 0xc9, 0x32, 0xce, 0x01};
     std::string platformName = "Microsoft";
     std::string platformUrl = "http://www.microsoft.com";
 #else
-    platformUUID = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
-                    0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
     std::string platformName = "";
     std::string platformUrl = "";
 #endif
@@ -127,10 +262,8 @@ IPCAStatus OCFFramework::Start(const IPCAAppInfoInternal& appInfo, bool isUnitTe
     CopyStringToBufferAllowTruncate(platformUrl,
         manufacturerUrl, ARRAY_SIZE(manufacturerUrl));
 
-    OCConvertUuidToString(platformUUID.uuid, platformId);
-
     OCPlatformInfo platformInfo = {
-        platformId,
+        nullptr,  /* rely on the stack to generate the platform ID. */
         platformManufacturerName,
         manufacturerUrl,
         modelNumber,
@@ -144,12 +277,13 @@ IPCAStatus OCFFramework::Start(const IPCAAppInfoInternal& appInfo, bool isUnitTe
 
     if (!isUnitTestMode)
     {
-        if (OC_STACK_OK != OCPlatform::registerPlatformInfo(platformInfo))
+        if (IPCA_OK != SetPlatformInfo(&platformInfo))
         {
             return IPCA_FAIL;
         }
 
-        if (OC_STACK_OK != OCPlatform::registerDeviceInfo(deviceInfo))
+
+        if (OC_STACK_OK != SetDeviceInfo(&deviceInfo))
         {
             return IPCA_FAIL;
         }
index b8fb122..349331f 100644 (file)
@@ -505,7 +505,7 @@ void defaultCallback(const HeaderOptions&, const OCRepresentation&, const int)
 }\r
 \r
 void defaultDeleteCallback(const HeaderOptions&, const int)\r
-{\r\r
+{\r
 }\r
 \r
 void defaultObserveCallback(const HeaderOptions&, const OCRepresentation&, const int, const int)\r