From 14635f49813df1699569d3b13456ea33955de54b Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sun, 13 Jan 2019 12:04:31 +0100 Subject: Add Device::create static method The method makes it easier to create a std::shared_ptr from a model enum instance. --- device.cc | 11 +++++++++++ libnitrokey/device.h | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/device.cc b/device.cc index 58dc0e5..aabcbfc 100644 --- a/device.cc +++ b/device.cc @@ -209,6 +209,17 @@ std::vector Device::enumerate(){ return res; } +std::shared_ptr Device::create(DeviceModel model) { + switch (model) { + case DeviceModel::PRO: + return std::make_shared(); + case DeviceModel::STORAGE: + return std::make_shared(); + default: + return {}; + } +} + bool Device::could_be_enumerated() { LOG(__FUNCTION__, Loglevel::DEBUG_L2); std::lock_guard lock(mex_dev_com); diff --git a/libnitrokey/device.h b/libnitrokey/device.h index 418d335..eab3888 100644 --- a/libnitrokey/device.h +++ b/libnitrokey/device.h @@ -24,6 +24,7 @@ #include #include "hidapi/hidapi.h" #include +#include #include #include #include "misc.h" @@ -154,6 +155,11 @@ public: */ static std::vector enumerate(); + /** + * Create a Device of the given model. + */ + static std::shared_ptr create(DeviceModel model); + void show_stats(); // ErrorCounters get_stats(){ return m_counters; } -- cgit v1.2.3