diff options
Diffstat (limited to 'Swiften/Queries')
-rw-r--r-- | Swiften/Queries/GenericRequest.h | 5 | ||||
-rw-r--r-- | Swiften/Queries/Request.cpp | 14 | ||||
-rw-r--r-- | Swiften/Queries/Request.h | 12 | ||||
-rw-r--r-- | Swiften/Queries/Requests/GetDiscoInfoRequest.h | 4 | ||||
-rw-r--r-- | Swiften/Queries/Requests/GetRosterRequest.h | 4 | ||||
-rw-r--r-- | Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h | 5 |
6 files changed, 20 insertions, 24 deletions
diff --git a/Swiften/Queries/GenericRequest.h b/Swiften/Queries/GenericRequest.h index c81760f..b4a1918 100644 --- a/Swiften/Queries/GenericRequest.h +++ b/Swiften/Queries/GenericRequest.h @@ -13,9 +13,8 @@ namespace Swift { IQ::Type type, const JID& receiver, boost::shared_ptr<Payload> payload, - IQRouter* router, - AutoDeleteBehavior autoDeleteBehavior = DoNotAutoDelete) : - Request(type, receiver, payload, router, autoDeleteBehavior) { + IQRouter* router) : + Request(type, receiver, payload, router) { } virtual void handleResponse(boost::shared_ptr<Payload> payload, boost::optional<Error> error) { diff --git a/Swiften/Queries/Request.cpp b/Swiften/Queries/Request.cpp index a788e91..4235c6f 100644 --- a/Swiften/Queries/Request.cpp +++ b/Swiften/Queries/Request.cpp @@ -4,7 +4,7 @@ namespace Swift { -Request::Request(IQ::Type type, const JID& receiver, boost::shared_ptr<Payload> payload, IQRouter* router, AutoDeleteBehavior autoDeleteBehavior) : router_(router), type_(type), receiver_(receiver), payload_(payload), autoDeleteBehavior_(autoDeleteBehavior), sent_(false) { +Request::Request(IQ::Type type, const JID& receiver, boost::shared_ptr<Payload> payload, IQRouter* router) : router_(router), type_(type), receiver_(receiver), payload_(payload), sent_(false) { } void Request::send() { @@ -16,7 +16,14 @@ void Request::send() { iq->addPayload(payload_); id_ = router_->getNewIQID(); iq->setID(id_); - router_->addHandler(this); + + try { + router_->addHandler(shared_from_this()); + } + catch (const std::exception&) { + router_->addHandler(this); + } + router_->sendIQ(iq); } @@ -31,9 +38,6 @@ bool Request::handleIQ(boost::shared_ptr<IQ> iq) { handleResponse(boost::shared_ptr<Payload>(), boost::optional<Error>(Error::UndefinedCondition)); } router_->removeHandler(this); - if (autoDeleteBehavior_ == AutoDeleteAfterResponse) { - MainEventLoop::deleteLater(this); - } handled = true; } return handled; diff --git a/Swiften/Queries/Request.h b/Swiften/Queries/Request.h index 52d1d15..1c972dc 100644 --- a/Swiften/Queries/Request.h +++ b/Swiften/Queries/Request.h @@ -3,6 +3,7 @@ #include <boost/shared_ptr.hpp> #include <boost/optional.hpp> +#include <boost/enable_shared_from_this.hpp> #include "Swiften/Base/String.h" #include "Swiften/Queries/IQHandler.h" @@ -12,19 +13,13 @@ #include "Swiften/JID/JID.h" namespace Swift { - class Request : public IQHandler { + class Request : public IQHandler, public boost::enable_shared_from_this<Request> { public: - enum AutoDeleteBehavior { - DoNotAutoDelete, - AutoDeleteAfterResponse - }; - Request( IQ::Type type, const JID& receiver, boost::shared_ptr<Payload> payload, - IQRouter* router, - AutoDeleteBehavior = DoNotAutoDelete); + IQRouter* router); void send(); @@ -39,7 +34,6 @@ namespace Swift { IQ::Type type_; JID receiver_; boost::shared_ptr<Payload> payload_; - AutoDeleteBehavior autoDeleteBehavior_; String id_; bool sent_; }; diff --git a/Swiften/Queries/Requests/GetDiscoInfoRequest.h b/Swiften/Queries/Requests/GetDiscoInfoRequest.h index 0e8508e..386dd10 100644 --- a/Swiften/Queries/Requests/GetDiscoInfoRequest.h +++ b/Swiften/Queries/Requests/GetDiscoInfoRequest.h @@ -7,8 +7,8 @@ namespace Swift { class GetDiscoInfoRequest : public GenericRequest<DiscoInfo> { public: - GetDiscoInfoRequest(const JID& jid, IQRouter* router, AutoDeleteBehavior autoDeleteBehavior = DoNotAutoDelete) : - GenericRequest<DiscoInfo>(IQ::Get, jid, boost::shared_ptr<DiscoInfo>(new DiscoInfo()), router, autoDeleteBehavior) { + GetDiscoInfoRequest(const JID& jid, IQRouter* router) : + GenericRequest<DiscoInfo>(IQ::Get, jid, boost::shared_ptr<DiscoInfo>(new DiscoInfo()), router) { } }; } diff --git a/Swiften/Queries/Requests/GetRosterRequest.h b/Swiften/Queries/Requests/GetRosterRequest.h index 2364d81..4ebb25e 100644 --- a/Swiften/Queries/Requests/GetRosterRequest.h +++ b/Swiften/Queries/Requests/GetRosterRequest.h @@ -7,8 +7,8 @@ namespace Swift { class GetRosterRequest : public GenericRequest<RosterPayload> { public: - GetRosterRequest(IQRouter* router, AutoDeleteBehavior autoDeleteBehavior = DoNotAutoDelete) : - GenericRequest<RosterPayload>(IQ::Get, JID(), boost::shared_ptr<Payload>(new RosterPayload()), router, autoDeleteBehavior) { + GetRosterRequest(IQRouter* router) : + GenericRequest<RosterPayload>(IQ::Get, JID(), boost::shared_ptr<Payload>(new RosterPayload()), router) { } }; } diff --git a/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h b/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h index 53ca3eb..3971c9d 100644 --- a/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h +++ b/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h @@ -9,10 +9,9 @@ namespace Swift { public: GetSecurityLabelsCatalogRequest( const JID& recipient, - IQRouter* router, - AutoDeleteBehavior autoDeleteBehavior = DoNotAutoDelete) : + IQRouter* router) : GenericRequest<SecurityLabelsCatalog>( - IQ::Get, JID(), boost::shared_ptr<SecurityLabelsCatalog>(new SecurityLabelsCatalog(recipient)), router, autoDeleteBehavior) { + IQ::Get, JID(), boost::shared_ptr<SecurityLabelsCatalog>(new SecurityLabelsCatalog(recipient)), router) { } }; } |