Browse Source

singleton

synchronous
Volker Birk 5 years ago
parent
commit
4cee907912
  1. 8
      callback_dispatcher.cc
  2. 5
      callback_dispatcher.hh

8
callback_dispatcher.cc

@ -3,8 +3,16 @@
#include <cassert> #include <cassert>
namespace pEp { namespace pEp {
bool CallbackDispatcher::once = true;
CallbackDispatcher dispatcher; CallbackDispatcher dispatcher;
CallbackDispatcher::CallbackDispatcher()
{
if (!once)
throw std::out_of_range("CallbackDispatcher is a singleton");
once = false;
}
PEP_STATUS CallbackDispatcher::messageToSend(::message *msg) PEP_STATUS CallbackDispatcher::messageToSend(::message *msg)
{ {
return dispatcher._messageToSend(msg); return dispatcher._messageToSend(msg);

5
callback_dispatcher.hh

@ -9,10 +9,13 @@ namespace pEp {
::messageToSend_t messageToSend; ::messageToSend_t messageToSend;
::notifyHandshake_t notifyHandshake; ::notifyHandshake_t notifyHandshake;
}; };
std::vector<callbacks> targets; std::vector<callbacks> targets;
static bool once;
public: public:
CallbackDispatcher();
static PEP_STATUS messageToSend(::message *msg); static PEP_STATUS messageToSend(::message *msg);
static PEP_STATUS notifyHandshake(::pEp_identity *me, static PEP_STATUS notifyHandshake(::pEp_identity *me,
::pEp_identity *partner, ::sync_handshake_signal signal); ::pEp_identity *partner, ::sync_handshake_signal signal);

Loading…
Cancel
Save