diff options
author | Kevin Smith <git@kismith.co.uk> | 2012-03-06 08:59:26 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-03-06 08:59:26 (GMT) |
commit | 54b16ff807d7f70ac7633292d773b7affece1c43 (patch) | |
tree | 566cecbcb46a0c67c48a1251361bee93b409d848 | |
parent | 3b308419485ce1ad50ee14488595a555777ef731 (diff) | |
download | swift-contrib-54b16ff807d7f70ac7633292d773b7affece1c43.zip swift-contrib-54b16ff807d7f70ac7633292d773b7affece1c43.tar.bz2 |
don't crash if an AdHoc is deleted while inflight
-rw-r--r-- | Swiften/AdHoc/OutgoingAdHocCommandSession.cpp | 9 | ||||
-rw-r--r-- | Swiften/AdHoc/OutgoingAdHocCommandSession.h | 3 |
2 files changed, 10 insertions, 2 deletions
diff --git a/Swiften/AdHoc/OutgoingAdHocCommandSession.cpp b/Swiften/AdHoc/OutgoingAdHocCommandSession.cpp index ecc6cd0..cd6b4a3 100644 --- a/Swiften/AdHoc/OutgoingAdHocCommandSession.cpp +++ b/Swiften/AdHoc/OutgoingAdHocCommandSession.cpp @@ -11,18 +11,22 @@ #include <Swiften/Queries/GenericRequest.h> #include <Swiften/Base/Algorithm.h> namespace Swift { OutgoingAdHocCommandSession::OutgoingAdHocCommandSession(const JID& to, const std::string& commandNode, IQRouter* iqRouter) : to_(to), commandNode_(commandNode), iqRouter_(iqRouter), isMultiStage_(false) { } +OutgoingAdHocCommandSession::~OutgoingAdHocCommandSession() { + connection_.disconnect(); +} + void OutgoingAdHocCommandSession::handleResponse(boost::shared_ptr<Command> payload, ErrorPayload::ref error) { if (error) { onError(error); } else { const std::vector<Command::Action>& actions = payload->getAvailableActions(); actionStates_.clear(); if (payload->getStatus() == Command::Executing ) { actionStates_[Command::Cancel] = EnabledAndPresent; actionStates_[Command::Complete] = Present; @@ -52,19 +56,19 @@ void OutgoingAdHocCommandSession::handleResponse(boost::shared_ptr<Command> payl } } bool OutgoingAdHocCommandSession::getIsMultiStage() const { return isMultiStage_; } void OutgoingAdHocCommandSession::start() { boost::shared_ptr<GenericRequest<Command> > commandRequest = boost::make_shared< GenericRequest<Command> >(IQ::Set, to_, boost::make_shared<Command>(commandNode_), iqRouter_); - commandRequest->onResponse.connect(boost::bind(&OutgoingAdHocCommandSession::handleResponse, this, _1, _2)); + connection_ = commandRequest->onResponse.connect(boost::bind(&OutgoingAdHocCommandSession::handleResponse, this, _1, _2)); commandRequest->send(); } void OutgoingAdHocCommandSession::cancel() { if (!sessionID_.empty()) { submitForm(Form::ref(), Command::Cancel); } } @@ -78,18 +82,19 @@ void OutgoingAdHocCommandSession::complete(Form::ref form) { void OutgoingAdHocCommandSession::goNext(Form::ref form) { submitForm(form, Command::Next); } void OutgoingAdHocCommandSession::submitForm(Form::ref form, Command::Action action) { boost::shared_ptr<Command> command(boost::make_shared<Command>(commandNode_, sessionID_, action)); command->setForm(form); boost::shared_ptr<GenericRequest<Command> > commandRequest = boost::make_shared< GenericRequest<Command> >(IQ::Set, to_, command, iqRouter_); - commandRequest->onResponse.connect(boost::bind(&OutgoingAdHocCommandSession::handleResponse, this, _1, _2)); + connection_.disconnect(); + connection_ = commandRequest->onResponse.connect(boost::bind(&OutgoingAdHocCommandSession::handleResponse, this, _1, _2)); commandRequest->send(); } OutgoingAdHocCommandSession::ActionState OutgoingAdHocCommandSession::getActionState(Command::Action action) const { return get(actionStates_, action, Absent); } } diff --git a/Swiften/AdHoc/OutgoingAdHocCommandSession.h b/Swiften/AdHoc/OutgoingAdHocCommandSession.h index a64eb4e..7c7cc99 100644 --- a/Swiften/AdHoc/OutgoingAdHocCommandSession.h +++ b/Swiften/AdHoc/OutgoingAdHocCommandSession.h @@ -8,18 +8,19 @@ #include <boost/shared_ptr.hpp> #include <string> #include <map> #include <Swiften/JID/JID.h> #include <Swiften/Base/boost_bsignals.h> #include <Swiften/Elements/Command.h> #include <Swiften/Elements/ErrorPayload.h> +#include <boost/signals/connection.hpp> namespace Swift { class IQRouter; class MainWindow; class UIEventStream; class OutgoingAdHocCommandSession { public: @@ -27,18 +28,19 @@ namespace Swift { * Availability of action. */ enum ActionState { Absent /** Action isn't applicable to this command. */ = 0, Present /** Action is applicable to this command */= 1, Enabled /** Action is applicable and currently available */ = 2, EnabledAndPresent = 3}; OutgoingAdHocCommandSession(const JID& to, const std::string& commandNode, IQRouter* iqRouter); + ~OutgoingAdHocCommandSession(); /** * Send initial request to the target. */ void start(); /** * Cancel command session with the target. */ void cancel(); /** @@ -85,11 +87,12 @@ namespace Swift { void submitForm(Form::ref, Command::Action action); private: JID to_; std::string commandNode_; IQRouter* iqRouter_; bool isMultiStage_; std::string sessionID_; std::map<Command::Action, ActionState> actionStates_; + boost::bsignals::connection connection_; }; } |