typedef void* RemoteModule;
typedef void (*DeviceStateChangedCallback)(const char* devId, DeviceState state, void* userDefined);
- typedef void (*DeviceEnumCallback)(NM_hDeviceList, const char* devId, void* userDefined);
typedef void (*NmNotificationCallback)(NM_NotificationData,void*);
typedef NM_ErrorCode (*InitFunc)(NM_hContext*);
typedef SignInState (*GetSessionStateFunc)(NM_hContext);
typedef NM_ErrorCode (*SubscribeDevStateChangedFunc)(NM_hContext, DeviceStateChangedCallback, void*);
typedef void (*UnsubscribeDeviceStateChangedFunc)(NM_hContext);
- typedef NM_ErrorCode (*GetOwnedDevicesFunc)(NM_hContext ctx, NM_hDeviceList* devList);
- typedef NM_ErrorCode (*FreeDeviceListFunc)(NM_hDeviceList*);
- typedef size_t (*GetListSizeFunc)(NM_hDeviceList);
- typedef NM_ErrorCode (*GetUnownedDevicesFunc)(NM_hContext, NM_hDeviceList* devList);
- typedef void (*ResetDeviceListFunc)(NM_hDeviceList devList);
- typedef const char* (*DeviceListEnumFunc)(NM_hDeviceList devList);
- typedef NM_ErrorCode (*DeviceListForEachFunc)(NM_hDeviceList, DeviceEnumCallback, void* userDefined);
- typedef NM_ErrorCode (*GetDeviceInfoFunc)(NM_hDeviceList devList, const char* devId, NM_DeviceInfo* info);
+ typedef NM_ErrorCode (*GetOwnedDevicesUUIDsFunc)(NM_hContext ctx, char*** dev_uuids);
+ typedef void (*FreeDeviceArrayFunc)(char*** dev_uuids);
+ typedef NM_ErrorCode (*GetUnownedDevicesUUIDsFunc)(NM_hContext ctx, char*** dev_uuids);
+ typedef NM_ErrorCode (*GetDeviceInfoByIdFunc)(NM_hContext ctx, const char* dev_id, NM_DeviceInfo* info);
+ typedef NM_ErrorCode (*OwnDeviceByIdFunc)(NM_hContext ctx, const char* dev_id);
+ typedef NM_ErrorCode (*UnOwnDeviceByIdFunc)(NM_hContext ctx, const char* dev_id);
typedef void (*FreeDeviceInfoFunc)(NM_DeviceInfo*);
- typedef NM_ErrorCode (*OwnDeviceFunc)(NM_hDeviceList, const char* devId);
- typedef NM_ErrorCode (*UnownDeviceFunc)(NM_hDeviceList dev_list, const char* devId);
typedef NM_ErrorCode (*SubsOnNotificationsFunc)(NM_hContext, NmNotificationCallback, void*);
typedef void (*UnsubsOnNotificationsFunc)(NM_hContext);
typedef NM_ErrorCode (*GetDeviceReportFunc)(NM_hContext, const char* devId, char** report);
GetSessionStateFunc m_nmGetSessionStateFunc;
SubscribeDevStateChangedFunc m_nmSubsDevStateChangedFunc;
UnsubscribeDeviceStateChangedFunc m_nmUnsubsDevStateChangedFunc;
- GetOwnedDevicesFunc m_nmGetOwnedDevFunc;
- FreeDeviceListFunc m_nmFreeDevListFunc;
- GetListSizeFunc m_nmGetListSizeFunc;
- GetUnownedDevicesFunc m_nmGetUnownedDevFunc;
- ResetDeviceListFunc m_nmResetDeviceListFunc;
- DeviceListEnumFunc m_nmDeviceListEnumFunc;
- DeviceListForEachFunc m_nmDeviceListForEachFunc;
- GetDeviceInfoFunc m_nmGetDeviceInfoFunc;
FreeDeviceInfoFunc m_nmFreeDeviceInfoFunc;
- OwnDeviceFunc m_nmOwnDeviceFunc;
- UnownDeviceFunc m_nmUnownDeviceFunc;
SubsOnNotificationsFunc m_nmSubsOnNotifFunc;
UnsubsOnNotificationsFunc m_nmUnsubsOnNotifFunc;
GetDeviceReportFunc m_nmGetDevReportFunc;
GetDevicePolicyFunc m_nmGetDevicePolicyFunc;
SetDevicePolicyFunc m_nmSetDevicePolicyFunc;
GetDeviceAgentsFunc m_nmGetDeviceAgentsFunc;
+ GetOwnedDevicesUUIDsFunc m_nmGetOwnedDeviceUUIDsFunc;
+ GetUnownedDevicesUUIDsFunc m_nmGetUnownedDeviceUUIDsFunc;
+ FreeDeviceArrayFunc m_nmFreeDevArrayFunc;
+ GetDeviceInfoByIdFunc m_nmGetDeviceInfoByIdFunc;
+ OwnDeviceByIdFunc m_nmOwnDeviceByIdFunc;
+ UnOwnDeviceByIdFunc m_nmUnownDeviceByIdFunc;
};
- DeviceList ToDeviceList(NM_hDeviceList& nmList);
+ DeviceList ToDeviceList(char** uuids);
DevicePtr ToDevice(const NM_DeviceInfo* device);
private:
- void FreeCache();
- void FreeDeviceList(NM_hDeviceList* nmList);
ErrorCode SubscribeOnNotifications();
ErrorCode UnsubscribeOnNotifications();
ErrorCode GetPolicy(const std::string& devId, const std::string& agentId, std::string& policy);
private:
ModuleSymbols m_moduleSymbols;
NM_hContext m_context;
- NM_hDeviceList m_ownedDevices;
- NM_hDeviceList m_unownedDevices;
std::vector<NotificationCallback> m_notificationCallbackList;
};
#define NM_GET_DEV_POLICY_FUNC_NAME "NM_getDevicePolicy"
#define NM_SET_DEV_POLICY_FUNC_NAME "NM_setDevicePolicy"
#define NM_GET_DEV_AGENTS_FUNC_NAME "NM_getDeviceAgents"
+#define NM_GET_OWNED_DEV_UUIDS_FUNC_NAME "NM_getOwnedDevicesUUIDs"
+#define NM_FREE_DEV_UUID_ARR_FUNC_NAME "NM_freeDeviceArray"
+#define NM_GET_DEV_INFO_BY_ID_FUNC_NAME "NM_getDeviceInfoEx"
+#define NM_OWN_DEV_BY_ID_FUNC_NAME "NM_ownDeviceEx"
+#define NM_UNOWN_DEV_BY_ID_FUNC_NAME "NM_unOwnDeviceEx"
namespace iotswsec
{
m_nmGetSessionStateFunc(nullptr),
m_nmSubsDevStateChangedFunc(nullptr),
m_nmUnsubsDevStateChangedFunc(nullptr),
- m_nmGetOwnedDevFunc(nullptr),
- m_nmFreeDevListFunc(nullptr),
- m_nmGetListSizeFunc(nullptr),
- m_nmGetUnownedDevFunc(nullptr),
- m_nmResetDeviceListFunc(nullptr),
- m_nmDeviceListEnumFunc(nullptr),
- m_nmDeviceListForEachFunc(nullptr),
- m_nmGetDeviceInfoFunc(nullptr),
m_nmFreeDeviceInfoFunc(nullptr),
- m_nmOwnDeviceFunc(nullptr),
- m_nmUnownDeviceFunc(nullptr),
m_nmSubsOnNotifFunc(nullptr),
m_nmUnsubsOnNotifFunc(nullptr),
m_nmGetDevReportFunc(nullptr),
m_nmFreeCharBufFunc(nullptr),
m_nmGetDevicePolicyFunc(nullptr),
m_nmSetDevicePolicyFunc(nullptr),
- m_nmGetDeviceAgentsFunc(nullptr)
+ m_nmGetDeviceAgentsFunc(nullptr),
+ m_nmGetOwnedDeviceUUIDsFunc(nullptr),
+ m_nmGetUnownedDeviceUUIDsFunc(nullptr),
+ m_nmFreeDevArrayFunc(nullptr),
+ m_nmGetDeviceInfoByIdFunc(nullptr),
+ m_nmOwnDeviceByIdFunc(nullptr),
+ m_nmUnownDeviceByIdFunc(nullptr)
{
if (LoadModule() != ErrorCode::Success)
{
dlsym(this->m_module, NM_SUBS_DEV_ST_CHNG_FUNC_NAME));
m_nmUnsubsDevStateChangedFunc = reinterpret_cast<UnsubscribeDeviceStateChangedFunc>(
dlsym(this->m_module, NM_UNSUBS_DEV_ST_CHNG_FUNC_NAME));
- m_nmGetOwnedDevFunc = reinterpret_cast<GetOwnedDevicesFunc>(
- dlsym(this->m_module, NM_GET_OWNED_DEV_FUNC_NAME));
- m_nmFreeDevListFunc = reinterpret_cast<FreeDeviceListFunc>(
- dlsym(this->m_module, NM_FREE_DEV_LIST_FUNC_NAME));
- m_nmGetListSizeFunc = reinterpret_cast<GetListSizeFunc>(
- dlsym(this->m_module, NM_GET_LIST_SIZE_FUNC_NAME));
- m_nmGetUnownedDevFunc = reinterpret_cast<GetUnownedDevicesFunc>(
- dlsym(this->m_module, NM_GET_UNOWNED_DEV_FUNC_NAME));
- m_nmResetDeviceListFunc = reinterpret_cast<ResetDeviceListFunc>(
- dlsym(this->m_module, NM_RESET_DEV_LIST_FUNC_NAME));
- m_nmDeviceListEnumFunc = reinterpret_cast<DeviceListEnumFunc>(
- dlsym(this->m_module, NM_DEV_LIST_ENUM_FUNC_NAME));
- m_nmDeviceListForEachFunc = reinterpret_cast<DeviceListForEachFunc>(
- dlsym(this->m_module, NM_DEV_LIST_FOREACH_FUNC_NAME));
- m_nmGetDeviceInfoFunc = reinterpret_cast<GetDeviceInfoFunc>(
- dlsym(this->m_module, NM_GET_DEV_INFO_FUNC_NAME));
m_nmFreeDeviceInfoFunc = reinterpret_cast<FreeDeviceInfoFunc>(
dlsym(this->m_module, NM_FREE_DEV_INFO_FUNC_NAME));
- m_nmOwnDeviceFunc = reinterpret_cast<OwnDeviceFunc>(
- dlsym(this->m_module, NM_OWN_DEV_FUNC_NAME));
- m_nmUnownDeviceFunc = reinterpret_cast<UnownDeviceFunc>(
- dlsym(this->m_module, NM_UNOWN_DEV_FUNC_NAME));
m_nmSubsOnNotifFunc = reinterpret_cast<SubsOnNotificationsFunc>(
dlsym(this->m_module, NM_SUBS_NOTIFICATIONS_FUNC_NAME));
m_nmUnsubsOnNotifFunc = reinterpret_cast<UnsubsOnNotificationsFunc>(
dlsym(this->m_module, NM_SET_DEV_POLICY_FUNC_NAME));
m_nmGetDeviceAgentsFunc = reinterpret_cast<GetDeviceAgentsFunc>(
dlsym(this->m_module, NM_GET_DEV_AGENTS_FUNC_NAME));
+ m_nmGetOwnedDeviceUUIDsFunc = reinterpret_cast<GetOwnedDevicesUUIDsFunc>(
+ dlsym(this->m_module, NM_GET_OWNED_DEV_UUIDS_FUNC_NAME));
+ m_nmGetUnownedDeviceUUIDsFunc = reinterpret_cast<GetUnownedDevicesUUIDsFunc>(
+ dlsym(this->m_module, NM_GET_UNOWNED_DEV_FUNC_NAME));
+ m_nmGetDeviceInfoByIdFunc = reinterpret_cast<GetDeviceInfoByIdFunc>(
+ dlsym(this->m_module, NM_GET_DEV_INFO_BY_ID_FUNC_NAME));
+ m_nmOwnDeviceByIdFunc = reinterpret_cast<OwnDeviceByIdFunc>(
+ dlsym(this->m_module, NM_OWN_DEV_BY_ID_FUNC_NAME));
+ m_nmUnownDeviceByIdFunc = reinterpret_cast<UnOwnDeviceByIdFunc>(
+ dlsym(this->m_module, NM_UNOWN_DEV_BY_ID_FUNC_NAME));
+ m_nmFreeDevArrayFunc = reinterpret_cast<FreeDeviceArrayFunc>(
+ dlsym(this->m_module, NM_FREE_DEV_UUID_ARR_FUNC_NAME));
if (!m_nmInitFunc ||
!m_nmCleanUpFunc ||
!m_nmGetSessionStateFunc ||
!m_nmSubsDevStateChangedFunc ||
!m_nmUnsubsDevStateChangedFunc ||
- !m_nmGetOwnedDevFunc ||
- !m_nmFreeDevListFunc ||
- !m_nmGetListSizeFunc ||
- !m_nmGetUnownedDevFunc ||
- !m_nmResetDeviceListFunc ||
- !m_nmDeviceListEnumFunc ||
- !m_nmDeviceListForEachFunc ||
- !m_nmGetDeviceInfoFunc ||
!m_nmFreeDeviceInfoFunc ||
- !m_nmOwnDeviceFunc ||
- !m_nmUnownDeviceFunc ||
!m_nmSubsOnNotifFunc ||
!m_nmUnsubsOnNotifFunc ||
!m_nmGetDevReportFunc ||
!m_nmFreeCharBufFunc ||
!m_nmGetDevicePolicyFunc ||
!m_nmSetDevicePolicyFunc ||
- !m_nmGetDeviceAgentsFunc)
+ !m_nmGetDeviceAgentsFunc ||
+ !m_nmGetOwnedDeviceUUIDsFunc ||
+ !m_nmGetUnownedDeviceUUIDsFunc ||
+ !m_nmGetDeviceInfoByIdFunc ||
+ !m_nmOwnDeviceByIdFunc ||
+ !m_nmUnownDeviceByIdFunc ||
+ !m_nmFreeDevArrayFunc)
{
LOG_ERR("Couldn't load one of the functions due to error: %s", dlerror());
ErrorCode NetworkManager::ModuleSymbols::UnloadModule()
{
if (IsModuleLoaded())
- {
+ {
m_nmInitFunc = nullptr;
m_nmCleanUpFunc = nullptr;
m_nmSignInFunc = nullptr;
m_nmGetSessionStateFunc = nullptr;
m_nmSubsDevStateChangedFunc = nullptr;
m_nmUnsubsDevStateChangedFunc = nullptr;
- m_nmGetOwnedDevFunc = nullptr;
- m_nmFreeDevListFunc = nullptr;
- m_nmGetListSizeFunc = nullptr;
- m_nmGetUnownedDevFunc = nullptr;
- m_nmResetDeviceListFunc = nullptr;
- m_nmDeviceListEnumFunc = nullptr;
- m_nmDeviceListForEachFunc = nullptr;
- m_nmGetDeviceInfoFunc = nullptr;
m_nmFreeDeviceInfoFunc = nullptr;
- m_nmOwnDeviceFunc = nullptr;
- m_nmUnownDeviceFunc = nullptr;
m_nmSubsOnNotifFunc = nullptr;
m_nmUnsubsOnNotifFunc = nullptr;
m_nmGetDevReportFunc = nullptr;
m_nmGetDevicePolicyFunc = nullptr;
m_nmSetDevicePolicyFunc = nullptr;
m_nmGetDeviceAgentsFunc = nullptr;
+ m_nmGetOwnedDeviceUUIDsFunc = nullptr;
+ m_nmGetUnownedDeviceUUIDsFunc = nullptr;
+ m_nmGetDeviceInfoByIdFunc = nullptr;
+ m_nmOwnDeviceByIdFunc = nullptr;
+ m_nmUnownDeviceByIdFunc = nullptr;
+ m_nmFreeDevArrayFunc = nullptr;
if (dlclose(m_module) == 0)
- {
+ {
m_moduleIsLoaded = false;
LOG_DBG("Module was unloaded successfully");
-
- return ErrorCode::Success;
}
else
{
LOG_ERR("Unload module error: %s", dlerror());
+
+ return ErrorCode::LibNotFound;
}
- }
+ }
+ else
+ {
+ LOG_INFO("Module %s is already unloaded", NMLIB_MODULE_NAME);
+ }
- return ErrorCode::LibNotFound;
+ return ErrorCode::Success;
}
NetworkManager::NetworkManager():
m_moduleSymbols(),
m_context(nullptr),
- m_ownedDevices(nullptr),
- m_unownedDevices(nullptr),
m_notificationCallbackList()
{
NM_ErrorCode res;
return ErrorCode::Success;
}
-void NetworkManager::FreeCache()
-{
- FreeDeviceList(&m_ownedDevices);
- FreeDeviceList(&m_unownedDevices);
-}
-
NetworkManager::~NetworkManager()
{
if (m_context)
{
- FreeCache();
UnsubscribeOnNotifications();
m_moduleSymbols.m_nmCleanUpFunc(&m_context);
}
ErrorCode NetworkManager::LogOut()
{
ASSERT_RETURN(m_moduleSymbols.m_nmSignOutFunc, "function isn't loaded", ErrorCode::FunctionNotFound);
- FreeCache();
UnsubscribeOnNotifications();
m_moduleSymbols.m_nmSignOutFunc(m_context);
return target;
}
-DeviceList NetworkManager::ToDeviceList(NM_hDeviceList& nmList)
+DeviceList NetworkManager::ToDeviceList(char** uuids)
{
- ASSERT_RETURN(m_moduleSymbols.m_nmDeviceListEnumFunc, "function isn't loaded", DeviceList());
- ASSERT_RETURN(m_moduleSymbols.m_nmGetDeviceInfoFunc, "function isn't loaded", DeviceList());
- ASSERT_RETURN(m_moduleSymbols.m_nmFreeDeviceInfoFunc, "function isn't loaded", DeviceList());
- ASSERT_RETURN(nmList, "list is nullptr", DeviceList());
-
DeviceList targetList;
- const char* deviceId;
- while ((deviceId = m_moduleSymbols.m_nmDeviceListEnumFunc(nmList)) != NULL_HANDLE)
+ if(!uuids)
{
- NM_DeviceInfo deviceInfo;
+ LOG_INFO("There are no found owned devices");
- NM_ErrorCode res;
+ return targetList;
+ }
+
+ for (std::size_t i = 0; uuids[i]; ++uuids)
+ {
+ DevicePtr target = std::make_shared<Device>();
+ ErrorCode res;
- if ((res = m_moduleSymbols.m_nmGetDeviceInfoFunc(nmList, deviceId, &deviceInfo)) != NM_ErrorCode::EC_OK)
+ std::string currentId(uuids[i]);
+
+ if ((res = GetDeviceInfo(currentId, target)) != ErrorCode::Success)
{
- LOG_ERR("network manager returned: %s", std::to_string(res).c_str());
+ LOG_ERR("couldn't get device info, error: %s", std::to_string(res).c_str());
continue;
}
-
- DevicePtr target = ToDevice(&deviceInfo);
- target->SetId(deviceId);
targetList.push_back(target);
-
- m_moduleSymbols.m_nmFreeDeviceInfoFunc(&deviceInfo);
}
return targetList;
}
-void NetworkManager::FreeDeviceList(NM_hDeviceList* nmList)
-{
- if (!nmList)
- {
- return;
- }
-
- ASSERT_RETURN_NOTHING(m_moduleSymbols.m_nmFreeDevListFunc, "function isn't loaded");
-
- m_moduleSymbols.m_nmFreeDevListFunc(nmList);
- nmList = nullptr;
-}
-
ErrorCode NetworkManager::GetOwnedDeviceList(DeviceList& deviceList)
{
- ASSERT_RETURN(m_moduleSymbols.m_nmGetOwnedDevFunc, "function isn't loaded", ErrorCode::FunctionNotFound);
+ ASSERT_RETURN(m_moduleSymbols.m_nmGetOwnedDeviceUUIDsFunc, "function isn't loaded", ErrorCode::FunctionNotFound);
+ ASSERT_RETURN(m_moduleSymbols.m_nmFreeDevArrayFunc, "function isn't loaded", ErrorCode::FunctionNotFound);
+
NM_ErrorCode res;
- if (m_ownedDevices)
- {
- FreeDeviceList(&m_ownedDevices);
- }
+ char** uuids = nullptr;
- if ((res = m_moduleSymbols.m_nmGetOwnedDevFunc(m_context, &m_ownedDevices)) != NM_ErrorCode::EC_OK)
+ if ((res = m_moduleSymbols.m_nmGetOwnedDeviceUUIDsFunc(m_context, &uuids)) != NM_ErrorCode::EC_OK)
{
LOG_ERR("network manager returned: %s", std::to_string(res).c_str());
return GetCorrespondingErrorCode(res);
}
- deviceList = ToDeviceList(m_ownedDevices);
+ deviceList = ToDeviceList(uuids);
+
+ m_moduleSymbols.m_nmFreeDevArrayFunc(&uuids);
return ErrorCode::Success;
}
ErrorCode NetworkManager::GetUnownedDeviceList(DeviceList& deviceList)
{
- ASSERT_RETURN(m_moduleSymbols.m_nmGetUnownedDevFunc, "function isn't loaded", ErrorCode::FunctionNotFound);
+ ASSERT_RETURN(m_moduleSymbols.m_nmGetUnownedDeviceUUIDsFunc, "function isn't loaded", ErrorCode::FunctionNotFound);
NM_ErrorCode res;
+ char** uuids = nullptr;
- FreeDeviceList(&m_unownedDevices);
-
- if ((res = m_moduleSymbols.m_nmGetUnownedDevFunc(m_context, &m_unownedDevices)) != NM_ErrorCode::EC_OK)
+ if ((res = m_moduleSymbols.m_nmGetUnownedDeviceUUIDsFunc(m_context, &uuids)) != NM_ErrorCode::EC_OK)
{
LOG_ERR("network manager returned: %s", std::to_string(res).c_str());
return GetCorrespondingErrorCode(res);
}
- deviceList = ToDeviceList(m_unownedDevices);
+ LOG_DBG("network manager returned: %s", std::to_string(res).c_str());
+
+ deviceList = ToDeviceList(uuids);
+
+ m_moduleSymbols.m_nmFreeDevArrayFunc(&uuids);
return ErrorCode::Success;
}
ErrorCode NetworkManager::UnownDevice(const std::string& deviceId)
{
- ASSERT_RETURN(m_moduleSymbols.m_nmUnownDeviceFunc, "function isn't loaded", ErrorCode::Error);
+ ASSERT_RETURN(m_moduleSymbols.m_nmUnownDeviceByIdFunc, "function isn't loaded", ErrorCode::Error);
NM_ErrorCode res;
- if ((res = m_moduleSymbols.m_nmUnownDeviceFunc(m_ownedDevices, deviceId.c_str())) != NM_ErrorCode::EC_OK)
+ if ((res = m_moduleSymbols.m_nmUnownDeviceByIdFunc(m_context, deviceId.c_str())) != NM_ErrorCode::EC_OK)
{
LOG_ERR("network manager returned: %s", std::to_string(res).c_str());
ErrorCode NetworkManager::OwnDevice(const std::string& deviceId)
{
- ASSERT_RETURN(m_moduleSymbols.m_nmOwnDeviceFunc, "function isn't loaded", ErrorCode::Error);
+ ASSERT_RETURN(m_moduleSymbols.m_nmOwnDeviceByIdFunc, "function isn't loaded", ErrorCode::Error);
NM_ErrorCode res;
- if ((res = m_moduleSymbols.m_nmOwnDeviceFunc(m_unownedDevices, deviceId.c_str())) != NM_ErrorCode::EC_OK)
+ if ((res = m_moduleSymbols.m_nmOwnDeviceByIdFunc(m_context, deviceId.c_str())) != NM_ErrorCode::EC_OK)
{
LOG_ERR("network manager returned: %s", std::to_string(res).c_str());
ErrorCode NetworkManager::GetDeviceInfo(const std::string& devId, DevicePtr& devInfo)
{
+ ASSERT_RETURN(m_moduleSymbols.m_nmGetDeviceInfoByIdFunc, "function isn't loaded", ErrorCode::Error);
+ ASSERT_RETURN(m_moduleSymbols.m_nmFreeDeviceInfoFunc, "function isn't loaded", ErrorCode::Error);
+
+ if (devId.empty())
+ {
+ return ErrorCode::InvalidArgument;
+ }
+
NM_DeviceInfo deviceInfo;
NM_ErrorCode res;
- if ((res = m_moduleSymbols.m_nmGetDeviceInfoFunc(m_ownedDevices,
- devId.c_str(), &deviceInfo)) != NM_ErrorCode::EC_OK)
+ LOG_DBG("Get device info for device with id: %s", devId.c_str());
+
+ if ((res = m_moduleSymbols.m_nmGetDeviceInfoByIdFunc(m_context, devId.c_str(), &deviceInfo)) != NM_ErrorCode::EC_OK)
{
LOG_ERR("network manager returned: %s", std::to_string(res).c_str());
devInfo = ToDevice(&deviceInfo);
devInfo->SetId(devId);
+ m_moduleSymbols.m_nmFreeDeviceInfoFunc(&deviceInfo);
return ErrorCode::Success;
}
EXPECT_NE(nullptr, module.m_nmSignOutFunc);
EXPECT_NE(nullptr, module.m_nmSubsDevStateChangedFunc);
EXPECT_NE(nullptr, module.m_nmUnsubsDevStateChangedFunc);
- EXPECT_NE(nullptr, module.m_nmGetOwnedDevFunc);
- EXPECT_NE(nullptr, module.m_nmGetListSizeFunc);
- EXPECT_NE(nullptr, module.m_nmGetUnownedDevFunc);
- EXPECT_NE(nullptr, module.m_nmResetDeviceListFunc);
- EXPECT_NE(nullptr, module.m_nmDeviceListEnumFunc);
- EXPECT_NE(nullptr, module.m_nmDeviceListForEachFunc);
- EXPECT_NE(nullptr, module.m_nmGetDeviceInfoFunc);
EXPECT_NE(nullptr, module.m_nmFreeDeviceInfoFunc);
- EXPECT_NE(nullptr, module.m_nmOwnDeviceFunc);
- EXPECT_NE(nullptr, module.m_nmUnownDeviceFunc);
-
}
TEST_F(ModuleLoaderTest, CreateContextTest)
m_loader.m_nmCleanUpFunc(&context);
}
-TEST_F(ModuleLoaderTest, GetOwnedDevicesTest)
+TEST_F(ModuleLoaderTest, GetDeviceInfoTest)
{
NM_hContext context;
ASSERT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmInitFunc(&context));
EXPECT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmSignInFunc(context, "login", "password"));
- NM_hDeviceList devList = nullptr;
-
- EXPECT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmGetOwnedDevFunc(context, &devList));
- EXPECT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmFreeDevListFunc(&devList));
+ char** devList = nullptr;
- m_loader.m_nmSignOutFunc(context);
- m_loader.m_nmCleanUpFunc(&context);
-}
+ ASSERT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmGetOwnedDeviceUUIDsFunc(context, &devList));
-TEST_F(ModuleLoaderTest, DevListEnumTest)
-{
- NM_hContext context;
- ASSERT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmInitFunc(&context));
-
- EXPECT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmSignInFunc(context, "login", "password"));
-
- NM_hDeviceList devList = nullptr;
+ if (devList)
+ {
+ if (*devList)
+ {
+ const char* deviceId = *devList;
- ASSERT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmGetOwnedDevFunc(context, &devList));
+ NM_DeviceInfo deviceInfo;
+ NM_ErrorCode res;
- size_t size = m_loader.m_nmGetListSizeFunc(devList);
+ EXPECT_EQ(NM_ErrorCode::EC_OK, res = m_loader.m_nmGetDeviceInfoByIdFunc(context, deviceId, &deviceInfo));
- std::cout << "size is: " << size << std::endl;
+ std::cout << "network manager returned: " << std::to_string(res) << std::endl;
- if (size > 0)
- {
- EXPECT_TRUE(m_loader.m_nmDeviceListEnumFunc(devList));
+ if (res == NM_ErrorCode::EC_OK)
+ {
+ m_loader.m_nmFreeDeviceInfoFunc(&deviceInfo);
+ }
+ }
}
- EXPECT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmFreeDevListFunc(&devList));
+ m_loader.m_nmFreeDevArrayFunc(&devList);
m_loader.m_nmSignOutFunc(context);
m_loader.m_nmCleanUpFunc(&context);
}
-TEST_F(ModuleLoaderTest, GetDeviceInfoTest)
+TEST_F(ModuleLoaderTest, GetUnownedDevicesTest)
{
NM_hContext context;
ASSERT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmInitFunc(&context));
EXPECT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmSignInFunc(context, "login", "password"));
- NM_hDeviceList devList = nullptr;
-
- ASSERT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmGetOwnedDevFunc(context, &devList));
+ char** devList = nullptr;
- size_t size = m_loader.m_nmGetListSizeFunc(devList);
+ ASSERT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmGetUnownedDeviceUUIDsFunc(context, &devList));
- std::cout << "size is: " << size << std::endl;
-
- if (size > 0)
+ if (devList)
{
- const char* deviceId;
-
- EXPECT_TRUE((deviceId = m_loader.m_nmDeviceListEnumFunc(devList)));
+ if (*devList)
+ {
+ const char* deviceId = *devList;
- NM_DeviceInfo deviceInfo;
- NM_ErrorCode res;
+ NM_DeviceInfo deviceInfo;
+ NM_ErrorCode res;
- EXPECT_EQ(NM_ErrorCode::EC_OK, res = m_loader.m_nmGetDeviceInfoFunc(devList, deviceId, &deviceInfo));
+ EXPECT_EQ(NM_ErrorCode::EC_OK, res = m_loader.m_nmGetDeviceInfoByIdFunc(context, deviceId, &deviceInfo));
- std::cout << "network manager returned: " << std::to_string(res) << std::endl;
+ std::cout << "network manager returned: " << std::to_string(res) << std::endl;
- m_loader.m_nmFreeDeviceInfoFunc(&deviceInfo);
+ if (res == NM_ErrorCode::EC_OK)
+ {
+ m_loader.m_nmFreeDeviceInfoFunc(&deviceInfo);
+ }
+ }
}
- EXPECT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmFreeDevListFunc(&devList));
-
- m_loader.m_nmSignOutFunc(context);
- m_loader.m_nmCleanUpFunc(&context);
-}
-
-TEST_F(ModuleLoaderTest, GetUnownedDevicesTest)
-{
- NM_hContext context;
- ASSERT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmInitFunc(&context));
-
- EXPECT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmSignInFunc(context, "login", "password"));
-
- NM_hDeviceList devList = nullptr;
-
- EXPECT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmGetUnownedDevFunc(context, &devList));
- EXPECT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmFreeDevListFunc(&devList));
+ m_loader.m_nmFreeDevArrayFunc(&devList);
m_loader.m_nmSignOutFunc(context);
m_loader.m_nmCleanUpFunc(&context);
EXPECT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmSignInFunc(context, "login", "password"));
- NM_hDeviceList devList = nullptr;
-
- ASSERT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmGetOwnedDevFunc(context, &devList));
+ char** devList = nullptr;
- size_t size = m_loader.m_nmGetListSizeFunc(devList);
+ ASSERT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmGetOwnedDeviceUUIDsFunc(context, &devList));
- std::cout << "size is: " << size << std::endl;
-
- if (size > 1)
+ if (devList)
{
- const char* deviceId;
- char* reportBuffer = nullptr;
+ if (*devList)
+ {
+ const char* deviceId = *devList;
+ char* reportBuffer = nullptr;
- EXPECT_TRUE((deviceId = m_loader.m_nmDeviceListEnumFunc(devList)));
- EXPECT_TRUE((deviceId = m_loader.m_nmDeviceListEnumFunc(devList)));
- NM_ErrorCode res;
+ NM_ErrorCode res;
- std::cout << "try to get report for device: " << deviceId << std::endl;
+ std::cout << "try to get report for device: " << deviceId << std::endl;
- EXPECT_EQ(NM_ErrorCode::EC_OK, (res = m_loader.m_nmGetDevReportFunc(context, deviceId, &reportBuffer)));
+ EXPECT_EQ(NM_ErrorCode::EC_OK, (res = m_loader.m_nmGetDevReportFunc(context, deviceId, &reportBuffer)));
- std::cout << "network manager returned: " << std::to_string(res) << std::endl;
+ std::cout << "network manager returned: " << std::to_string(res) << std::endl;
- EXPECT_TRUE(reportBuffer);
+ EXPECT_TRUE(reportBuffer);
- if (reportBuffer)
- {
- std::cout << "report: " << reportBuffer << std::endl;
- }
+ if (reportBuffer)
+ {
+ std::cout << "report: " << reportBuffer << std::endl;
+ }
- m_loader.m_nmFreeCharBufFunc(reportBuffer);
+ m_loader.m_nmFreeCharBufFunc(reportBuffer);
+ }
}
- EXPECT_EQ(NM_ErrorCode::EC_OK, m_loader.m_nmFreeDevListFunc(&devList));
+ m_loader.m_nmFreeDevArrayFunc(&devList);
m_loader.m_nmSignOutFunc(context);
m_loader.m_nmCleanUpFunc(&context);