Browse Source

move err-handling code to bottom

should go into own module later
pull/15/head
heck 2 years ago
parent
commit
7b1f8eb90a
  1. 60
      src/Adapter.cc
  2. 23
      src/Adapter.hh

60
src/Adapter.cc

@ -14,36 +14,6 @@ using namespace std;
thread_local pEp::Adapter::Session pEp::Adapter::session{}; thread_local pEp::Adapter::Session pEp::Adapter::session{};
namespace pEp { 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 { namespace Adapter {
std::thread _sync_thread; std::thread _sync_thread;
::utility::locked_queue<SYNC_EVENT, ::free_Sync_event> sync_evt_q; ::utility::locked_queue<SYNC_EVENT, ::free_Sync_event> sync_evt_q;
@ -243,4 +213,34 @@ namespace pEp {
return !ev; return !ev;
} }
} // namespace Adapter } // 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 } // namespace pEp

23
src/Adapter.hh

@ -14,18 +14,6 @@
#include "callback_dispatcher.hh" #include "callback_dispatcher.hh"
namespace pEp { 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 { namespace Adapter {
// public // public
enum class SyncModes enum class SyncModes
@ -149,6 +137,17 @@ namespace pEp {
bool is_sync_running(); bool is_sync_running();
bool in_shutdown(); bool in_shutdown();
} // namespace Adapter } // 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 } // namespace pEp
#include "Adapter.hxx" #include "Adapter.hxx"

Loading…
Cancel
Save