From 400e23642aa555647fb4897376326f946a0b0cb7 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Thu, 18 Oct 2018 10:52:12 +0200 Subject: [PATCH] startup and shutdown in sync thread --- Adapter.cc | 13 ++++++++----- Adapter.hh | 3 ++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Adapter.cc b/Adapter.cc index 796db41..fba18ed 100644 --- a/Adapter.cc +++ b/Adapter.cc @@ -83,25 +83,28 @@ namespace pEp { return q.pop_front(); } - template< class T > static void sync_thread(T *obj, function< int (T::*) > _startup) + template< class T > static void sync_thread(T *obj, function< void(T *) > _startup, function< void(T *) > _shutdown) { PEP_STATUS status = register_sync_callbacks(session(), nullptr, _notifyHandshake, _retrieve_next_sync_event); throw_status(status); - if (obj && startup) { + if (obj && startup) _startup(obj); - } do_sync_protocol(session(), (void *) obj); unregister_sync_callbacks(session()); session(release); + + if (obj && _shutdown) + _shutdown(obj); } template< class T > void startup(messageToSend_t messageToSend, notifyHandshake_t notifyHandshake, T *obj, - function< int ( T::* ) > _startup + function< void (T *) > _startup, + function< void(T *) > _shutdown ) { if (messageToSend) @@ -116,7 +119,7 @@ namespace pEp { lock_guard lock(m); if (!_sync_thread) - _sync_thread = new thread(sync_thread, obj, _startup); + _sync_thread = new thread(sync_thread, obj, _startup, _shutdown); } } diff --git a/Adapter.hh b/Adapter.hh index aa369f1..6c16a6b 100644 --- a/Adapter.hh +++ b/Adapter.hh @@ -23,7 +23,8 @@ namespace pEp { namespace Adapter { template void startup(messageToSend_t messageToSend, notifyHandshake_t notifyHandshake, T *obj = nullptr, - function< int (T::*) > _startup = nullptr + function< void (T *) > _startup = nullptr, + function< void(T *) > _shutdown = nullptr ); enum session_action {