diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2018-02-16 15:17:47 +0100 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2018-02-28 20:07:14 +0100 |
commit | 38c3b4c58e6c6b86d6241183be1814bac2e037d2 (patch) | |
tree | 2f5dd6ea25a64f446133c48209ceb53fd4615d71 /NitrokeyManager.cc | |
parent | d6ae8192be443749fcd1f593db0f9be4d039da93 (diff) | |
download | libnitrokey-38c3b4c58e6c6b86d6241183be1814bac2e037d2.tar.gz libnitrokey-38c3b4c58e6c6b86d6241183be1814bac2e037d2.tar.bz2 |
Log current device ID
Allow logger to set global prefix
Used to indicate current device
Store USB path when used to connection as well
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'NitrokeyManager.cc')
-rw-r--r-- | NitrokeyManager.cc | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 162ad93..f2518b1 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -171,10 +171,14 @@ using nitrokey::misc::strcpyT; std::lock_guard<std::mutex> lock(mex_dev_com_manager); auto position = connected_devices_byID.find(id); - if (position == connected_devices_byID.end()) return false; + if (position == connected_devices_byID.end()) { + LOGD1(std::string("Could not find device ")+id); + return false; + } auto d = connected_devices_byID[id]; device = d; + current_device_id = id; //validate connection try{ @@ -185,10 +189,13 @@ using nitrokey::misc::strcpyT; } catch (const DeviceCommunicationException &){ d->disconnect(); + current_device_id = ""; connected_devices_byID[id] = nullptr; connected_devices_byID.erase(position); return false; } + nitrokey::log::Log::setPrefix(id); + LOGD1("Device successfully changed"); return true; } @@ -221,6 +228,9 @@ using nitrokey::misc::strcpyT; } device = p; //previous device will be disconnected automatically + current_device_id = path; + nitrokey::log::Log::setPrefix(path); + LOGD1("Device successfully changed"); return true; } @@ -1105,5 +1115,9 @@ using nitrokey::misc::strcpyT; return data.data().SD_Card_Size_u8; } + const string NitrokeyManager::get_current_device_id() const { + return current_device_id; + } + } |