summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-06-12 07:46:07 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-06-12 07:50:13 (GMT)
commit3260f09c55a6f06d9c3ac10f2eddbda68d94de4d (patch)
tree3f502e41a813d54d5a8efd2ca41f469dfefe16c5 /Swiften/Queries/Responder.h
parente9a402583b02866c87475711c57b04f499e846ef (diff)
downloadswift-3260f09c55a6f06d9c3ac10f2eddbda68d94de4d.zip
swift-3260f09c55a6f06d9c3ac10f2eddbda68d94de4d.tar.bz2
Do not register IQHandler in the constructor.
This can get us in all kinds of trouble, including that it makes it impossible to use shared_ptr<> for Requests.
Diffstat (limited to 'Swiften/Queries/Responder.h')
-rw-r--r--Swiften/Queries/Responder.h17
1 files changed, 13 insertions, 4 deletions
diff --git a/Swiften/Queries/Responder.h b/Swiften/Queries/Responder.h
index b6029ae..e6e8ca6 100644
--- a/Swiften/Queries/Responder.h
+++ b/Swiften/Queries/Responder.h
@@ -2,13 +2,19 @@
#define SWIFTEN_Responder_H
#include "Swiften/Queries/IQHandler.h"
+#include "Swiften/Queries/IQRouter.h"
#include "Swiften/Elements/Error.h"
namespace Swift {
template<typename PAYLOAD_TYPE>
class Responder : public IQHandler {
public:
- Responder(IQRouter* router) : IQHandler(router) {
+ Responder(IQRouter* router) : router_(router) {
+ router_->addHandler(this);
+ }
+
+ ~Responder() {
+ router_->removeHandler(this);
}
protected:
@@ -16,11 +22,11 @@ namespace Swift {
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) {
- getRouter()->sendIQ(IQ::createResult(to, id, payload));
+ router_->sendIQ(IQ::createResult(to, id, payload));
}
void sendError(const JID& to, const String& id, Error::Condition condition, Error::Type type) {
- getRouter()->sendIQ(IQ::createError(to, id, condition, type));
+ router_->sendIQ(IQ::createError(to, id, condition, type));
}
private:
@@ -36,13 +42,16 @@ namespace Swift {
result = handleGetRequest(iq->getFrom(), iq->getID(), payload);
}
if (!result) {
- getRouter()->sendIQ(IQ::createError(iq->getFrom(), iq->getID(), Error::NotAllowed, Error::Cancel));
+ router_->sendIQ(IQ::createError(iq->getFrom(), iq->getID(), Error::NotAllowed, Error::Cancel));
}
return true;
}
}
return false;
}
+
+ private:
+ IQRouter* router_;
};
}