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;
notifyHandshake_t Adapter::_notifyHandshake = nullptr;
std::thread *_sync_thread = nullptr;
Adapter::Adapter(messageToSend_t messageToSend,
notifyHandshake_t notifyHandshake, bool is_sync_thread)
notifyHandshake_t notifyHandshake)
{
if (messageToSend)
_messageToSend = messageToSend;
@ -39,10 +40,11 @@ namespace pEp {
PEP_SESSION _session = session();
if (is_sync_thread) {
PEP_STATUS status = register_sync_callbacks(_session, nullptr,
notifyHandshake, _retrieve_next_sync_event);
throw_status(status);
{
lock_guard<mutex> lock(mtx());
if (!_sync_thread)
_sync_thread = new thread();
}
}
@ -115,5 +117,17 @@ namespace pEp {
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
#include "locked_queue.hh"
#include <thread>
#include <pEp/sync_api.h>
namespace pEp {
@ -12,11 +13,11 @@ namespace pEp {
class Adapter {
static messageToSend_t _messageToSend;
static notifyHandshake_t _notifyHandshake;
static std::thread *_sync_thread;
public:
Adapter(messageToSend_t messageToSend,
notifyHandshake_t notifyHandshake,
bool is_sync_thread = false);
notifyHandshake_t notifyHandshake);
virtual ~Adapter() { }
enum session_action {
@ -34,6 +35,7 @@ namespace pEp {
protected:
static int _inject_sync_event(SYNC_EVENT ev, void *management);
static SYNC_EVENT _retrieve_next_sync_event(void *management, time_t threshold);
static void sync_thread();
private:
static std::mutex& mtx()

Loading…
Cancel
Save