From 2e7a0001849c5ad6875dd8e6e179282f057ddf9a Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Wed, 17 Oct 2018 13:03:02 +0200 Subject: [PATCH] callbacks --- Adapter.cc | 16 +++++++++++----- Adapter.hh | 7 +++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Adapter.cc b/Adapter.cc index 444d25f..796db41 100644 --- a/Adapter.cc +++ b/Adapter.cc @@ -83,20 +83,26 @@ namespace pEp { return q.pop_front(); } - static void sync_thread(void *obj) + template< class T > static void sync_thread(T *obj, function< int (T::*) > _startup) { PEP_STATUS status = register_sync_callbacks(session(), nullptr, _notifyHandshake, _retrieve_next_sync_event); throw_status(status); - do_sync_protocol(session(), obj); + if (obj && startup) { + _startup(obj); + } + + do_sync_protocol(session(), (void *) obj); unregister_sync_callbacks(session()); session(release); } - void startup(messageToSend_t messageToSend, - notifyHandshake_t notifyHandshake, void *obj) + template< class T > void startup(messageToSend_t messageToSend, + notifyHandshake_t notifyHandshake, T *obj, + function< int ( T::* ) > _startup + ) { if (messageToSend) _messageToSend = messageToSend; @@ -110,7 +116,7 @@ namespace pEp { lock_guard lock(m); if (!_sync_thread) - _sync_thread = new thread(sync_thread, obj); + _sync_thread = new thread(sync_thread, obj, _startup); } } diff --git a/Adapter.hh b/Adapter.hh index 5f4a878..aa369f1 100644 --- a/Adapter.hh +++ b/Adapter.hh @@ -5,6 +5,7 @@ #include "locked_queue.hh" #include +#include #include #include @@ -20,8 +21,10 @@ namespace pEp { }; namespace Adapter { - void startup(messageToSend_t messageToSend, - notifyHandshake_t notifyHandshake, void *obj = nullptr); + template void startup(messageToSend_t messageToSend, + notifyHandshake_t notifyHandshake, T *obj = nullptr, + function< int (T::*) > _startup = nullptr + ); enum session_action { init,