static int discoverAllDevices(void) { // delete un/owned device lists before updating them if(g_own_list) { OCDeleteDiscoveredDevices(g_own_list); g_own_list = NULL; } if(g_unown_list) { OCDeleteDiscoveredDevices(g_unown_list); g_unown_list = NULL; } // call |OCGetDevInfoFromNetwork| API actually printf(" Discovering All Un/Owned Devices on Network..\n"); if(OC_STACK_OK != OCGetDevInfoFromNetwork(DISCOVERY_TIMEOUT, &g_own_list, &g_unown_list)) { OIC_LOG(ERROR, TAG, "OCGetDevInfoFromNetwork API error"); return -1; } // display the discovered un/owned lists printf(" > Discovered Owned Devices\n"); g_own_cnt = printDevList(g_own_list); printf(" > Discovered Unowned Devices\n"); g_unown_cnt = printDevList(g_unown_list); return 0; }
OCStackResult OCSecure::getDevInfoFromNetwork(unsigned short timeout, DeviceList_t &ownedDevList, DeviceList_t &unownedDevList) { OCStackResult result = OC_STACK_OK; OCProvisionDev_t *owned = nullptr, *unowned = nullptr, *tmp = nullptr, *dev = nullptr; auto csdkLock = OCPlatform_impl::Instance().csdkLock(); auto cLock = csdkLock.lock(); if(cLock) { std::lock_guard<std::recursive_mutex> lock(*cLock); result = OCGetDevInfoFromNetwork(timeout, &owned, &unowned); if (result == OC_STACK_OK) { dev = owned; while (dev) { tmp = dev; ownedDevList.push_back(std::shared_ptr<OCSecureResource>( new OCSecureResource(csdkLock, dev))); dev = dev->next; tmp->next = nullptr; } dev = unowned; while (dev) { tmp = dev; unownedDevList.push_back(std::shared_ptr<OCSecureResource>( new OCSecureResource(csdkLock, dev))); dev = dev->next; tmp->next = nullptr; } } } else { oclog() <<"Mutex not found"; result = OC_STACK_ERROR; } return result; }
TEST(OCGetDevInfoFromNetworkTest, NullOwnedDeviceInfo) { OCProvisionDev_t *unownedList = NULL; EXPECT_EQ(OC_STACK_INVALID_PARAM, OCGetDevInfoFromNetwork(0, NULL, &unownedList)); }