summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-06-12 10:26:41 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-06-12 10:26:41 (GMT)
commit9bc8ddaf40d73647944592385bf56ece41046846 (patch)
tree200c49a14f60754050af71922234d4aadb991bd1
parenteded58915fd89e8b008ba7e078c5967fdef9f4cb (diff)
downloadswift-9bc8ddaf40d73647944592385bf56ece41046846.zip
swift-9bc8ddaf40d73647944592385bf56ece41046846.tar.bz2
Removing auto delete stuff from Request.
This should now be handled properly by using shared_ptrs.
-rw-r--r--Swift/Controllers/ChatControllerBase.cpp2
-rw-r--r--Swift/Controllers/MainController.cpp2
-rw-r--r--Swift/Controllers/XMPPRosterController.cpp2
-rw-r--r--Swiften/QA/ClientTest/ClientTest.cpp2
-rw-r--r--Swiften/Queries/GenericRequest.h5
-rw-r--r--Swiften/Queries/Request.cpp14
-rw-r--r--Swiften/Queries/Request.h12
-rw-r--r--Swiften/Queries/Requests/GetDiscoInfoRequest.h4
-rw-r--r--Swiften/Queries/Requests/GetRosterRequest.h4
-rw-r--r--Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h5
10 files changed, 24 insertions, 28 deletions
diff --git a/Swift/Controllers/ChatControllerBase.cpp b/Swift/Controllers/ChatControllerBase.cpp
index 3b3ddb7..0d22571 100644
--- a/Swift/Controllers/ChatControllerBase.cpp
+++ b/Swift/Controllers/ChatControllerBase.cpp
@@ -26,7 +26,7 @@ void ChatControllerBase::setAvailableServerFeatures(boost::shared_ptr<DiscoInfo>
if (info->hasFeature(DiscoInfo::SecurityLabels)) {
chatWindow_->setSecurityLabelsEnabled(true);
chatWindow_->setSecurityLabelsError();
- GetSecurityLabelsCatalogRequest* request = new GetSecurityLabelsCatalogRequest(JID(toJID_.toBare()), iqRouter_, Request::AutoDeleteAfterResponse);
+ boost::shared_ptr<GetSecurityLabelsCatalogRequest> request(new GetSecurityLabelsCatalogRequest(JID(toJID_.toBare()), iqRouter_));
request->onResponse.connect(boost::bind(&ChatControllerBase::handleSecurityLabelsCatalogResponse, this, _1, _2));
request->send();
labelsEnabled_ = true;
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index e5036a5..ff53450 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -101,7 +101,7 @@ void MainController::handleConnected() {
discoResponder_->setDiscoInfo(capsInfo_->getNode() + "#" + capsInfo_->getVersion(), discoInfo);
serverDiscoInfo_ = boost::shared_ptr<DiscoInfo>(new DiscoInfo());
- GetDiscoInfoRequest* discoInfoRequest = new GetDiscoInfoRequest(JID(), client_, Request::AutoDeleteAfterResponse);
+ boost::shared_ptr<GetDiscoInfoRequest> discoInfoRequest(new GetDiscoInfoRequest(JID(), client_));
discoInfoRequest->onResponse.connect(boost::bind(&MainController::handleServerDiscoInfoResponse, this, _1, _2));
discoInfoRequest->send();
diff --git a/Swift/Controllers/XMPPRosterController.cpp b/Swift/Controllers/XMPPRosterController.cpp
index 46fb40c..e1716e6 100644
--- a/Swift/Controllers/XMPPRosterController.cpp
+++ b/Swift/Controllers/XMPPRosterController.cpp
@@ -26,7 +26,7 @@ XMPPRosterController::XMPPRosterController(IQRouter* iqRouter, boost::shared_ptr
}
void XMPPRosterController::requestRoster() {
- GetRosterRequest* rosterRequest = new GetRosterRequest(iqRouter_, Request::AutoDeleteAfterResponse);
+ boost::shared_ptr<GetRosterRequest> rosterRequest(new GetRosterRequest(iqRouter_));
rosterRequest->onResponse.connect(boost::bind(&XMPPRosterController::handleRosterReceived, this, _1));
rosterRequest->send();
}
diff --git a/Swiften/QA/ClientTest/ClientTest.cpp b/Swiften/QA/ClientTest/ClientTest.cpp
index 20a03a4..d3e8c67 100644
--- a/Swiften/QA/ClientTest/ClientTest.cpp
+++ b/Swiften/QA/ClientTest/ClientTest.cpp
@@ -28,7 +28,7 @@ void handleRosterReceived(boost::shared_ptr<Payload>) {
}
void handleConnected() {
- GetRosterRequest* rosterRequest = new GetRosterRequest(client, Request::AutoDeleteAfterResponse);
+ boost::shared_ptr<GetRosterRequest> rosterRequest(new GetRosterRequest(client));
rosterRequest->onResponse.connect(boost::bind(&handleRosterReceived, _1));
rosterRequest->send();
}
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) {
}
};
}