diff options
Diffstat (limited to 'Swiften/Queries/Responder.h')
-rw-r--r-- | Swiften/Queries/Responder.h | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/Swiften/Queries/Responder.h b/Swiften/Queries/Responder.h index b38c3c4..2333b5f 100644 --- a/Swiften/Queries/Responder.h +++ b/Swiften/Queries/Responder.h @@ -4,33 +4,78 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_Responder_H -#define SWIFTEN_Responder_H +#pragma once #include "Swiften/Queries/IQHandler.h" #include "Swiften/Queries/IQRouter.h" #include "Swiften/Elements/ErrorPayload.h" namespace Swift { + /** + * A class for handling incoming IQ Get and Set requests of a specific payload type. + * + * Concrete subclasses of this class need to implement handleGetRequest() and handleSetRequest() to + * implement the behavior of the responder. + * + * \tparam PAYLOAD_TYPE The type of payload this Responder handles. Only IQ requests containing this + * payload type will be passed to handleGetRequest() and handleSetRequest() + */ template<typename PAYLOAD_TYPE> class Responder : public IQHandler { public: Responder(IQRouter* router) : router_(router) { - router_->addHandler(this); } ~Responder() { + } + + /** + * Starts the responder. + * + * After the responder has started, it will start receiving and responding to requests. + * + * \see stop() + */ + void start() { + router_->addHandler(this); + } + + /** + * Stops the responder. + * + * When the responder is stopped, it will no longer receive incoming requests. + * + * \see start() + */ + void stop() { router_->removeHandler(this); } protected: + /** + * Handle an incoming IQ-Get request containing a payload of class PAYLOAD_TYPE. + * + * This method is implemented in the concrete subclasses. + */ virtual bool handleGetRequest(const JID& from, const String& id, boost::shared_ptr<PAYLOAD_TYPE> payload) = 0; + + /** + * Handle an incoming IQ-Set request containing a payload of class PAYLOAD_TYPE. + * + * This method is implemented in the concrete subclasses. + */ virtual bool handleSetRequest(const JID& from, const String& id, boost::shared_ptr<PAYLOAD_TYPE> payload) = 0; - void sendResponse(const JID& to, const String& id, boost::shared_ptr<Payload> payload) { + /** + * Convenience function for sending an IQ response. + */ + void sendResponse(const JID& to, const String& id, boost::shared_ptr<PAYLOAD_TYPE> payload) { router_->sendIQ(IQ::createResult(to, id, payload)); } + /** + * Convenience function for responding with an error. + */ void sendError(const JID& to, const String& id, ErrorPayload::Condition condition, ErrorPayload::Type type) { router_->sendIQ(IQ::createError(to, id, condition, type)); } @@ -60,5 +105,3 @@ namespace Swift { IQRouter* router_; }; } - -#endif |