Browse Source

sync thread implementation

LPA-1
Volker Birk 7 years ago
parent
commit
451e049b83
  1. 24
      Adapter.cc
  2. 6
      Adapter.hh

24
Adapter.cc

@ -27,9 +27,10 @@ namespace pEp {
messageToSend_t Adapter::_messageToSend = nullptr; messageToSend_t Adapter::_messageToSend = nullptr;
notifyHandshake_t Adapter::_notifyHandshake = nullptr; notifyHandshake_t Adapter::_notifyHandshake = nullptr;
std::thread *_sync_thread = nullptr;
Adapter::Adapter(messageToSend_t messageToSend, Adapter::Adapter(messageToSend_t messageToSend,
notifyHandshake_t notifyHandshake, bool is_sync_thread) notifyHandshake_t notifyHandshake)
{ {
if (messageToSend) if (messageToSend)
_messageToSend = messageToSend; _messageToSend = messageToSend;
@ -39,10 +40,11 @@ namespace pEp {
PEP_SESSION _session = session(); PEP_SESSION _session = session();
if (is_sync_thread) { {
PEP_STATUS status = register_sync_callbacks(_session, nullptr, lock_guard<mutex> lock(mtx());
notifyHandshake, _retrieve_next_sync_event);
throw_status(status); if (!_sync_thread)
_sync_thread = new thread();
} }
} }
@ -115,5 +117,17 @@ namespace pEp {
return queue().pop_front(); return queue().pop_front();
} }
void Adapter::sync_thread()
{
PEP_STATUS status = register_sync_callbacks(session(), nullptr,
_notifyHandshake, _retrieve_next_sync_event);
throw_status(status);
do_sync_protocol(session(), nullptr);
unregister_sync_callbacks(session());
session(release);
}
} }

6
Adapter.hh

@ -4,6 +4,7 @@
#pragma once #pragma once
#include "locked_queue.hh" #include "locked_queue.hh"
#include <thread>
#include <pEp/sync_api.h> #include <pEp/sync_api.h>
namespace pEp { namespace pEp {
@ -12,11 +13,11 @@ namespace pEp {
class Adapter { class Adapter {
static messageToSend_t _messageToSend; static messageToSend_t _messageToSend;
static notifyHandshake_t _notifyHandshake; static notifyHandshake_t _notifyHandshake;
static std::thread *_sync_thread;
public: public:
Adapter(messageToSend_t messageToSend, Adapter(messageToSend_t messageToSend,
notifyHandshake_t notifyHandshake, notifyHandshake_t notifyHandshake);
bool is_sync_thread = false);
virtual ~Adapter() { } virtual ~Adapter() { }
enum session_action { enum session_action {
@ -34,6 +35,7 @@ namespace pEp {
protected: protected:
static int _inject_sync_event(SYNC_EVENT ev, void *management); static int _inject_sync_event(SYNC_EVENT ev, void *management);
static SYNC_EVENT _retrieve_next_sync_event(void *management, time_t threshold); static SYNC_EVENT _retrieve_next_sync_event(void *management, time_t threshold);
static void sync_thread();
private: private:
static std::mutex& mtx() static std::mutex& mtx()

Loading…
Cancel
Save