From 8bede81660658a3675f4b7f68835ef3a623c696f Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 8 Dec 2017 10:59:42 +0100 Subject: Disconnect all devices before enumerating and discovering ids. Add log. Disconnection allows rediscovering devices. Signed-off-by: Szczepan Zalega --- NitrokeyManager.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index e3e1730..b3c92a1 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -113,13 +113,25 @@ using nitrokey::misc::strcpyT; } std::vector NitrokeyManager::list_devices_by_cpuID(){ + //disconnect default device + disconnect(); + std::lock_guard lock(mex_dev_com_manager); + LOGD1("Disconnecting registered devices"); + for (auto & kv : connected_devices_byID){ + if (kv.second != nullptr) + kv.second->disconnect(); + } + connected_devices_byID.clear(); + LOGD1("Enumerating devices"); std::vector res; auto d = make_shared(); const auto v = d->enumerate(); + LOGD1("Discovering IDs"); for (auto & p: v){ d = make_shared(); + LOGD1( std::string("Found: ") + p ); d->set_path(p); try{ if (d->connect()){ @@ -131,13 +143,13 @@ using nitrokey::misc::strcpyT; auto id = std::to_string(sc_id) + ":" + std::to_string(sd_id); connected_devices_byID[id] = d; res.push_back(id); + LOGD1( std::string("Found: ") + p + " => " + id); } else{ - std::cout << "Could not connect to: " + p << std::endl; + LOGD1( std::string("Could not connect to: ") + p); } } catch (const DeviceCommunicationException &e){ - //ignore - std::cout << p << ": " << " Exception encountered" << std::endl; + LOGD1( std::string("Exception encountered: ") + p); } } return res; @@ -157,6 +169,7 @@ using nitrokey::misc::strcpyT; auto d = connected_devices_byID[id]; device = d; + //validate connection try{ get_status(); } -- cgit v1.2.3