Device info when unowned fix.
authorLomtev Dmytro <d.lomtev@samsung.com>
Thu, 11 May 2017 10:09:00 +0000 (13:09 +0300)
committerLomtev Dmytro <d.lomtev@samsung.com>
Thu, 11 May 2017 10:20:35 +0000 (13:20 +0300)
network-manager/nmlib/IoT/src/iotdevice_impl.cpp
network-manager/nmlib/IoT/src/iotivity.cpp

index e774bea..0ba2ff4 100644 (file)
@@ -91,13 +91,10 @@ IoTDevice_impl::IoTDevice_impl(std::shared_ptr<OCResource> device_resource, bool
 
     cond_var.wait_for(lock, std::chrono::seconds(CALLBACK_WAIT_TIMEOUT_S));
 
-    /* !!! Dima please review !!! */
-    this->uuid = device_resource->sid();
-
     OCPlatform::getDeviceInfo(device_resource->host(),
                               dev_info_uri,
                               device_resource->connectivityType(),
-                              [this](const OCRepresentation & rep)
+                              [this, &device_resource](const OCRepresentation & rep)
     {
         std::string value;
 
@@ -125,6 +122,28 @@ IoTDevice_impl::IoTDevice_impl(std::shared_ptr<OCResource> device_resource, bool
     });
 
     cond_var.wait_for(lock, std::chrono::seconds(CALLBACK_WAIT_TIMEOUT_S));
+
+    if (this->uuid.empty()) this->uuid = device_resource->sid();
+
+    if (name == "undefined" || name.empty())
+    {
+        std::shared_ptr<OIC::Service::RemoteEnrollee> remote_enrollee = OIC::Service::EasySetup::getInstance()->createRemoteEnrollee(device_resource);
+
+        remote_enrollee->getConfiguration(
+            [this](std::shared_ptr<OIC::Service::GetConfigurationStatus> status)
+            {
+                if(status->getESResult() == ES_OK)
+                {
+                    OIC::Service::EnrolleeConf conf = status->getEnrolleeConf();
+                    name = conf.getDeviceName();
+                    model = conf.getModelNumber();
+                }
+                cond_var.notify_one();
+            }
+        );
+
+        cond_var.wait_for(lock, std::chrono::seconds(CALLBACK_WAIT_TIMEOUT_S));
+    }
 }
 
 IoTDevice_impl::IoTDevice_impl(const std::string& host, const std::string& uid, bool connected)
index 0d11af1..070c472 100644 (file)
@@ -180,6 +180,9 @@ void IoTivity::signIn(const std::string& host, const std::string& login, const s
         throw std::invalid_argument("Wrong login credentials");
 
     OCAccountManager::Ptr accountMgr = OCPlatform::constructAccountManagerObject(host, CT_ADAPTER_TCP);
+
+    if (!accountMgr)
+        throw IoTInternalError("Can not create account manager", EC_IOTIVITY_ERROR);
     params->accountMgr = accountMgr;
 
     std::mutex mtx;