diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2016-10-14 13:00:30 +0200 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2016-10-19 16:34:10 +0200 |
commit | 48786a730bbbdd75719069e81e620eb916e98be0 (patch) | |
tree | 1758108ca7111bab01b9927c6981bd8f901e206f /NitrokeyManager.cc | |
parent | 443e50b1a447dee6181aa721fb310060cecd63ae (diff) | |
download | libnitrokey-48786a730bbbdd75719069e81e620eb916e98be0.tar.gz libnitrokey-48786a730bbbdd75719069e81e620eb916e98be0.tar.bz2 |
C/C++ API: make connection and disconnection more robust
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'NitrokeyManager.cc')
-rw-r--r-- | NitrokeyManager.cc | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 872ebb4..e5d912d 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -45,7 +45,7 @@ namespace nitrokey{ } bool NitrokeyManager::connect() { - device = nullptr; + this->disconnect(); vector< shared_ptr<Device> > devices = { make_shared<Stick10>(), make_shared<Stick20>() }; for( auto & d : devices ){ if (d->connect()){ @@ -57,7 +57,8 @@ namespace nitrokey{ bool NitrokeyManager::connect(const char *device_model) { - switch (device_model[0]){ + this->disconnect(); + switch (device_model[0]){ case 'P': device = make_shared<Stick10>(); break; @@ -78,7 +79,12 @@ namespace nitrokey{ } bool NitrokeyManager::disconnect() { - return device->disconnect(); + if (device == nullptr){ + return false; + } + const auto res = device->disconnect(); + device = nullptr; + return res; } void NitrokeyManager::set_debug(bool state) { |