From 4cee907912fadc945840e27a60bb90a71b964f29 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Tue, 30 Jun 2020 22:41:15 +0200 Subject: [PATCH] singleton --- callback_dispatcher.cc | 8 ++++++++ callback_dispatcher.hh | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/callback_dispatcher.cc b/callback_dispatcher.cc index c6098a8..6a29946 100644 --- a/callback_dispatcher.cc +++ b/callback_dispatcher.cc @@ -3,8 +3,16 @@ #include namespace pEp { + bool CallbackDispatcher::once = true; CallbackDispatcher dispatcher; + CallbackDispatcher::CallbackDispatcher() + { + if (!once) + throw std::out_of_range("CallbackDispatcher is a singleton"); + once = false; + } + PEP_STATUS CallbackDispatcher::messageToSend(::message *msg) { return dispatcher._messageToSend(msg); diff --git a/callback_dispatcher.hh b/callback_dispatcher.hh index 8a25303..76e997e 100644 --- a/callback_dispatcher.hh +++ b/callback_dispatcher.hh @@ -9,10 +9,13 @@ namespace pEp { ::messageToSend_t messageToSend; ::notifyHandshake_t notifyHandshake; }; - std::vector targets; + static bool once; + public: + CallbackDispatcher(); + static PEP_STATUS messageToSend(::message *msg); static PEP_STATUS notifyHandshake(::pEp_identity *me, ::pEp_identity *partner, ::sync_handshake_signal signal);