Browse Source

shutdown sync for single threaded script

PYADPT-55
Volker Birk 2 years ago
parent
commit
1c9eeb93f6
5 changed files with 44 additions and 7 deletions
  1. +10
    -1
      src/adapter.cc
  2. +10
    -4
      src/adapter.hh
  3. +1
    -1
      src/message.cc
  4. +2
    -1
      src/message_api.cc
  5. +21
    -0
      src/pEpmodule.cc

+ 10
- 1
src/adapter.cc View File

@ -7,7 +7,7 @@
namespace pEp {
namespace PythonAdapter {
Adapter::Adapter(bool unregister_this)
: flag_unregister(unregister_this)
: flag_unregister(unregister_this), flag_sync_enabled(false)
{
session(init);
}
@ -55,6 +55,15 @@ namespace pEp {
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)
{
lock_guard<mutex> lock(mtx());


+ 10
- 4
src/adapter.hh View File

@ -14,6 +14,7 @@ namespace pEp {
class Adapter {
bool flag_unregister;
bool flag_sync_enabled;
public:
Adapter(bool unregister_this = false);
@ -28,16 +29,21 @@ namespace pEp {
PEP_SESSION session(session_action action = none);
static ::utility::locked_queue< SYNC_EVENT >& queue()
{
static ::utility::locked_queue< SYNC_EVENT > q;
return q;
if (!q)
q = new ::utility::locked_queue< SYNC_EVENT >();
return *q;
}
void shutdown_sync() { queue().push_front(nullptr); }
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;
bool queue_active() { return !!q; }
private:
static mutex& mtx()
{


+ 1
- 1
src/message.cc View File

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


+ 2
- 1
src/message_api.cc View File

@ -7,6 +7,7 @@
#include <pEp/message_api.h>
#include <pEp/sync_api.h>
#include <pEp/sync_codec.h>
#include <pEp/distribution_codec.h>
namespace pEp {
namespace PythonAdapter {
@ -47,7 +48,7 @@ namespace pEp {
PEP_decrypt_flags_t _flags = (PEP_decrypt_flags_t) flags;
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);
_throw_status(status);


+ 21
- 0
src/pEpmodule.cc View File

@ -122,6 +122,14 @@ namespace pEp {
void leave_device_group() {
::leave_device_group(adapter.session());
}
void script_is_implementing_sync() {
adapter.script_is_implementing_sync();
}
bool is_sync_active() {
return adapter.is_sync_active();
}
}
}
@ -557,6 +565,19 @@ BOOST_PYTHON_MODULE(pEp)
"\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


Loading…
Cancel
Save