IOT_DeviceFinder was added
authori.metelytsia <i.metelytsia@samsung.com>
Thu, 20 Apr 2017 12:04:53 +0000 (15:04 +0300)
committeri.metelytsia <i.metelytsia@samsung.com>
Thu, 20 Apr 2017 12:04:53 +0000 (15:04 +0300)
network-manager/nmlib/IoT/inc/IOT_DeviceFinder.h [new file with mode: 0644]
network-manager/nmlib/IoT/src/IOT_DeviceFinder.cpp [new file with mode: 0644]

diff --git a/network-manager/nmlib/IoT/inc/IOT_DeviceFinder.h b/network-manager/nmlib/IoT/inc/IOT_DeviceFinder.h
new file mode 100644 (file)
index 0000000..5d76ee6
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef __IOT_DEVICE_FINDER_H__
+#define __IOT_DEVICE_FINDER_H__
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+
+class IOT_DeviceFinder
+{
+public:
+    IOT_DeviceFinder() = default;
+    IOT_DeviceFinder(const IOT_DeviceFinder&) = delete;
+
+    ~IOT_DeviceFinder() = default;
+
+    IOT_DeviceFinder& operator=(const IOT_DeviceFinder&) = delete;
+
+    std::vector<std::shared_ptr<OC::OCResource>> operator()(    const std::string& _host = "",
+                                                                const std::string& _request_uri = "/oic/res?rt=oic.wk.prov",
+                                                                OCConnectivityType _connectivity_type = CT_DEFAULT,
+                                                                OC::QualityOfService _QoS = OC::QualityOfService::LowQos,
+                                                                int _wait_for_sec = 3   );
+
+private:
+    std::vector<std::shared_ptr<OC::OCResource>> m_devices;
+};
+
+#endif /* __IOT_DEVICE_FINDER_H__ */
diff --git a/network-manager/nmlib/IoT/src/IOT_DeviceFinder.cpp b/network-manager/nmlib/IoT/src/IOT_DeviceFinder.cpp
new file mode 100644 (file)
index 0000000..e16657a
--- /dev/null
@@ -0,0 +1,29 @@
+#include <iostream>
+#include <memory>
+#include <string>
+#include <vector>
+#include <thread>
+#include <chrono>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+
+#include "IOT_DeviceFinder.h"
+
+std::vector<std::shared_ptr<OC::OCResource>> IOT_DeviceFinder::operator()(  const std::string& _host /*= ""*/,
+                                                                            const std::string& _request_uri /*= "/oic/res?rt=oic.wk.prov"*/,
+                                                                            OCConnectivityType _connectivity_type /*= CT_DEFAULT*/,
+                                                                            OC::QualityOfService _QoS /*= OC::QualityOfService::LowQos*/,
+                                                                            int _wait_for_sec /*= 3*/   )
+{
+    OC::OCPlatform::findResourceList(   _host,
+                                        _request_uri,
+                                        _connectivity_type,
+                                        [this](std::vector<std::shared_ptr<OC::OCResource>> _resources)
+                                        {
+                                            std::copy(_resources.begin(), _resources.end(), std::back_inserter(this->m_devices));
+                                        },
+                                        _QoS    );
+    std::this_thread::sleep_for(std::chrono::seconds(_wait_for_sec));
+    return m_devices;
+}