aboutsummaryrefslogtreecommitdiff
path: root/NitrokeyManager.cc
diff options
context:
space:
mode:
Diffstat (limited to 'NitrokeyManager.cc')
-rw-r--r--NitrokeyManager.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index d563b26..da5f61a 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -81,6 +81,11 @@ using nitrokey::misc::strcpyT;
set_debug(true);
}
NitrokeyManager::~NitrokeyManager() {
+ for (auto d : connected_devices){
+ if (d.second == nullptr) continue;
+ d.second->disconnect();
+ connected_devices[d.first] = nullptr;
+ }
}
bool NitrokeyManager::set_current_device_speed(int retry_delay, int send_receive_delay){
@@ -98,6 +103,31 @@ using nitrokey::misc::strcpyT;
return true;
}
+ std::vector<std::string> NitrokeyManager::list_devices(){
+ auto p = make_shared<Stick20>();
+ return p->enumerate(); // make static
+ }
+
+ bool NitrokeyManager::connect_with_path(std::string path) {
+ std::lock_guard<std::mutex> lock(mex_dev_com_manager);
+
+ if(connected_devices.find(path) != connected_devices.end()
+ && connected_devices[path] != nullptr) {
+ device = connected_devices[path];
+ return true;
+ }
+
+
+ auto p = make_shared<Stick20>();
+ p->set_path(path);
+
+ if(!p->connect()) return false;
+
+ connected_devices [path] = p;
+ device = p;
+ return true;
+ }
+
bool NitrokeyManager::connect() {
std::lock_guard<std::mutex> lock(mex_dev_com_manager);
vector< shared_ptr<Device> > devices = { make_shared<Stick10>(), make_shared<Stick20>() };