|
@ -1,13 +1,23 @@ |
|
|
#pragma once |
|
|
#pragma once |
|
|
|
|
|
|
|
|
#include <vector> |
|
|
#include <vector> |
|
|
|
|
|
#include <functional> |
|
|
#include "Adapter.hh" |
|
|
#include "Adapter.hh" |
|
|
|
|
|
|
|
|
namespace pEp { |
|
|
namespace pEp { |
|
|
|
|
|
// use this class when implementing a desktop adapter
|
|
|
|
|
|
// register different interfaces with add()
|
|
|
|
|
|
// then use CallbackDispatcher::start_sync() to start Sync
|
|
|
|
|
|
// and CallbackDispatcher::stop_sync() to stop Sync
|
|
|
|
|
|
|
|
|
class CallbackDispatcher { |
|
|
class CallbackDispatcher { |
|
|
|
|
|
using proc = std::function<void()>; |
|
|
|
|
|
|
|
|
struct callbacks { |
|
|
struct callbacks { |
|
|
::messageToSend_t messageToSend; |
|
|
::messageToSend_t messageToSend; |
|
|
::notifyHandshake_t notifyHandshake; |
|
|
::notifyHandshake_t notifyHandshake; |
|
|
|
|
|
proc on_startup; |
|
|
|
|
|
proc on_shutdown; |
|
|
}; |
|
|
}; |
|
|
std::vector<callbacks> targets; |
|
|
std::vector<callbacks> targets; |
|
|
|
|
|
|
|
@ -16,15 +26,25 @@ namespace pEp { |
|
|
public: |
|
|
public: |
|
|
CallbackDispatcher(); |
|
|
CallbackDispatcher(); |
|
|
|
|
|
|
|
|
|
|
|
void add( |
|
|
|
|
|
::messageToSend_t messageToSend, |
|
|
|
|
|
::notifyHandshake_t notifyHandshake, |
|
|
|
|
|
proc on_startup = nullptr, |
|
|
|
|
|
proc on_shutdown = nullptr |
|
|
|
|
|
); |
|
|
|
|
|
void remove(::messageToSend_t messageToSend); |
|
|
|
|
|
|
|
|
|
|
|
void start_sync(); |
|
|
|
|
|
void stop_sync(); |
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
|
|
void on_startup(); |
|
|
|
|
|
void on_shutdown(); |
|
|
|
|
|
|
|
|
static PEP_STATUS messageToSend(::message *msg); |
|
|
static PEP_STATUS messageToSend(::message *msg); |
|
|
static PEP_STATUS notifyHandshake(::pEp_identity *me, |
|
|
static PEP_STATUS notifyHandshake(::pEp_identity *me, |
|
|
::pEp_identity *partner, ::sync_handshake_signal signal); |
|
|
::pEp_identity *partner, ::sync_handshake_signal signal); |
|
|
|
|
|
|
|
|
void add(::messageToSend_t messageToSend, |
|
|
|
|
|
::notifyHandshake_t notifyHandshake); |
|
|
|
|
|
void remove(::messageToSend_t messageToSend); |
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
|
|
PEP_STATUS _messageToSend(::message *msg); |
|
|
PEP_STATUS _messageToSend(::message *msg); |
|
|
PEP_STATUS _notifyHandshake(::pEp_identity *me, |
|
|
PEP_STATUS _notifyHandshake(::pEp_identity *me, |
|
|
::pEp_identity *partner, ::sync_handshake_signal signal); |
|
|
::pEp_identity *partner, ::sync_handshake_signal signal); |
|
|