aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2017-12-08 10:59:42 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2018-02-28 19:23:27 +0100
commit8bede81660658a3675f4b7f68835ef3a623c696f (patch)
treee1d377ef37a67cc73355464d92440ab3f9df557b
parent47b2406684683bdee02cc79ae0e0d8ce9c5d3320 (diff)
downloadlibnitrokey-8bede81660658a3675f4b7f68835ef3a623c696f.tar.gz
libnitrokey-8bede81660658a3675f4b7f68835ef3a623c696f.tar.bz2
Disconnect all devices before enumerating and discovering ids. Add log.
Disconnection allows rediscovering devices. Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r--NitrokeyManager.cc19
1 files 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<std::string> NitrokeyManager::list_devices_by_cpuID(){
+ //disconnect default device
+ disconnect();
+
std::lock_guard<std::mutex> 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<std::string> res;
auto d = make_shared<Stick20>();
const auto v = d->enumerate();
+ LOGD1("Discovering IDs");
for (auto & p: v){
d = make_shared<Stick20>();
+ 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();
}