}
}
-namespace NetworkManager {
+namespace NetworkManager
+{
using namespace std;
IoTDevice_impl::IoTDevice_impl(std::shared_ptr<OCResource> device_resource, bool connected)
- : dev(device_resource), name("unknown"), model("unknown"), type("unknown"), uuid("unknown"), spec_ver("unknown"), online(connected)
+ : dev(device_resource), name("unknown"), model("unknown"), type("unknown"), uuid("unknown"), spec_ver("unknown"),
+ online(connected)
{
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) {
+ [this](std::shared_ptr<OCResource> res)
+ {
auto rt = res->getResourceTypes();
- for (auto res_type: rt)
+ for (auto res_type : rt)
{
if (res_type.compare(0, dev_type_resource.length(), dev_type_resource) == 0)
{
OCPlatform::getDeviceInfo(device_resource->host(),
dev_info_uri,
device_resource->connectivityType(),
- [this](const OCRepresentation& rep){
+ [this](const OCRepresentation & rep)
+ {
std::string value;
if(rep.getValue("di", value))
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): name("unknown"), model("unknown"), type("unknown"), uuid(uid), spec_ver("unknown"), host(host), online(connected)
+IoTDevice_impl::IoTDevice_impl(const std::string& host, const std::string& uid, bool connected)
+ : name("unknown"), model("unknown"), type("unknown"), uuid(uid), spec_ver("unknown"), host(host), online(connected)
{
- //std::string uri{"/oic/d?di="};
- std::string uri = dev_type_uri;
- uri += "&di=";
- uri += uuid;
-// uri += "&rt=oic.wk.d";
- std::cout << "Request: " << host << uri << std::endl;
-
std::unique_lock<std::mutex> lock(mtx);
- auto res = OCPlatform::getDeviceInfo(host, uri, static_cast<OCConnectivityType>(CT_ADAPTER_TCP | CT_IP_USE_V4),
- [this](const OCRepresentation& rep){
- std::string value;
- std::cout << "In getDeviceInfo CALLBACK" << std::endl;
- printRepresentation(rep);
+ string uri{"/oic/res?di="};
+ uri += uuid;
+ uri += "&rt=oic.wk.d";
- if(rep.getValue("n", value))
- {
- this->name = std::move(value);
- }
+ OCPlatform::findResource(host, uri, static_cast<OCConnectivityType>(CT_ADAPTER_TCP | CT_IP_USE_V4),
+ [this](shared_ptr<OC::OCResource> resource)
+ {
+ dev = resource;
- if(rep.getValue("icv", value))
- {
- this->spec_ver = std::move(value);
- }
+ auto rts = resource->getResourceTypes();
- if(rep.getValue("dmv", value))
+ for (auto res_type : rts)
{
- this->model = std::move(value);
+ if (res_type.compare(0, dev_type_resource.length(), dev_type_resource) == 0)
+ {
+ type = res_type.substr(dev_type_resource.length());
+ }
}
cond_var.notify_one();
- });
+ },
+ [this] (const std::string & uri, const int ecode)
+ {
+ std::cout << "Fail to found device on URI: " << uri << std::endl << "Error code: " << ecode << std::endl;
+ cond_var.notify_one();
+ }
+ );
cond_var.wait_for(lock, std::chrono::seconds(CALLBACK_WAIT_TIMEOUT_S));
+
+ if (dev)
+ {
+ QueryParamsMap get_params;
+ dev->get("oic.wk.d", "oic.if.baseline", get_params,
+ [this](const HeaderOptions & headers, const OCRepresentation & rep, const int ecode)
+ {
+ std::string value;
+
+ if(rep.getValue("n", value))
+ {
+ this->name = std::move(value);
+ }
+
+ if(rep.getValue("icv", value))
+ {
+ this->spec_ver = std::move(value);
+ }
+
+ if(rep.getValue("dmv", value))
+ {
+ this->model = std::move(value);
+ }
+ cond_var.notify_one();
+ });
+
+ cond_var.wait_for(lock, std::chrono::seconds(CALLBACK_WAIT_TIMEOUT_S));
+ }
}
-IoTDevice_impl::~IoTDevice_impl()
+IoTDevice_impl::~IoTDevice_impl()
{
}
NM_DeviceInfo info;
ASSERT_EQ(EC_OK, NM_getDeviceInfo(list, uid, &info));
- std::cout << "Device uid: " << uid << std::endl;
+ std::cout << "\t\tDevice uid: " << uid << std::endl;
ASSERT_STRNE(NULL, info.name);
- std::cout << "Device name: " << info.name << std::endl;
+ std::cout << "\t\tDevice name: " << info.name << std::endl;
ASSERT_STRNE(NULL, info.model);
- std::cout << "Device model: " << info.model << std::endl;
+ std::cout << "\t\tDevice model: " << info.model << std::endl;
ASSERT_STRNE(NULL, info.type);
- std::cout << "Device type: " << info.type << std::endl;
+ std::cout << "\t\tDevice type: " << info.type << std::endl;
- std::cout << "Device state: " << (info.state == DS_Online ? "online" : "offline") << std::endl;
+ std::cout << "\t\tDevice state: " << (info.state == DS_Online ? "online" : "offline") << std::endl << std::endl;
NM_freeDeviceInfo(&info);
}
ASSERT_EQ(EC_NULL_POINTER, NM_getUnownedDevices(ctx, nullptr));
ASSERT_EQ(EC_OK, NM_getUnownedDevices(ctx, &dev_list));
- std::cout << "Devices found: " << NM_getListSize(dev_list) << std::endl;
+ std::cout << "Unowned devices found: " << NM_getListSize(dev_list) << std::endl;
ASSERT_EQ(EC_NULL_POINTER, NM_deviceListForEach(nullptr, each_callback, nullptr));
ASSERT_EQ(EC_OK, NM_deviceListForEach(dev_list, each_callback, nullptr));
NM_freeDeviceList(nullptr);