summaryrefslogtreecommitdiff
path: root/device.cc
diff options
context:
space:
mode:
authorRobin Krahl <me@robin-krahl.de>2019-01-13 12:04:22 +0100
committerRobin Krahl <me@robin-krahl.de>2019-01-13 13:26:12 +0100
commit1751759356bd64cc78f8f71543c3edd5cdce8376 (patch)
tree850e2af876151c5ae2df96c31ea15a333002cd6b /device.cc
parent6c52c50d59eafa5acc7ae650695f199b7a014841 (diff)
downloadlibnitrokey-1751759356bd64cc78f8f71543c3edd5cdce8376.tar.gz
libnitrokey-1751759356bd64cc78f8f71543c3edd5cdce8376.tar.bz2
Make Device::enumerate static
Device::enumerate does not need any instance data, therefore it is made static. Note that this not only changes the public API by making the method static. We also return all connected Nitrokey devices instead of only Storage devices. The NitrokeyManager method list_devices_by_cpuID is changed to check the device type so that they still only return Storage devices. The list_device method now returns both Storage and Pro devices.
Diffstat (limited to 'device.cc')
-rw-r--r--device.cc15
1 files changed, 8 insertions, 7 deletions
diff --git a/device.cc b/device.cc
index d3f6e09..58dc0e5 100644
--- a/device.cc
+++ b/device.cc
@@ -188,16 +188,17 @@ int Device::recv(void *packet) {
}
std::vector<DeviceInfo> Device::enumerate(){
- //TODO make static
- auto pInfo = hid_enumerate(m_vid, m_pid);
+ auto pInfo = hid_enumerate(NITROKEY_VID, 0);
auto pInfo_ = pInfo;
std::vector<DeviceInfo> res;
while (pInfo != nullptr){
- std::string path(pInfo->path);
- std::wstring serialNumber(pInfo->serial_number);
- auto deviceModel = this->get_device_model();
- DeviceInfo info = { deviceModel, path, serialNumber };
- res.push_back(info);
+ auto deviceModel = product_id_to_model(pInfo->product_id);
+ if (deviceModel.has_value()) {
+ std::string path(pInfo->path);
+ std::wstring serialNumber(pInfo->serial_number);
+ DeviceInfo info = { deviceModel.value(), path, serialNumber };
+ res.push_back(info);
+ }
pInfo = pInfo->next;
}