From b9313f35da53db5db26f700cf61b1eea4b364c14 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Thu, 2 Apr 2020 17:04:51 +0200 Subject: [PATCH] Refactor LongOperationInProgressException This patch changes LongOperationInProgressException to derive from DeviceCommunicationException. This makes it easier to use the C API as the exception now has a unique numerical identifier. Fixes #170. --- libnitrokey/DeviceCommunicationExceptions.h | 1 + libnitrokey/LongOperationInProgressException.h | 15 +++++++-------- libnitrokey/device_proto.h | 3 +-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/libnitrokey/DeviceCommunicationExceptions.h b/libnitrokey/DeviceCommunicationExceptions.h index f710d0b1..caecab06 100644 --- a/libnitrokey/DeviceCommunicationExceptions.h +++ b/libnitrokey/DeviceCommunicationExceptions.h @@ -69,5 +69,6 @@ class InvalidCRCReceived: public DeviceReceivingFailure { uint8_t getType() const {return 5;}; }; +// LongOperationInProgressException with type 6, see LongOperationInProgressException.h #endif //LIBNITROKEY_DEVICECOMMUNICATIONEXCEPTIONS_H diff --git a/libnitrokey/LongOperationInProgressException.h b/libnitrokey/LongOperationInProgressException.h index 865d6b58..6fe36269 100644 --- a/libnitrokey/LongOperationInProgressException.h +++ b/libnitrokey/LongOperationInProgressException.h @@ -22,23 +22,22 @@ #ifndef LIBNITROKEY_LONGOPERATIONINPROGRESSEXCEPTION_H #define LIBNITROKEY_LONGOPERATIONINPROGRESSEXCEPTION_H -#include "CommandFailedException.h" +#include "DeviceCommunicationExceptions.h" -class LongOperationInProgressException : public CommandFailedException { +class LongOperationInProgressException : public DeviceCommunicationException { public: unsigned char progress_bar_value; - LongOperationInProgressException( - unsigned char _command_id, uint8_t last_command_status, unsigned char _progress_bar_value) - : CommandFailedException(_command_id, last_command_status), progress_bar_value(_progress_bar_value){ + LongOperationInProgressException(unsigned char _progress_bar_value) + : DeviceCommunicationException("Device returned busy status with long operation in progress"), + progress_bar_value(_progress_bar_value){ LOG( std::string("LongOperationInProgressException, progress bar status: ")+ std::to_string(progress_bar_value), nitrokey::log::Loglevel::DEBUG); } - virtual const char *what() const throw() { - return "Device returned busy status with long operation in progress"; - } + + uint8_t getType() const {return 6;}; }; diff --git a/libnitrokey/device_proto.h b/libnitrokey/device_proto.h index 45a6c164..4f3b2266 100644 --- a/libnitrokey/device_proto.h +++ b/libnitrokey/device_proto.h @@ -439,8 +439,7 @@ namespace nitrokey { == stick20::device_status::busy_progressbar){ dev->m_counters.busy_progressbar++; LOG(std::string("Throw: Long operation in progress exception"), Loglevel::DEBUG_L1); - throw LongOperationInProgressException( - resp.command_id, resp.device_status, resp.storage_status.progress_bar_value); + throw LongOperationInProgressException(resp.storage_status.progress_bar_value); } if (!resp.isValid()) {