From 45a0b1cecde0eeecf8b8be75ec24d1ecc3ad884f Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Wed, 4 Apr 2018 23:56:31 +0200 Subject: Add a NitrokeyManager::connect overload for enum Identifying the model to connect to by the first character of a string is not intuitive. This patch adds an overload for the connect function that accepts a device::DeviceModel enum value, providing a cleaner interface. --- NitrokeyManager.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'NitrokeyManager.cc') diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index db0c0a9..48196a9 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -273,6 +273,21 @@ using nitrokey::misc::strcpyT; return device->connect(); } + bool NitrokeyManager::connect(device::DeviceModel device_model) { + const char *model_string; + switch (device_model) { + case device::DeviceModel::PRO: + model_string = "P"; + break; + case device::DeviceModel::STORAGE: + model_string = "S"; + break; + default: + throw std::runtime_error("Unknown model"); + } + return connect(model_string); + } + shared_ptr NitrokeyManager::instance() { static std::mutex mutex; std::lock_guard lock(mutex); -- cgit v1.2.1