diff --git a/api/icsneocpp/error.cpp b/api/icsneocpp/error.cpp index 0adb62e..8f906ab 100644 --- a/api/icsneocpp/error.cpp +++ b/api/icsneocpp/error.cpp @@ -216,12 +216,7 @@ APIError::Severity APIError::SeverityForType(ErrorType type) { switch(type) { // API Warnings case OutputTruncated: - case DeviceCurrentlyOpen: - case DeviceCurrentlyClosed: - case DeviceCurrentlyOnline: - case DeviceCurrentlyOffline: - case DeviceCurrentlyPolling: - case DeviceNotCurrentlyPolling: + // Device Warnings case PollingMessageOverflow: case DeviceFirmwareOutOfDate: @@ -240,6 +235,12 @@ APIError::Severity APIError::SeverityForType(ErrorType type) { case MessageMaxLengthExceeded: // Device Errors + case DeviceCurrentlyOpen: + case DeviceCurrentlyClosed: + case DeviceCurrentlyOnline: + case DeviceCurrentlyOffline: + case DeviceCurrentlyPolling: + case DeviceNotCurrentlyPolling: case NoSerialNumber: case IncorrectSerialNumber: case SettingsReadError: diff --git a/include/icsneo/api/errormanager.h b/include/icsneo/api/errormanager.h index 47de2e3..f23524c 100644 --- a/include/icsneo/api/errormanager.h +++ b/include/icsneo/api/errormanager.h @@ -36,13 +36,14 @@ public: } void add(APIError::ErrorType type) { std::lock_guard lk(mutex); - add_internal(type); + add_internal(APIError::APIError(type)); } void add(APIError::ErrorType type, const Device* forDevice) { std::lock_guard lk(mutex); - add_internal(type, forDevice); + add_internal(APIError::APIError(type, forDevice)); } + void discard(ErrorFilter filter = ErrorFilter()); void setErrorLimit(size_t newLimit) { @@ -92,40 +93,6 @@ private: errors.push_back(error); } } - void add_internal(APIError::ErrorType type) { - // Ensure the error list is at most exactly full (size of errorLimit - 1, leaving room for a potential APIError::TooManyErrors) - enforceLimit(); - - // We are exactly full, either because the list was truncated or because we were simply full before - if(errors.size() == errorLimit - 1) { - // If the error is worth adding - if(APIError::SeverityForType(type) >= lowestCurrentSeverity()) { - discardLeastSevere(1); - errors.emplace_back(type); - } - - errors.push_back(APIError(APIError::TooManyErrors)); - } else { - errors.emplace_back(type); - } - } - void add_internal(APIError::ErrorType type, const Device* forDevice) { - // Ensure the error list is at most exactly full (size of errorLimit - 1, leaving room for a potential APIError::TooManyErrors) - enforceLimit(); - - // We are exactly full, either because the list was truncated or because we were simply full before - if(errors.size() == errorLimit - 1) { - // If the error is worth adding - if(APIError::SeverityForType(type) >= lowestCurrentSeverity()) { - discardLeastSevere(1); - errors.emplace_back(type); - } - - errors.push_back(APIError(APIError::TooManyErrors)); - } else { - errors.emplace_back(type, forDevice); - } - } bool enforceLimit(); // Returns whether the limit enforcement resulted in an overflow