--- /dev/null
+*.pro
+*.pro.*
#include <memory>
#include <OCApi.h>
#include <OCPlatform.h>
+#include <mutex>
+#include <condition_variable>
namespace NetworkManager {
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;
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__
--- /dev/null
+/**
+ * @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;
+}
#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()
}
-const UUID& IoTDevice_impl::getUUID()
+const std::string& IoTDevice_impl::getUUID()
{
return uuid;
}
#include "iotivity.h"
#include "iotdevice_impl.h"
+#include "IOT_DeviceFinder.h"
+#include <iostream>
namespace NetworkManager {
}
-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;
}
#include <string>
-#include "uuid.h"
namespace NetworkManager {
public:
virtual ~IoTDevice() {}
- virtual const UUID& getUUID() = 0;
+ virtual const std::string& getUUID() = 0;
virtual const std::string& getName() = 0;
}
-#endif // __IOTDEVICE_H__
\ No newline at end of file
+#endif // __IOTDEVICE_H__
#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
{
/**
* @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
};
#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
char* name;
char* model;
char* type;
- DeviceSessionState state;
+ DeviceState state;
} NM_DeviceInfo;
#define NULL_HANDLE (void*)0