Browse Source

shutdown sync for single threaded script

PYADPT-55
Volker Birk 6 years ago
parent
commit
1c9eeb93f6
  1. 11
      src/adapter.cc
  2. 14
      src/adapter.hh
  3. 2
      src/message.cc
  4. 3
      src/message_api.cc
  5. 21
      src/pEpmodule.cc

11
src/adapter.cc

@ -7,7 +7,7 @@
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
Adapter::Adapter(bool unregister_this) Adapter::Adapter(bool unregister_this)
: flag_unregister(unregister_this) : flag_unregister(unregister_this), flag_sync_enabled(false)
{ {
session(init); session(init);
} }
@ -55,6 +55,15 @@ namespace pEp {
return _session; return _session;
} }
::utility::locked_queue< SYNC_EVENT > * Adapter::q = nullptr;
void Adapter::shutdown_sync()
{
if (queue_active())
queue().push_front(nullptr);
flag_sync_enabled = false;
}
PyObject *Adapter::ui_object(PyObject *value) PyObject *Adapter::ui_object(PyObject *value)
{ {
lock_guard<mutex> lock(mtx()); lock_guard<mutex> lock(mtx());

14
src/adapter.hh

@ -14,6 +14,7 @@ namespace pEp {
class Adapter { class Adapter {
bool flag_unregister; bool flag_unregister;
bool flag_sync_enabled;
public: public:
Adapter(bool unregister_this = false); Adapter(bool unregister_this = false);
@ -28,16 +29,21 @@ namespace pEp {
PEP_SESSION session(session_action action = none); PEP_SESSION session(session_action action = none);
static ::utility::locked_queue< SYNC_EVENT >& queue() static ::utility::locked_queue< SYNC_EVENT >& queue()
{ {
static ::utility::locked_queue< SYNC_EVENT > q; if (!q)
return q; q = new ::utility::locked_queue< SYNC_EVENT >();
return *q;
} }
void script_is_implementing_sync() { flag_sync_enabled = true; }
void shutdown_sync() { queue().push_front(nullptr); } void shutdown_sync();
bool is_sync_active() { return flag_sync_enabled; }
protected: protected:
static PyObject *ui_object(PyObject *value = nullptr); static PyObject *ui_object(PyObject *value = nullptr);
static int _inject_sync_event(SYNC_EVENT ev, void *management); static int _inject_sync_event(SYNC_EVENT ev, void *management);
static ::utility::locked_queue< SYNC_EVENT > *q;
bool queue_active() { return !!q; }
private: private:
static mutex& mtx() static mutex& mtx()
{ {

2
src/message.cc

@ -306,7 +306,7 @@ namespace pEp {
} }
boost::python::tuple Message::decrypt(int flags) { boost::python::tuple Message::decrypt(int flags) {
return decrypt_message(*this, flags); return pEp::PythonAdapter::decrypt_message(*this, flags);
} }
int Message::outgoing_rating() int Message::outgoing_rating()

3
src/message_api.cc

@ -7,6 +7,7 @@
#include <pEp/message_api.h> #include <pEp/message_api.h>
#include <pEp/sync_api.h> #include <pEp/sync_api.h>
#include <pEp/sync_codec.h> #include <pEp/sync_codec.h>
#include <pEp/distribution_codec.h>
namespace pEp { namespace pEp {
namespace PythonAdapter { namespace PythonAdapter {
@ -47,7 +48,7 @@ namespace pEp {
PEP_decrypt_flags_t _flags = (PEP_decrypt_flags_t) flags; PEP_decrypt_flags_t _flags = (PEP_decrypt_flags_t) flags;
message *_src = src; message *_src = src;
PEP_STATUS status = decrypt_message(adapter.session(), _src, &_dst, &_keylist, PEP_STATUS status = ::decrypt_message(adapter.session(), _src, &_dst, &_keylist,
&_rating, &_flags); &_rating, &_flags);
_throw_status(status); _throw_status(status);

21
src/pEpmodule.cc

@ -122,6 +122,14 @@ namespace pEp {
void leave_device_group() { void leave_device_group() {
::leave_device_group(adapter.session()); ::leave_device_group(adapter.session());
} }
void script_is_implementing_sync() {
adapter.script_is_implementing_sync();
}
bool is_sync_active() {
return adapter.is_sync_active();
}
} }
} }
@ -558,6 +566,19 @@ BOOST_PYTHON_MODULE(pEp)
"call this for a grouped device, which should leave\n" "call this for a grouped device, which should leave\n"
); );
def("script_is_implementing_sync", &pEp::PythonAdapter::script_is_implementing_sync,
"script_is_implementing_sync()\n"
"\n"
"call this in case the Python script is implementing sync to make\n"
"is_sync_active() working\n"
);
def("is_sync_active", &pEp::PythonAdapter::is_sync_active,
"is_sync_active()\n"
"\n"
"True if sync is active, False otherwise\n"
);
// codecs // codecs
call< object >(((object)(import("codecs").attr("register"))).ptr(), make_function(sync_search)); call< object >(((object)(import("codecs").attr("register"))).ptr(), make_function(sync_search));

Loading…
Cancel
Save