parent
24e13adfe1
commit
c18746e4ec
@ -1,99 +0,0 @@
|
||||
// This file is under GNU Affero General Public License 3.0
|
||||
// see LICENSE.txt
|
||||
|
||||
#include "user_interface.hh"
|
||||
#include <assert.h>
|
||||
#include "adapter.hh"
|
||||
|
||||
namespace pEp {
|
||||
namespace PythonAdapter {
|
||||
Adapter::Adapter(bool unregister_this)
|
||||
: flag_unregister(unregister_this)
|
||||
{
|
||||
session(init);
|
||||
}
|
||||
|
||||
Adapter::~Adapter()
|
||||
{
|
||||
session(release);
|
||||
}
|
||||
|
||||
PEP_SESSION Adapter::session(session_action action)
|
||||
{
|
||||
lock_guard<mutex> lock(mtx());
|
||||
|
||||
thread_local static PEP_SESSION _session = nullptr;
|
||||
thread_local int booked = 0;
|
||||
PEP_STATUS status = PEP_STATUS_OK;
|
||||
|
||||
switch (action) {
|
||||
case release:
|
||||
if (booked)
|
||||
--booked;
|
||||
if (!booked && _session) {
|
||||
::release(_session);
|
||||
_session = nullptr;
|
||||
}
|
||||
break;
|
||||
|
||||
case none:
|
||||
if (_session)
|
||||
break;
|
||||
|
||||
case init:
|
||||
++booked;
|
||||
if (!_session)
|
||||
// status = ::init(&_session, _messageToSend, _inject_sync_event, _ensure_passphrase);
|
||||
// status = ::init(&_session, _messageToSend, _inject_sync_event);
|
||||
break;
|
||||
|
||||
default:
|
||||
status = PEP_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
if (status)
|
||||
_throw_status(status);
|
||||
|
||||
return _session;
|
||||
}
|
||||
|
||||
::utility::locked_queue< SYNC_EVENT > * Adapter::q = nullptr;
|
||||
bool Adapter::flag_sync_enabled = false;
|
||||
|
||||
void Adapter::shutdown_sync()
|
||||
{
|
||||
if (queue_active())
|
||||
queue().push_front(nullptr);
|
||||
flag_sync_enabled = false;
|
||||
}
|
||||
|
||||
PyObject *Adapter::ui_object(PyObject *value)
|
||||
{
|
||||
lock_guard<mutex> lock(mtx());
|
||||
static PyObject *obj = nullptr;
|
||||
if (value)
|
||||
obj = value;
|
||||
return obj;
|
||||
}
|
||||
|
||||
// int Adapter::_inject_sync_event(SYNC_EVENT ev, void *management)
|
||||
// {
|
||||
// if (!flag_sync_enabled)
|
||||
// return 1;
|
||||
//
|
||||
// if (is_sync_thread(adapter.session())) {
|
||||
// PEP_STATUS status = do_sync_protocol_step(adapter.session(), adapter.ui_object(), ev);
|
||||
// return status == PEP_STATUS_OK ? 0 : 1;
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// queue().push_back(ev);
|
||||
// }
|
||||
// catch (exception&) {
|
||||
// return 1;
|
||||
// }
|
||||
// return 0;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -1,59 +0,0 @@
|
||||
// This file is under GNU Affero General Public License 3.0
|
||||
// see LICENSE.txt
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "pEpmodule.hh"
|
||||
#include "pEp/locked_queue.hh"
|
||||
#include "user_interface.hh"
|
||||
#include <pEp/sync_api.h>
|
||||
|
||||
namespace pEp {
|
||||
namespace PythonAdapter {
|
||||
using Message = pEp::PythonAdapter::Message;
|
||||
|
||||
class Adapter {
|
||||
bool flag_unregister;
|
||||
|
||||
public:
|
||||
Adapter(bool unregister_this = false);
|
||||
virtual ~Adapter();
|
||||
|
||||
enum session_action {
|
||||
none = 0,
|
||||
init,
|
||||
release
|
||||
};
|
||||
|
||||
PEP_SESSION session(session_action action = none);
|
||||
static ::utility::locked_queue< SYNC_EVENT >& queue()
|
||||
{
|
||||
if (!q)
|
||||
q = new ::utility::locked_queue< SYNC_EVENT >();
|
||||
return *q;
|
||||
}
|
||||
void script_is_implementing_sync() { flag_sync_enabled = true; }
|
||||
void shutdown_sync();
|
||||
bool is_sync_active() { return flag_sync_enabled; }
|
||||
|
||||
protected:
|
||||
static PyObject *ui_object(PyObject *value = nullptr);
|
||||
static int _inject_sync_event(SYNC_EVENT ev, void *management);
|
||||
|
||||
static ::utility::locked_queue< SYNC_EVENT > *q;
|
||||
static bool flag_sync_enabled;
|
||||
|
||||
bool queue_active() { return !!q; }
|
||||
|
||||
private:
|
||||
static mutex& mtx()
|
||||
{
|
||||
static mutex m;
|
||||
return m;
|
||||
}
|
||||
|
||||
friend class UserInterface_callback;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,61 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include <mutex>
|
||||
|
||||
namespace utility
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
template<class T> class locked_queue
|
||||
{
|
||||
mutex _mtx;
|
||||
list<T> _q;
|
||||
|
||||
public:
|
||||
T& back()
|
||||
{
|
||||
lock_guard<mutex> lg(_mtx);
|
||||
return _q.back();
|
||||
}
|
||||
T& front()
|
||||
{
|
||||
lock_guard<mutex> lg(_mtx);
|
||||
return _q.front();
|
||||
}
|
||||
T pop_back()
|
||||
{
|
||||
lock_guard<mutex> lg(_mtx);
|
||||
T r = _q.back();
|
||||
_q.pop_back();
|
||||
return r;
|
||||
}
|
||||
T pop_front()
|
||||
{
|
||||
lock_guard<mutex> lg(_mtx);
|
||||
T r = _q.front();
|
||||
_q.pop_front();
|
||||
return r;
|
||||
}
|
||||
void push_back(const T& data)
|
||||
{
|
||||
lock_guard<mutex> lg(_mtx);
|
||||
_q.push_back(data);
|
||||
}
|
||||
void push_front(const T& data)
|
||||
{
|
||||
lock_guard<mutex> lg(_mtx);
|
||||
_q.push_front(data);
|
||||
}
|
||||
size_t size()
|
||||
{
|
||||
lock_guard<mutex> lg(_mtx);
|
||||
return _q.size();
|
||||
}
|
||||
bool empty()
|
||||
{
|
||||
lock_guard<mutex> lg(_mtx);
|
||||
return _q.empty();
|
||||
}
|
||||
};
|
||||
};
|
Loading…
Reference in new issue