diff --git a/src/Adapter.cc b/src/Adapter.cc index 23cd2fe..30fe078 100644 --- a/src/Adapter.cc +++ b/src/Adapter.cc @@ -207,14 +207,23 @@ namespace pEp { _inject_sync_event(nullptr, nullptr); } + void start_sync() + { + startup( + &callback_dispatcher, + &::pEp::CallbackDispatcher::on_startup, + &::pEp::CallbackDispatcher::on_shutdown); + } + // public - void shutdown() + void stop_sync() { pEpLog("called"); if (_sync_thread.joinable()) { pEpLog("sync_is_running - injecting null event"); inject_sync_shutdown(); _sync_thread.join(); + pEp::callback_dispatcher.notifyHandshake(nullptr, nullptr, SYNC_NOTIFY_STOP); } } diff --git a/src/Adapter.hh b/src/Adapter.hh index 41c88b7..3f6f2b9 100644 --- a/src/Adapter.hh +++ b/src/Adapter.hh @@ -47,6 +47,8 @@ namespace pEp { ::PEP_STATUS _ensure_passphrase(::PEP_SESSION session, const char *fpr); + void start_sync(); + template void startup( messageToSend_t messageToSend, @@ -84,7 +86,7 @@ namespace pEp { // injects a NULL event into sync_event_queue to denote sync thread to // shutdown, and joins & removes the sync thread - void shutdown(); + void stop_sync(); bool is_sync_running(); bool in_shutdown(); diff --git a/src/callback_dispatcher.cc b/src/callback_dispatcher.cc index 7a50dbc..5cc7491 100644 --- a/src/callback_dispatcher.cc +++ b/src/callback_dispatcher.cc @@ -5,6 +5,7 @@ #include "passphrase_cache.hh" #include #include +#include "Adapter.hh" pEp::CallbackDispatcher pEp::callback_dispatcher; @@ -51,7 +52,7 @@ namespace pEp { } if (targets.empty()) { - stop_sync(); + Adapter::stop_sync(); } } @@ -73,39 +74,6 @@ namespace pEp { } } - void CallbackDispatcher::start_sync() - { - pEpLog("called"); - callback_dispatcher.semaphore.go(); - - pEp::Adapter::startup( - CallbackDispatcher::messageToSend, - CallbackDispatcher::notifyHandshake, - &callback_dispatcher, - &CallbackDispatcher::on_startup, - &CallbackDispatcher::on_shutdown); - - pEpLog("all targets signal: SYNC_NOTIFY_START"); - for (auto target : callback_dispatcher.targets) { - if (target.notifyHandshake) { - target.notifyHandshake(nullptr, nullptr, SYNC_NOTIFY_START); - } - } - } - - void CallbackDispatcher::stop_sync() - { - callback_dispatcher.semaphore.stop(); - Adapter::shutdown(); - callback_dispatcher.semaphore.go(); - - for (auto target : callback_dispatcher.targets) { - if (target.notifyHandshake) { - target.notifyHandshake(nullptr, nullptr, SYNC_NOTIFY_STOP); - } - } - } - PEP_STATUS CallbackDispatcher::_messageToSend(::message *msg) { if (Adapter::on_sync_thread() && !msg) { diff --git a/src/callback_dispatcher.hh b/src/callback_dispatcher.hh index 5a75e29..8dfd272 100644 --- a/src/callback_dispatcher.hh +++ b/src/callback_dispatcher.hh @@ -7,10 +7,10 @@ #include #include #include -#include "Adapter.hh" + #include "Semaphore.hh" #include "passphrase_cache.hh" - +#include namespace pEp { // use this class when implementing a desktop adapter // register different interfaces with add() @@ -37,18 +37,15 @@ namespace pEp { proc on_shutdown = nullptr); void remove(::messageToSend_t messageToSend); - static void start_sync(); - static void stop_sync(); - static PEP_STATUS messageToSend(::message *msg); static PEP_STATUS notifyHandshake( ::pEp_identity *me, ::pEp_identity *partner, ::sync_handshake_signal signal); - protected: void on_startup(); void on_shutdown(); + protected: PEP_STATUS _messageToSend(::message *msg); PEP_STATUS _notifyHandshake(