|
@ -12,6 +12,7 @@ using namespace std; |
|
|
namespace pEp { |
|
|
namespace pEp { |
|
|
void throw_status(PEP_STATUS status) |
|
|
void throw_status(PEP_STATUS status) |
|
|
{ |
|
|
{ |
|
|
|
|
|
pEpLog("called"); |
|
|
if (status == PEP_STATUS_OK) |
|
|
if (status == PEP_STATUS_OK) |
|
|
return; |
|
|
return; |
|
|
if (status >= 0x400 && status <= 0x4ff) |
|
|
if (status >= 0x400 && status <= 0x4ff) |
|
@ -28,7 +29,7 @@ namespace pEp { |
|
|
RuntimeError::RuntimeError(const std::string& _text, PEP_STATUS _status) |
|
|
RuntimeError::RuntimeError(const std::string& _text, PEP_STATUS _status) |
|
|
: std::runtime_error(_text.c_str()), text(_text), status(_status) |
|
|
: std::runtime_error(_text.c_str()), text(_text), status(_status) |
|
|
{ |
|
|
{ |
|
|
|
|
|
pEpLog("called"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
namespace Adapter { |
|
|
namespace Adapter { |
|
@ -36,18 +37,19 @@ namespace pEp { |
|
|
notifyHandshake_t _notifyHandshake = nullptr; |
|
|
notifyHandshake_t _notifyHandshake = nullptr; |
|
|
std::thread *_sync_thread = nullptr; |
|
|
std::thread *_sync_thread = nullptr; |
|
|
|
|
|
|
|
|
::utility::locked_queue< SYNC_EVENT, ::free_Sync_event > q; |
|
|
::utility::locked_queue< SYNC_EVENT, ::free_Sync_event > sync_q; |
|
|
std::mutex m; |
|
|
std::mutex m; |
|
|
|
|
|
|
|
|
int _inject_sync_event(SYNC_EVENT ev, void *management) |
|
|
int _inject_sync_event(SYNC_EVENT ev, void *management) |
|
|
{ |
|
|
{ |
|
|
|
|
|
pEpLog("called"); |
|
|
try { |
|
|
try { |
|
|
if (ev == nullptr) { |
|
|
if (ev == nullptr) { |
|
|
q.clear(); |
|
|
sync_q.clear(); |
|
|
q.push_back(ev); |
|
|
sync_q.push_back(ev); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
q.push_front(ev); |
|
|
sync_q.push_front(ev); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
catch (exception&) { |
|
|
catch (exception&) { |
|
@ -61,7 +63,7 @@ namespace pEp { |
|
|
delete _sync_thread; |
|
|
delete _sync_thread; |
|
|
_sync_thread = nullptr; |
|
|
_sync_thread = nullptr; |
|
|
pEpLog("...thread joined"); |
|
|
pEpLog("...thread joined"); |
|
|
q.clear(); |
|
|
sync_q.clear(); |
|
|
} else { |
|
|
} else { |
|
|
//FATAL
|
|
|
//FATAL
|
|
|
pEpLog("FATAL: sync thread not joinable/detached"); |
|
|
pEpLog("FATAL: sync thread not joinable/detached"); |
|
@ -74,8 +76,9 @@ namespace pEp { |
|
|
// threshold: max waiting time in seconds
|
|
|
// threshold: max waiting time in seconds
|
|
|
SYNC_EVENT _retrieve_next_sync_event(void *management, unsigned threshold) |
|
|
SYNC_EVENT _retrieve_next_sync_event(void *management, unsigned threshold) |
|
|
{ |
|
|
{ |
|
|
|
|
|
pEpLog("called"); |
|
|
SYNC_EVENT syncEvent = nullptr; |
|
|
SYNC_EVENT syncEvent = nullptr; |
|
|
const bool success = q.try_pop_front(syncEvent, std::chrono::seconds(threshold)); |
|
|
const bool success = sync_q.try_pop_front(syncEvent, std::chrono::seconds(threshold)); |
|
|
|
|
|
|
|
|
if (!success) |
|
|
if (!success) |
|
|
return new_sync_timeout_event(); |
|
|
return new_sync_timeout_event(); |
|
@ -85,6 +88,7 @@ namespace pEp { |
|
|
|
|
|
|
|
|
bool on_sync_thread() |
|
|
bool on_sync_thread() |
|
|
{ |
|
|
{ |
|
|
|
|
|
pEpLog("called"); |
|
|
if (_sync_thread && _sync_thread->get_id() == this_thread::get_id()) |
|
|
if (_sync_thread && _sync_thread->get_id() == this_thread::get_id()) |
|
|
return true; |
|
|
return true; |
|
|
else |
|
|
else |
|
@ -93,6 +97,7 @@ namespace pEp { |
|
|
|
|
|
|
|
|
PEP_SESSION session(session_action action) |
|
|
PEP_SESSION session(session_action action) |
|
|
{ |
|
|
{ |
|
|
|
|
|
pEpLog("called"); |
|
|
std::lock_guard<mutex> lock(m); |
|
|
std::lock_guard<mutex> lock(m); |
|
|
bool in_sync = on_sync_thread(); |
|
|
bool in_sync = on_sync_thread(); |
|
|
|
|
|
|
|
@ -131,6 +136,7 @@ namespace pEp { |
|
|
|
|
|
|
|
|
bool is_sync_running() |
|
|
bool is_sync_running() |
|
|
{ |
|
|
{ |
|
|
|
|
|
pEpLog("called"); |
|
|
return _sync_thread != nullptr; |
|
|
return _sync_thread != nullptr; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|