diff --git a/setup.py b/setup.py index e62010f..445936c 100644 --- a/setup.py +++ b/setup.py @@ -219,7 +219,6 @@ module_pEp = Extension( 'src/pEp/native_pEp/message_api.cc', 'src/pEp/native_pEp/str_attr.cc', 'src/pEp/native_pEp/user_interface.cc', - # 'src/adapter.cc' ], ) diff --git a/src/pEp/native_pEp/adapter.cc b/src/pEp/native_pEp/adapter.cc deleted file mode 100644 index 6bc1c4f..0000000 --- a/src/pEp/native_pEp/adapter.cc +++ /dev/null @@ -1,99 +0,0 @@ -// This file is under GNU Affero General Public License 3.0 -// see LICENSE.txt - -#include "user_interface.hh" -#include -#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 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 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; -// } - } -} - diff --git a/src/pEp/native_pEp/adapter.hh b/src/pEp/native_pEp/adapter.hh deleted file mode 100644 index 634e65c..0000000 --- a/src/pEp/native_pEp/adapter.hh +++ /dev/null @@ -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 - -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; - }; - } -} - diff --git a/src/pEp/native_pEp/locked_queue.hh b/src/pEp/native_pEp/locked_queue.hh deleted file mode 100644 index 88c7430..0000000 --- a/src/pEp/native_pEp/locked_queue.hh +++ /dev/null @@ -1,61 +0,0 @@ -#pragma once - -#include -#include - -namespace utility -{ - using namespace std; - - template class locked_queue - { - mutex _mtx; - list _q; - - public: - T& back() - { - lock_guard lg(_mtx); - return _q.back(); - } - T& front() - { - lock_guard lg(_mtx); - return _q.front(); - } - T pop_back() - { - lock_guard lg(_mtx); - T r = _q.back(); - _q.pop_back(); - return r; - } - T pop_front() - { - lock_guard lg(_mtx); - T r = _q.front(); - _q.pop_front(); - return r; - } - void push_back(const T& data) - { - lock_guard lg(_mtx); - _q.push_back(data); - } - void push_front(const T& data) - { - lock_guard lg(_mtx); - _q.push_front(data); - } - size_t size() - { - lock_guard lg(_mtx); - return _q.size(); - } - bool empty() - { - lock_guard lg(_mtx); - return _q.empty(); - } - }; -};