aboutsummaryrefslogtreecommitdiff
path: root/NitrokeyManager.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-10-14 13:00:30 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-10-19 16:34:10 +0200
commit48786a730bbbdd75719069e81e620eb916e98be0 (patch)
tree1758108ca7111bab01b9927c6981bd8f901e206f /NitrokeyManager.cc
parent443e50b1a447dee6181aa721fb310060cecd63ae (diff)
downloadlibnitrokey-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.cc12
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) {