Get device type info implemented.
authorLomtev Dmytro <d.lomtev@samsung.com>
Thu, 27 Apr 2017 06:54:50 +0000 (09:54 +0300)
committerLomtev Dmytro <d.lomtev@samsung.com>
Thu, 27 Apr 2017 14:15:01 +0000 (17:15 +0300)
network-manager/nmlib/IoT/src/iotdevice_impl.cpp

index 262a311..d856a01 100644 (file)
@@ -6,11 +6,34 @@ using namespace OC;
 namespace NetworkManager {
 
 const std::string IoTDevice_impl::dev_info_uri{"/oic/d"};
+const std::string dev_type_resource{"oic.d."};
+const std::string dev_type_uri{"/oic/res?rt=oic.wk.d"};
+
+using namespace std;
 
 IoTDevice_impl::IoTDevice_impl(std::shared_ptr<OCResource> device_resource)
     : dev(device_resource), name("unknown"), model("unknown"), type("unknown"), uuid("unknown"), spec_ver("unknown")
 {
     host = device_resource->host();
+
+    std::unique_lock<std::mutex> lock(mtx);
+
+    OCPlatform::findResource(device_resource->host(), dev_type_uri, device_resource->connectivityType(),
+                             [this](std::shared_ptr<OCResource> res) {
+        auto rt = res->getResourceTypes();
+        for (auto res_type: rt)
+        {
+            if (res_type.compare(0, dev_type_resource.length(), dev_type_resource) == 0)
+            {
+                type = res_type.substr(dev_type_resource.length());
+            }
+        }
+
+        this->cond_var.notify_one();
+    });
+
+    cond_var.wait_for(lock, std::chrono::seconds(CALLBACK_WAIT_TIMEOUT_S));
+
     OCPlatform::getDeviceInfo(device_resource->host(),
                               dev_info_uri,
                               device_resource->connectivityType(),
@@ -27,7 +50,7 @@ IoTDevice_impl::IoTDevice_impl(std::shared_ptr<OCResource> device_resource)
             this->name = std::move(value);
         }
 
-        if(rep.getValue("lcv", value))
+        if(rep.getValue("icv", value))
         {
             this->spec_ver = std::move(value);
         }
@@ -37,10 +60,9 @@ IoTDevice_impl::IoTDevice_impl(std::shared_ptr<OCResource> device_resource)
             this->model = std::move(value);
         }
 
-        this->cond_var.notify_all();
+        this->cond_var.notify_one();
     });
 
-    std::unique_lock<std::mutex> lock(mtx);
     cond_var.wait_for(lock, std::chrono::seconds(CALLBACK_WAIT_TIMEOUT_S));
 }