Browse Source

move start_sync() and stop_sync() from CallbackDispatcher to Adapter.hh

LIB-11
heck 3 months ago
parent
commit
9b922a39dc
4 changed files with 18 additions and 42 deletions
  1. +10
    -1
      src/Adapter.cc
  2. +3
    -1
      src/Adapter.hh
  3. +2
    -34
      src/callback_dispatcher.cc
  4. +3
    -6
      src/callback_dispatcher.hh

+ 10
- 1
src/Adapter.cc View File

@ -207,14 +207,23 @@ namespace pEp {
_inject_sync_event(nullptr, nullptr);
}
void start_sync()
{
startup<pEp::CallbackDispatcher>(
&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);
}
}


+ 3
- 1
src/Adapter.hh View File

@ -47,6 +47,8 @@ namespace pEp {
::PEP_STATUS _ensure_passphrase(::PEP_SESSION session, const char *fpr);
void start_sync();
template<class T = void>
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();


+ 2
- 34
src/callback_dispatcher.cc View File

@ -5,6 +5,7 @@
#include "passphrase_cache.hh"
#include <stdexcept>
#include <cassert>
#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>(
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) {


+ 3
- 6
src/callback_dispatcher.hh View File

@ -7,10 +7,10 @@
#include <vector>
#include <functional>
#include <mutex>
#include "Adapter.hh"
#include "Semaphore.hh"
#include "passphrase_cache.hh"
#include <pEp/sync_api.h>
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(


Loading…
Cancel
Save