From 26ffc8fe121e03e1b663aa0015a71b0fc914f95e Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Thu, 19 Jun 2014 22:21:49 +0200 Subject: Implement a way to add callbacks, waiting for an IRC event to return an iq --- src/bridge/bridge.hpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/bridge/bridge.hpp') diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp index 8711829..0983595 100644 --- a/src/bridge/bridge.hpp +++ b/src/bridge/bridge.hpp @@ -7,12 +7,21 @@ #include #include +#include #include #include class XmppComponent; class Poller; +/** + * A callback called for each IrcMessage we receive. If the message triggers + * a response, it must send an iq and return true (in that case it is + * removed from the list), otherwise it must do nothing and just return + * false. + */ +typedef std::function iq_responder_callback_t; + /** * One bridge is spawned for each XMPP user that uses the component. The * bridge spawns IrcClients when needed (when the user wants to join a @@ -131,6 +140,16 @@ public: * Remove the preferred jid for the given IRC nick */ void remove_preferred_from_jid(const std::string& nick); + /** + * Add a callback to the waiting iq list. + */ + void add_waiting_iq(iq_responder_callback_t&& callback); + /** + * Iter over all the waiting_iq, call the iq_responder_filter_t for each, + * whenever one of them returns true: call the corresponding + * iq_responder_callback_t and remove the callback from the list. + */ + void trigger_response_iq(const std::string& irc_hostname, const IrcMessage& message); private: /** @@ -173,6 +192,13 @@ private: * from='#somechan%server@biboumi/ToTo' */ std::unordered_map preferred_user_from; + /** + * A list of callbacks that are waiting for some IrcMessage to trigger a + * response. We add callbacks in this list whenever we received an IQ + * request and we need a response from IRC to be able to provide the + * response iq. + */ + std::list waiting_iq; Bridge(const Bridge&) = delete; Bridge(Bridge&& other) = delete; -- cgit v1.2.3