diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2017-12-04 16:29:56 +0100 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2018-02-28 19:23:04 +0100 |
commit | 2faa8f6782a2e6294ed8849048a281d12d60da1c (patch) | |
tree | 0e8947f40697da905278c44338f948ce5fa2b3c7 /NitrokeyManager.cc | |
parent | d5486ba77235a874245fbee07a75cea89fa59ea2 (diff) | |
download | libnitrokey-2faa8f6782a2e6294ed8849048a281d12d60da1c.tar.gz libnitrokey-2faa8f6782a2e6294ed8849048a281d12d60da1c.tar.bz2 |
Initial support for multiple devices with C++ and test
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'NitrokeyManager.cc')
-rw-r--r-- | NitrokeyManager.cc | 30 |
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>() }; |