Skip to content

Commit

Permalink
Refactor LongOperationInProgressException
Browse files Browse the repository at this point in the history
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 Nitrokey#170.
  • Loading branch information
robinkrahl committed Apr 2, 2020
1 parent 6100df4 commit b9313f3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
1 change: 1 addition & 0 deletions libnitrokey/DeviceCommunicationExceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 7 additions & 8 deletions libnitrokey/LongOperationInProgressException.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;};
};


Expand Down
3 changes: 1 addition & 2 deletions libnitrokey/device_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit b9313f3

Please sign in to comment.