diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2016-08-05 19:50:46 +0200 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2016-08-05 20:32:45 +0200 |
commit | e9c165399bc87e9d283845efdd2d667061b1e323 (patch) | |
tree | 8ce834d70805fad5bde2ed8a2aec3b9beba3b37d /NitrokeyManager.cc | |
parent | 2675570622b808aec77be240b4663e29598049ef (diff) | |
download | libnitrokey-e9c165399bc87e9d283845efdd2d667061b1e323.tar.gz libnitrokey-e9c165399bc87e9d283845efdd2d667061b1e323.tar.bz2 |
Autodetect inserted stick and connect to it
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'NitrokeyManager.cc')
-rw-r--r-- | NitrokeyManager.cc | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index ed9c7b4..79efc49 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -1,5 +1,6 @@ #include <cassert> #include <cstring> +#include <iostream> #include "include/NitrokeyManager.h" namespace nitrokey{ @@ -35,7 +36,24 @@ namespace nitrokey{ NitrokeyManager::NitrokeyManager(): device(nullptr) { set_debug(true); } - NitrokeyManager::~NitrokeyManager() {delete _instance; delete device;} + NitrokeyManager::~NitrokeyManager() { + delete device; + } + + bool NitrokeyManager::connect() { + device = nullptr; + vector<Device*> devices = { new Stick10(), new Stick20() }; + for( auto d : devices ){ + if (device != nullptr){ + delete d; + } + if (device == nullptr && d->connect()){ + device = d; + } + } + return device != nullptr; + } + bool NitrokeyManager::connect(const char *device_model) { switch (device_model[0]){ |