diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2016-10-18 15:19:55 +0200 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2016-10-19 16:40:25 +0200 |
commit | b33580e849bbdc8162135e74c9bd0405da454883 (patch) | |
tree | 2ada95a955647b6683361b6273f6d8d4cab3216f | |
parent | 98a9730783268b01d8f55b8b323bb70fdd964a11 (diff) | |
download | libnitrokey-b33580e849bbdc8162135e74c9bd0405da454883.tar.gz libnitrokey-b33580e849bbdc8162135e74c9bd0405da454883.tar.bz2 |
Code refactoring: removing disambiguity from device constants
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r-- | device.cc | 9 | ||||
-rw-r--r-- | include/device.h | 6 | ||||
-rw-r--r-- | include/device_proto.h | 4 |
3 files changed, 11 insertions, 8 deletions
@@ -13,7 +13,8 @@ using namespace nitrokey::log; Device::Device() : m_vid(0), m_pid(0), - m_retry_count(40), + m_retry_sending_count(3), + m_retry_receiving_count(40), m_retry_timeout(100), mp_devhandle(NULL), last_command_status(0){} @@ -69,7 +70,7 @@ int Device::recv(void *packet) { Loglevel::DEBUG_L2); if (status > 0) break; // success - if (retry_count++ >= m_retry_count) { + if (retry_count++ >= m_retry_receiving_count) { Log::instance()( "Maximum retry count reached" + std::to_string(retry_count), Loglevel::WARNING); @@ -88,7 +89,7 @@ Stick10::Stick10() { m_pid = 0x4108; m_model = DeviceModel::PRO; m_send_receive_delay = 100ms; - m_retry_count = 100; + m_retry_receiving_count = 100; } Stick20::Stick20() { @@ -97,5 +98,5 @@ Stick20::Stick20() { m_retry_timeout = 20ms; m_model = DeviceModel::STORAGE; m_send_receive_delay = 20ms; - m_retry_count = 40; + m_retry_receiving_count = 40; } diff --git a/include/device.h b/include/device.h index 67b739c..34b7a5b 100644 --- a/include/device.h +++ b/include/device.h @@ -38,7 +38,8 @@ public: */ virtual int recv(void *packet); - int get_retry_count() const { return m_retry_count; }; + int get_retry_receiving_count() const { return m_retry_receiving_count; }; + int get_retry_sending_count() const { return m_retry_sending_count; }; std::chrono::milliseconds get_retry_timeout() const { return m_retry_timeout; }; std::chrono::milliseconds get_send_receive_delay() const {return m_send_receive_delay;} @@ -59,7 +60,8 @@ private: * library, there's no way of doing it asynchronously, * hence polling. */ - int m_retry_count; + int m_retry_sending_count; + int m_retry_receiving_count; std::chrono::milliseconds m_retry_timeout; std::chrono::milliseconds m_send_receive_delay; diff --git a/include/device_proto.h b/include/device_proto.h index bf78d29..d64c341 100644 --- a/include/device_proto.h +++ b/include/device_proto.h @@ -219,7 +219,7 @@ namespace nitrokey { if (!outp.isValid()) throw std::runtime_error("Invalid outgoing packet"); int receiving_retry_counter = 0; - int sending_retry_counter = 3; + int sending_retry_counter = dev.get_retry_sending_count(); while (sending_retry_counter-- > 0) { status = dev.send(&outp); if (status <= 0) @@ -230,7 +230,7 @@ namespace nitrokey { std::this_thread::sleep_for(dev.get_send_receive_delay()); // FIXME make checks done in device:recv here - receiving_retry_counter = dev.get_retry_count(); + receiving_retry_counter = dev.get_retry_receiving_count(); while (receiving_retry_counter-- > 0) { status = dev.recv(&resp); |