Control app API functions stub.
authorLomtev Dmytro <d.lomtev@samsung.com>
Mon, 24 Apr 2017 11:40:41 +0000 (14:40 +0300)
committerLomtev Dmytro <d.lomtev@samsung.com>
Mon, 24 Apr 2017 11:44:10 +0000 (14:44 +0300)
.gitignore [new file with mode: 0644]
network-manager/nmlib/IoT/inc/iotdevice_impl.h
network-manager/nmlib/IoT/src/iot_dev_manager.cpp [new file with mode: 0644]
network-manager/nmlib/IoT/src/iotdevice_impl.cpp
network-manager/nmlib/IoT/src/iotivity.cpp
network-manager/nmlib/include/iotdevice.h
network-manager/nmlib/include/iotivity.h
network-manager/nmlib/include/nmlib.h

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..e1a4cf7
--- /dev/null
@@ -0,0 +1,2 @@
+*.pro
+*.pro.*
index 06c032b..d495951 100644 (file)
@@ -5,6 +5,8 @@
 #include <memory>
 #include <OCApi.h>
 #include <OCPlatform.h>
+#include <mutex>
+#include <condition_variable>
 
 namespace NetworkManager {
 
@@ -14,7 +16,7 @@ public:
     IoTDevice_impl(std::shared_ptr<OC::OCResource> device_resource);
     ~IoTDevice_impl() override;
 
-    const UUID& getUUID() override;
+    const std::string& getUUID() override;
     
     const std::string& getName() override;
     
@@ -30,9 +32,12 @@ private:
     std::string name;
     std::string model;
     std::string type;
-    UUID uuid;
+    std::string uuid;
+    std::string spec_ver;
+    std::mutex mtx;
+    std::condition_variable cond_var;
 };
 
 }
 
-#endif // __IOTDEVICE_IMPL_H__
\ No newline at end of file
+#endif // __IOTDEVICE_IMPL_H__
diff --git a/network-manager/nmlib/IoT/src/iot_dev_manager.cpp b/network-manager/nmlib/IoT/src/iot_dev_manager.cpp
new file mode 100644 (file)
index 0000000..4785596
--- /dev/null
@@ -0,0 +1,105 @@
+/**
+ * @brief  IoTivity to Control App interface
+ * @date   Created 21.04.2017
+ * @author Created 2017 in Samsung Ukraine R&D Center (SURC) under a contract
+ *         between LLC "Samsung Electronics Ukraine Company" (Kiev, Ukraine)
+ *         and "Samsung Electronics Co", Ltd (Seoul, Republic of Korea).
+ *         Copyright: (c) Samsung Electronics Co, Ltd 2017. All rights reserved.
+ * @author Mail to: <A HREF="mailto:d.lomtev@samsung.com">Dmytro Lomtev, d.lomtev@samsung.com</A>
+ */
+
+#include <cstring>
+#include "nmlib.h"
+
+
+NM_ErrorCode NM_init(NM_hContext* ctx)
+{
+    ctx = nullptr;
+    return EC_NOT_IMPLEMENTED_YET;
+}
+
+void NM_cleanup(NM_hContext ctx)
+{
+
+}
+
+NM_ErrorCode NM_signIn(NM_hContext ctx, const char* host, const char* user, const char* pass)
+{
+    return EC_NOT_IMPLEMENTED_YET;
+}
+
+void NM_signOut(NM_hContext ctx)
+{
+
+}
+
+NM_ErrorCode NM_subscribeDeviceStateChanged(NM_hContext ctx, NM_deviceStateChangedCb* callback, void* user_defined)
+{
+    return EC_NOT_IMPLEMENTED_YET;
+}
+
+void NM_unsubscribeDeviceStateChanged(NM_hContext ctx)
+{
+
+}
+
+NM_ErrorCode NM_getOwnedDevices(NM_hContext ctx, NM_hDeviceList* dev_list)
+{
+    dev_list = nullptr;
+    return EC_NOT_IMPLEMENTED_YET;
+}
+
+NM_ErrorCode NM_freeDeviceList(NM_hDeviceList* dev_list)
+{
+    return EC_NOT_IMPLEMENTED_YET;
+}
+
+size_t NM_getListSize(NM_hDeviceList dev_list)
+{
+    return 0;
+}
+
+NM_ErrorCode NM_getUnownedDevices(NM_hContext ctx, NM_hDeviceList* dev_list)
+{
+    dev_list = nullptr;
+    return EC_NOT_IMPLEMENTED_YET;
+}
+
+void NM_resetDeviceList(NM_hDeviceList dev_list)
+{
+
+}
+
+const char* NM_deviceListEnum(NM_hDeviceList dev_list)
+{
+    return nullptr;
+}
+
+NM_ErrorCode NM_deviceListForEach(NM_hDeviceList dev_list, NM_deviceEnumerationCb* callback, void* user_defined)
+{
+    return EC_NOT_IMPLEMENTED_YET;
+}
+
+NM_ErrorCode NM_getDeviceInfo(NM_hDeviceList dev_list, const char* dev_id, NM_DeviceInfo* info)
+{
+    if (info == nullptr) return EC_NULL_POINTER;
+    info->name = nullptr;
+    info->model = nullptr;
+    info->type = nullptr;
+    return EC_NOT_IMPLEMENTED_YET;
+}
+
+void NM_freeDeviceInfo(NM_DeviceInfo* info)
+{
+    
+}
+
+NM_ErrorCode NM_ownDevice(NM_hDeviceList dev_list, const char* dev_id)
+{
+    return EC_NOT_IMPLEMENTED_YET;
+}
+
+NM_ErrorCode NM_unOwnDevice(NM_hDeviceList dev_list, const char* dev_id)
+{
+    return EC_NOT_IMPLEMENTED_YET;
+}
index 9ac1386..412bf28 100644 (file)
@@ -1,11 +1,45 @@
 #include "iotdevice_impl.h"
 
