aboutsummaryrefslogtreecommitdiff
path: root/device.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2017-01-31 18:15:48 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2017-03-11 15:41:41 +0100
commitd69cf0b866fa3cc5afda2bb1a321a900520fbcc1 (patch)
tree50f0e9e28c7b5dae8a006695d8f8a67a90644988 /device.cc
parent0503db5b47f247568b78504fa781e083e108eab9 (diff)
downloadlibnitrokey-d69cf0b866fa3cc5afda2bb1a321a900520fbcc1.tar.gz
libnitrokey-d69cf0b866fa3cc5afda2bb1a321a900520fbcc1.tar.bz2
Add method for checking is the device listed as connected in OS
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'device.cc')
-rw-r--r--device.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/device.cc b/device.cc
index 532ba2e..42c6883 100644
--- a/device.cc
+++ b/device.cc
@@ -106,6 +106,24 @@ int Device::recv(void *packet) {
return status;
}
+bool Device::is_connected() {
+ Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2);
+ std::lock_guard<std::mutex> lock(mex_dev_com);
+ if (mp_devhandle==nullptr){
+ return false;
+ }
+ auto pInfo = hid_enumerate(m_vid, m_pid);
+ if (pInfo != nullptr){
+ hid_free_enumeration(pInfo);
+ return true;
+ }
+ return false;
+
+// alternative:
+// unsigned char buf[1];
+// return hid_read_timeout(mp_devhandle, buf, sizeof(buf), 20) != -1;
+}
+
Stick10::Stick10():
Device(0x20a0, 0x4108, DeviceModel::PRO, 100ms, 20, 100ms)
{}