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 /Swiften
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.
Diffstat (limited to 'Swiften')
-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
7 files changed, 21 insertions, 25 deletions
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) {
}
};
}