aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-11-03 13:45:53 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2016-11-26 18:56:28 +0100
commit130a33311567a1f0f6a9a2d8707bff20a558eb20 (patch)
tree382228626bd47f64c09abe45f7b58a3c8c396c6c
parent7d943d3e8717ba47af4b53787cc4c29ad6ee2f90 (diff)
downloadlibnitrokey-130a33311567a1f0f6a9a2d8707bff20a558eb20.tar.gz
libnitrokey-130a33311567a1f0f6a9a2d8707bff20a558eb20.tar.bz2
Treat LongOperationException as CommandFailed and handle it transparently
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r--include/LongOperationInProgressException.h10
-rw-r--r--include/device_proto.h15
2 files changed, 13 insertions, 12 deletions
diff --git a/include/LongOperationInProgressException.h b/include/LongOperationInProgressException.h
index 673a218..7f182b0 100644
--- a/include/LongOperationInProgressException.h
+++ b/include/LongOperationInProgressException.h
@@ -5,16 +5,16 @@
#ifndef LIBNITROKEY_LONGOPERATIONINPROGRESSEXCEPTION_H
#define LIBNITROKEY_LONGOPERATIONINPROGRESSEXCEPTION_H
+#include "CommandFailedException.h"
-class LongOperationInProgressException : public std::exception {
+class LongOperationInProgressException : public CommandFailedException {
public:
unsigned char progress_bar_value;
- unsigned char command_id;
- LongOperationInProgressException(unsigned char _command_id, unsigned char _progress_bar_value) {
- command_id = _command_id;
- progress_bar_value = _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){
nitrokey::log::Log::instance()(
std::string("LongOperationInProgressException, progress bar status: ")+
std::to_string(progress_bar_value), nitrokey::log::Loglevel::DEBUG);
diff --git a/include/device_proto.h b/include/device_proto.h
index 187d25c..0953566 100644
--- a/include/device_proto.h
+++ b/include/device_proto.h
@@ -316,21 +316,22 @@ namespace nitrokey {
clear_packet(outp);
if (status <= 0)
- throw std::runtime_error(
+ throw std::runtime_error( //FIXME replace with CriticalErrorException
std::string("Device error while executing command ") +
std::to_string(status));
- if (resp.device_status == static_cast<uint8_t>(stick10::device_status::busy) &&
- static_cast<stick20::device_status>(resp.storage_status.device_status)
- == stick20::device_status::busy_progressbar){
- throw LongOperationInProgressException(resp.command_id, resp.storage_status.progress_bar_value);
- }
-
Log::instance()("Incoming HID packet:", Loglevel::DEBUG);
Log::instance()(static_cast<std::string>(resp), Loglevel::DEBUG);
Log::instance()(std::string("receiving_retry_counter count: ") + std::to_string(receiving_retry_counter),
Loglevel::DEBUG);
+ if (resp.device_status == static_cast<uint8_t>(stick10::device_status::busy) &&
+ static_cast<stick20::device_status>(resp.storage_status.device_status)
+ == stick20::device_status::busy_progressbar){
+ throw LongOperationInProgressException(
+ resp.command_id, resp.device_status, resp.storage_status.progress_bar_value);
+ }
+
if (!resp.isValid()) throw std::runtime_error("Invalid incoming packet");
if (receiving_retry_counter <= 0)
throw std::runtime_error(