Browse Source

startup and shutdown in sync thread

LPA-1
Volker Birk 7 years ago
parent
commit
400e23642a
  1. 13
      Adapter.cc
  2. 3
      Adapter.hh

13
Adapter.cc

@ -83,25 +83,28 @@ namespace pEp {
return q.pop_front(); 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, PEP_STATUS status = register_sync_callbacks(session(), nullptr,
_notifyHandshake, _retrieve_next_sync_event); _notifyHandshake, _retrieve_next_sync_event);
throw_status(status); throw_status(status);
if (obj && startup) { if (obj && startup)
_startup(obj); _startup(obj);
}
do_sync_protocol(session(), (void *) obj); do_sync_protocol(session(), (void *) obj);
unregister_sync_callbacks(session()); unregister_sync_callbacks(session());
session(release); session(release);
if (obj && _shutdown)
_shutdown(obj);
} }
template< class T > void startup(messageToSend_t messageToSend, template< class T > void startup(messageToSend_t messageToSend,
notifyHandshake_t notifyHandshake, T *obj, notifyHandshake_t notifyHandshake, T *obj,
function< int ( T::* ) > _startup function< void (T *) > _startup,
function< void(T *) > _shutdown
) )
{ {
if (messageToSend) if (messageToSend)
@ -116,7 +119,7 @@ namespace pEp {
lock_guard<mutex> lock(m); lock_guard<mutex> lock(m);
if (!_sync_thread) if (!_sync_thread)
_sync_thread = new thread(sync_thread<T>, obj, _startup); _sync_thread = new thread(sync_thread<T>, obj, _startup, _shutdown);
} }
} }

3
Adapter.hh

@ -23,7 +23,8 @@ namespace pEp {
namespace Adapter { namespace Adapter {
template<class T> void startup(messageToSend_t messageToSend, template<class T> void startup(messageToSend_t messageToSend,
notifyHandshake_t notifyHandshake, T *obj = nullptr, notifyHandshake_t notifyHandshake, T *obj = nullptr,
function< int (T::*) > _startup = nullptr function< void (T *) > _startup = nullptr,
function< void(T *) > _shutdown = nullptr
); );
enum session_action { enum session_action {

Loading…
Cancel
Save