+using namespace OC;
+
 namespace NetworkManager {
 
 
-IoTDevice_impl::IoTDevice_impl(std::shared_ptr<OC::OCResource> device_resource)
-    : dev(device_resource), name("test iot device"), model("test model"), type("generic type"), uuid{0}
+IoTDevice_impl::IoTDevice_impl(std::shared_ptr<OCResource> device_resource)
+    : dev(device_resource), name("unknown"), model("unknown"), type("unknown"), uuid("unknown"), spec_ver("unknown")
 {
+    OCPlatform::getDeviceInfo(device_resource->host(),
+                              device_resource->uri(),
+                              device_resource->connectivityType(),
+                              [this](const OCRepresentation& rep){
+        std::string value;
+
+        if(rep.getValue("di", value))
+        {
+            this->uuid = std::move(value);
+        }
+
+        if(rep.getValue("n", value))
+        {
+            this->name = std::move(value);
+        }
+
+        if(rep.getValue("lcv", value))
+        {
+            this->spec_ver = std::move(value);
+        }
+
+        if(rep.getValue("dmv", value))
+        {
+            this->model = std::move(value);
+        }
+
+        this->cond_var.notify_one();
+    });
+
+    std::unique_lock<std::mutex> lock(mtx);
+
+    cond_var.wait(lock);
 }
 
 IoTDevice_impl::~IoTDevice_impl() 
@@ -13,7 +47,7 @@ IoTDevice_impl::~IoTDevice_impl()
 
 }
 
-const UUID& IoTDevice_impl::getUUID()
+const std::string& IoTDevice_impl::getUUID()
 {
     return uuid;
 }
index 9a30ee1..07b7fe2 100644 (file)
@@ -1,5 +1,7 @@
 #include "iotivity.h"
 #include "iotdevice_impl.h"
