From 89ca327f03bed83493d4cf976b5ea8e1e0b3537b Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Thu, 18 Oct 2018 15:19:30 +0200 Subject: [PATCH] ... --- Adapter.cc | 53 +++---------------- Adapter.hh | 1 + Adapter.hxx | 58 +++++++++++++++++++++ libpEpAdapter/libpEpAdapter.vcxproj | 1 + libpEpAdapter/libpEpAdapter.vcxproj.filters | 3 ++ 5 files changed, 70 insertions(+), 46 deletions(-) create mode 100644 Adapter.hxx diff --git a/Adapter.cc b/Adapter.cc index 27186ae..3d18983 100644 --- a/Adapter.cc +++ b/Adapter.cc @@ -32,11 +32,12 @@ namespace pEp { } namespace Adapter { - static messageToSend_t _messageToSend = nullptr; - static notifyHandshake_t _notifyHandshake = nullptr; - static std::thread *_sync_thread = nullptr; - static ::utility::locked_queue< SYNC_EVENT > q; - static std::mutex m; + messageToSend_t _messageToSend = nullptr; + notifyHandshake_t _notifyHandshake = nullptr; + std::thread *_sync_thread = nullptr; + + ::utility::locked_queue< SYNC_EVENT > q; + std::mutex m; static int _inject_sync_event(SYNC_EVENT ev, void *management) { @@ -54,7 +55,7 @@ namespace pEp { return 0; } - static SYNC_EVENT _retrieve_next_sync_event(void *management, time_t threshold) + SYNC_EVENT _retrieve_next_sync_event(void *management, time_t threshold) { time_t started = time(nullptr); bool timeout = false; @@ -83,46 +84,6 @@ namespace pEp { return q.pop_front(); } - 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) - _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< void (T *) > _startup, - function< void (T *) > _shutdown - ) - { - if (messageToSend) - _messageToSend = messageToSend; - - if (notifyHandshake) - _notifyHandshake = notifyHandshake; - - session(); - - { - lock_guard lock(m); - - if (!_sync_thread) - _sync_thread = new thread(sync_thread, obj, _startup, _shutdown); - } - } - PEP_SESSION session(session_action action) { lock_guard lock(m); diff --git a/Adapter.hh b/Adapter.hh index 237d437..31f25ed 100644 --- a/Adapter.hh +++ b/Adapter.hh @@ -8,6 +8,7 @@ #include #include #include +#include "Adapter.hxx" using namespace std; diff --git a/Adapter.hxx b/Adapter.hxx new file mode 100644 index 0000000..b98e283 --- /dev/null +++ b/Adapter.hxx @@ -0,0 +1,58 @@ +#pragma once + +#include + +using namespace std; + +namespace pEp { + namespace Adapter { + extern messageToSend_t _messageToSend; + extern notifyHandshake_t _notifyHandshake; + extern std::thread *_sync_thread; + + extern ::utility::locked_queue< SYNC_EVENT > q; + extern std::mutex m; + + SYNC_EVENT _retrieve_next_sync_event(void *management, time_t threshold); + + template< class T > 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) + _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< void(T *) > _startup, + function< void(T *) > _shutdown + ) + { + if (messageToSend) + _messageToSend = messageToSend; + + if (notifyHandshake) + _notifyHandshake = notifyHandshake; + + session(); + + { + lock_guard lock(m); + + if (!_sync_thread) + _sync_thread = new thread(sync_thread, obj, _startup, _shutdown); + } + } + } +} diff --git a/libpEpAdapter/libpEpAdapter.vcxproj b/libpEpAdapter/libpEpAdapter.vcxproj index 466daad..cfeae10 100644 --- a/libpEpAdapter/libpEpAdapter.vcxproj +++ b/libpEpAdapter/libpEpAdapter.vcxproj @@ -139,6 +139,7 @@ + diff --git a/libpEpAdapter/libpEpAdapter.vcxproj.filters b/libpEpAdapter/libpEpAdapter.vcxproj.filters index ec57bb8..349cfcd 100644 --- a/libpEpAdapter/libpEpAdapter.vcxproj.filters +++ b/libpEpAdapter/libpEpAdapter.vcxproj.filters @@ -26,5 +26,8 @@ Header Files + + Header Files + \ No newline at end of file