From 7b1f8eb90a0cba822fcc3aebc780748d3ce6d8dd Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 20 Jan 2023 16:15:43 +0530 Subject: [PATCH] move err-handling code to bottom should go into own module later --- src/Adapter.cc | 60 +++++++++++++++++++++++++------------------------- src/Adapter.hh | 23 +++++++++---------- 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/src/Adapter.cc b/src/Adapter.cc index f91377d..d15372e 100644 --- a/src/Adapter.cc +++ b/src/Adapter.cc @@ -14,36 +14,6 @@ using namespace std; thread_local pEp::Adapter::Session pEp::Adapter::session{}; namespace pEp { - void throw_status(::PEP_STATUS status) - { - if (status == ::PEP_STATUS_OK) { - return; - } - if (status == ::PEP_KEY_IMPORTED) { - return; - } - if (status >= 0x400 && status <= 0x4ff) { - return; - } - if (status == ::PEP_STATEMACHINE_CANNOT_SEND) { - return; - } - if (status == ::PEP_OUT_OF_MEMORY) { - throw bad_alloc(); - } - if (status == ::PEP_ILLEGAL_VALUE) { - throw invalid_argument("illegal value"); - } - - string _status = status_to_string(status); - throw RuntimeError(_status, status); - } - - RuntimeError::RuntimeError(const std::string &_text, ::PEP_STATUS _status) : - std::runtime_error(_text.c_str()), text(_text), status(_status) - { - } - namespace Adapter { std::thread _sync_thread; ::utility::locked_queue sync_evt_q; @@ -243,4 +213,34 @@ namespace pEp { return !ev; } } // namespace Adapter + + void throw_status(::PEP_STATUS status) + { + if (status == ::PEP_STATUS_OK) { + return; + } + if (status == ::PEP_KEY_IMPORTED) { + return; + } + if (status >= 0x400 && status <= 0x4ff) { + return; + } + if (status == ::PEP_STATEMACHINE_CANNOT_SEND) { + return; + } + if (status == ::PEP_OUT_OF_MEMORY) { + throw bad_alloc(); + } + if (status == ::PEP_ILLEGAL_VALUE) { + throw invalid_argument("illegal value"); + } + + string _status = status_to_string(status); + throw RuntimeError(_status, status); + } + + RuntimeError::RuntimeError(const std::string &_text, ::PEP_STATUS _status) : + std::runtime_error(_text.c_str()), text(_text), status(_status) + { + } } // namespace pEp diff --git a/src/Adapter.hh b/src/Adapter.hh index 338a716..ccaae8c 100644 --- a/src/Adapter.hh +++ b/src/Adapter.hh @@ -14,18 +14,6 @@ #include "callback_dispatcher.hh" namespace pEp { - - // throws std::bad_alloc if status==PEP_OUT_OF_MEMORY, - // throws std::invalid_argument if status==PEP_ILLEGAL_VALUE, - // throws RuntimeError when 'status' represents another exceptional value. - void throw_status(::PEP_STATUS status); - - struct RuntimeError : std::runtime_error { - RuntimeError(const std::string &_text, ::PEP_STATUS _status); - std::string text; - ::PEP_STATUS status; - }; - namespace Adapter { // public enum class SyncModes @@ -149,6 +137,17 @@ namespace pEp { bool is_sync_running(); bool in_shutdown(); } // namespace Adapter + + // throws std::bad_alloc if status==PEP_OUT_OF_MEMORY, + // throws std::invalid_argument if status==PEP_ILLEGAL_VALUE, + // throws RuntimeError when 'status' represents another exceptional value. + void throw_status(::PEP_STATUS status); + + struct RuntimeError : std::runtime_error { + RuntimeError(const std::string &_text, ::PEP_STATUS _status); + std::string text; + ::PEP_STATUS status; + }; } // namespace pEp #include "Adapter.hxx"