aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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) {