Browse Source

don't pollute the global namespace with "using namespace std;" in the header. Adds some comments for documentation.

sync
Roker 7 years ago
parent
commit
8d92ae2efd
  1. 6
      Adapter.cc
  2. 18
      Adapter.hh

6
Adapter.cc

@ -24,8 +24,8 @@ namespace pEp {
throw RuntimeError(status_to_string(status), status); throw RuntimeError(status_to_string(status), status);
} }
RuntimeError::RuntimeError(string _text, PEP_STATUS _status) RuntimeError::RuntimeError(const std::string& _text, PEP_STATUS _status)
: runtime_error(_text.c_str()), text(_text), status(_status) : std::runtime_error(_text.c_str()), text(_text), status(_status)
{ {
} }
@ -90,7 +90,7 @@ namespace pEp {
PEP_SESSION session(session_action action) PEP_SESSION session(session_action action)
{ {
lock_guard<mutex> lock(m); std::lock_guard<mutex> lock(m);
bool in_sync = on_sync_thread(); bool in_sync = on_sync_thread();
thread_local static PEP_SESSION _session = nullptr; thread_local static PEP_SESSION _session = nullptr;

18
Adapter.hh

@ -9,14 +9,17 @@
#include <string> #include <string>
#include <pEp/sync_api.h> #include <pEp/sync_api.h>
using namespace std;
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); void throw_status(PEP_STATUS status);
struct RuntimeError : runtime_error { struct RuntimeError : std::runtime_error {
RuntimeError(string _text, PEP_STATUS _status); RuntimeError(const std::string& _text, PEP_STATUS _status);
string text; std::string text;
PEP_STATUS status; PEP_STATUS status;
}; };
@ -25,10 +28,11 @@ namespace pEp {
messageToSend_t messageToSend, messageToSend_t messageToSend,
notifyHandshake_t notifyHandshake, notifyHandshake_t notifyHandshake,
T *obj = nullptr, T *obj = nullptr,
function< void (T *) > _startup = nullptr, std::function< void (T *) > _startup = nullptr,
function< void (T *) > _shutdown = nullptr std::function< void (T *) > _shutdown = nullptr
); );
// returns 'true' when called from the "sync" thread, 'false' otherwise.
bool on_sync_thread(); bool on_sync_thread();
enum session_action { enum session_action {
@ -37,6 +41,8 @@ namespace pEp {
}; };
PEP_SESSION session(session_action action = init); PEP_SESSION session(session_action action = init);
// injects a NULL event into sync_event_queue to denote sync thread to shutdown,
// and joins & removes the sync thread
void shutdown(); void shutdown();
} }
} }

Loading…
Cancel
Save