Browse Source

allow UserInterface on one thread

PYADPT-55
Volker Birk 7 years ago
parent
commit
21379bcb3f
  1. 24
      src/user_interface.cc
  2. 10
      src/user_interface.hh

24
src/user_interface.cc

@ -7,8 +7,22 @@
namespace pEp {
namespace PythonAdapter {
UserInterface *UserInterface::_ui = nullptr;
UserInterface::UserInterface()
{
if (_ui)
throw runtime_error("only one UserInterface thread allowed");
_ui = this;
}
UserInterface::~UserInterface()
{
_ui = nullptr;
}
UserInterface_callback::UserInterface_callback(PyObject *self) :
_self(self)
UserInterface(), _self(self)
{
adapter.ui_object(self);
PEP_STATUS status = ::register_sync_callbacks(adapter.session(),
@ -23,19 +37,15 @@ namespace pEp {
::unregister_sync_callbacks(adapter.session());
}
PEP_STATUS UserInterface::_notifyHandshake(void *obj,
PEP_STATUS UserInterface::_notifyHandshake(
pEp_identity *me, pEp_identity *partner,
sync_handshake_signal signal
)
{
if (!obj)
return PEP_SEND_FUNCTION_NOT_REGISTERED;
if (!(me && partner))
return PEP_ILLEGAL_VALUE;
auto that = dynamic_cast< UserInterface_callback * >(
static_cast< UserInterface * > (obj));
auto that = dynamic_cast< UserInterface_callback * >(_ui);
that->notifyHandshake(Identity(me), Identity(partner), signal);
return PEP_STATUS_OK;

10
src/user_interface.hh

@ -10,9 +10,10 @@
namespace pEp {
namespace PythonAdapter {
class UserInterface {
static UserInterface *_ui;
public:
UserInterface() { }
virtual ~UserInterface() { }
UserInterface();
virtual ~UserInterface();
virtual void notifyHandshake(
pEp::PythonAdapter::Identity me,
@ -26,14 +27,13 @@ namespace pEp {
pEp::PythonAdapter::Identity partner, int result);
protected:
static PEP_STATUS _notifyHandshake(void *obj, pEp_identity *me,
static PEP_STATUS _notifyHandshake(pEp_identity *me,
pEp_identity *partner, sync_handshake_signal signal);
static SYNC_EVENT retrieve_next_sync_event(void *management, time_t threshold);
};
class UserInterface_callback : public UserInterface {
PyObject *_self;
PyObject *_self;
public:
UserInterface_callback(PyObject *self);
~UserInterface_callback();

Loading…
Cancel
Save