+#include "IOT_DeviceFinder.h"
+#include <iostream>
 
 namespace NetworkManager {
 
@@ -27,14 +29,25 @@ void IoTivity::signOut()
 }
 
 
-IoTDevicesVector IoTivity::getOwnedDevices()
+IoTDevicesMap IoTivity::getOwnedDevices()
 {
-    return IoTDevicesVector();
+    return IoTDevicesMap();
 }
 
-IoTDevicesVector IoTivity::getUnOwnedDevices()
+IoTDevicesMap IoTivity::getUnOwnedDevices()
 {
-    return IoTDevicesVector();
+    IoTDevicesMap map;
+    IOT_DeviceFinder dev_finder;
+    auto devs = dev_finder();
+    for (auto d : devs) {
+        std::shared_ptr<IoTDevice> dev(new IoTDevice_impl(d));
+        auto res = map.emplace(dev->getName(), dev);
+
+        if (!res.second) {
+            std::cerr << "IoTDevicesMap insertion failed" << std::endl;
+        }
+    }
+    return map;
 }
 
 
index 80caa4f..25022a6 100644 (file)
@@ -3,7 +3,6 @@
 
 
 #include <string>
-#include "uuid.h"
 
 namespace NetworkManager {
 
@@ -12,7 +11,7 @@ class IoTDevice
 public:    
     virtual ~IoTDevice() {}
 
-    virtual const UUID& getUUID() = 0;
+    virtual const std::string& getUUID() = 0;
     
     virtual const std::string& getName() = 0;
     
@@ -27,4 +26,4 @@ public:
 
 }
 
-#endif // __IOTDEVICE_H__
\ No newline at end of file
+#endif // __IOTDEVICE_H__
index 5c366c0..57f107d 100644 (file)
@@ -4,11 +4,11 @@
 #include "nmexceptions.h"
 #include "iotdevice.h"
 #include <memory>
-#include <vector>
+#include <map>
 
 namespace NetworkManager {
 
-typedef std::vector<std::shared_ptr<IoTDevice>> IoTDevicesVector;
+typedef std::map<std::string, std::shared_ptr<IoTDevice>> IoTDevicesMap;
 
 class IoTivity
 {
@@ -26,11 +26,11 @@ public:
     /**
      * @brief Get owned devices list from iotcloud server
      */
-    IoTDevicesVector getOwnedDevices();
+    IoTDevicesMap getOwnedDevices();
     /**
      * @brief Get unowned devices list from local network
      */
-    IoTDevicesVector getUnOwnedDevices();              // discuss which is preferable
+    IoTDevicesMap getUnOwnedDevices();              // discuss which is preferable
 };
 
 
index 734f423..d33d44b 100644 (file)
@@ -15,19 +15,20 @@ extern "C" {
 #endif
 
 typedef enum  {
-    NM_OK = 0,
-    NM_AUTH_ERROR,
-    NM_INTERNAL_ERROR,
-    NM_NOT_INITIALIZED,
-    NM_NULL_POINTER,
-    NM_OUT_OF_MEMORY,
-    NM_BAD_PARAMETER,
+    EC_OK = 0,
+    EC_AUTH_ERROR,
+    EC_INTERNAL_ERROR,
+    EC_NOT_INITIALIZED,
+    EC_NULL_POINTER,
+    EC_OUT_OF_MEMORY,
+    EC_BAD_PARAMETER,
+    EC_NOT_IMPLEMENTED_YET,
     // ...
 } NM_ErrorCode;
 
 typedef enum {
-    DS_Offline = 0
-    DS_Online = 1
+    DS_Offline = 0,
+    DS_Online = 1,
 } DeviceState;
 
 typedef struct
@@ -35,7 +36,7 @@ typedef struct
     char* name;
     char* model;
     char* type;
-    DeviceSessionState state;
+    DeviceState state;
 } NM_DeviceInfo;
 
 #define NULL_HANDLE (void*)0