summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-11-10 21:24:03 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-11-10 21:24:03 (GMT)
commit54781ce12f7654f8136e645d4ebc5934d90c6bea (patch)
tree90bad869f9f64d57a3c0af209b83a538a47c7762 /Swiften/Queries
parentfcfac59db5cb4503554f2b30854b2e91928296f6 (diff)
parent66ced3654ad295478b33d3e4f1716f66ab4048b5 (diff)
downloadswift-54781ce12f7654f8136e645d4ebc5934d90c6bea.zip
swift-54781ce12f7654f8136e645d4ebc5934d90c6bea.tar.bz2
Refactored session management.
Diffstat (limited to 'Swiften/Queries')
-rw-r--r--Swiften/Queries/GenericRequest.h9
-rw-r--r--Swiften/Queries/IQRouter.cpp4
-rw-r--r--Swiften/Queries/Request.cpp4
-rw-r--r--Swiften/Queries/Request.h4
-rw-r--r--Swiften/Queries/Requests/GetPrivateStorageRequest.h6
-rw-r--r--Swiften/Queries/Requests/SetPrivateStorageRequest.h6
-rw-r--r--Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp4
-rw-r--r--Swiften/Queries/Responder.h6
-rw-r--r--Swiften/Queries/Responders/DiscoInfoResponder.cpp2
-rw-r--r--Swiften/Queries/Responders/UnitTest/DiscoInfoResponderTest.cpp2
-rw-r--r--Swiften/Queries/UnitTest/IQRouterTest.cpp2
-rw-r--r--Swiften/Queries/UnitTest/RequestTest.cpp2
12 files changed, 24 insertions, 27 deletions
diff --git a/Swiften/Queries/GenericRequest.h b/Swiften/Queries/GenericRequest.h
index b4a1918..77dae52 100644
--- a/Swiften/Queries/GenericRequest.h
+++ b/Swiften/Queries/GenericRequest.h
@@ -1,8 +1,7 @@
-#ifndef SWIFTEN_GenericRequest_H
-#define SWIFTEN_GenericRequest_H
+#pragma once
#include <boost/signal.hpp>
#include "Swiften/Queries/Request.h"
namespace Swift {
@@ -14,16 +13,14 @@ namespace Swift {
const JID& receiver,
boost::shared_ptr<Payload> payload,
IQRouter* router) :
Request(type, receiver, payload, router) {
}
- virtual void handleResponse(boost::shared_ptr<Payload> payload, boost::optional<Error> error) {
+ virtual void handleResponse(boost::shared_ptr<Payload> payload, boost::optional<ErrorPayload> error) {
onResponse(boost::dynamic_pointer_cast<PAYLOAD_TYPE>(payload), error);
}
public:
- boost::signal<void (boost::shared_ptr<PAYLOAD_TYPE>, const boost::optional<Error>&)> onResponse;
+ boost::signal<void (boost::shared_ptr<PAYLOAD_TYPE>, const boost::optional<ErrorPayload>&)> onResponse;
};
}
-
-#endif
diff --git a/Swiften/Queries/IQRouter.cpp b/Swiften/Queries/IQRouter.cpp
index ffed5f7..fdfa00b 100644
--- a/Swiften/Queries/IQRouter.cpp
+++ b/Swiften/Queries/IQRouter.cpp
@@ -3,13 +3,13 @@
#include <algorithm>
#include <boost/bind.hpp>
#include "Swiften/Base/foreach.h"
#include "Swiften/Queries/IQHandler.h"
#include "Swiften/Queries/IQChannel.h"
-#include "Swiften/Elements/Error.h"
+#include "Swiften/Elements/ErrorPayload.h"
namespace Swift {
static void noop(IQHandler*) {}
IQRouter::IQRouter(IQChannel* channel) : channel_(channel), queueRemoves_(false) {
@@ -31,13 +31,13 @@ void IQRouter::handleIQ(boost::shared_ptr<IQ> iq) {
handled |= handler->handleIQ(iq);
if (handled) {
break;
}
}
if (!handled && (iq->getType() == IQ::Get || iq->getType() == IQ::Set) ) {
- channel_->sendIQ(IQ::createError(iq->getFrom(), iq->getID(), Error::FeatureNotImplemented, Error::Cancel));
+ channel_->sendIQ(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::FeatureNotImplemented, ErrorPayload::Cancel));
}
processPendingRemoves();
queueRemoves_ = false;
}
diff --git a/Swiften/Queries/Request.cpp b/Swiften/Queries/Request.cpp
index 90aa295..18446ae 100644
--- a/Swiften/Queries/Request.cpp
+++ b/Swiften/Queries/Request.cpp
@@ -32,17 +32,17 @@ void Request::send() {
}
bool Request::handleIQ(boost::shared_ptr<IQ> iq) {
bool handled = false;
if (sent_ && iq->getID() == id_) {
if (iq->getType() == IQ::Result) {
- handleResponse(iq->getPayloadOfSameType(payload_), boost::optional<Error>());
+ handleResponse(iq->getPayloadOfSameType(payload_), boost::optional<ErrorPayload>());
}
else {
// FIXME: Get proper error
- handleResponse(boost::shared_ptr<Payload>(), boost::optional<Error>(Error::UndefinedCondition));
+ handleResponse(boost::shared_ptr<Payload>(), boost::optional<ErrorPayload>(ErrorPayload::UndefinedCondition));
}
router_->removeHandler(this);
handled = true;
}
return handled;
}
diff --git a/Swiften/Queries/Request.h b/Swiften/Queries/Request.h
index 8f7a1d1..cc4a58e 100644
--- a/Swiften/Queries/Request.h
+++ b/Swiften/Queries/Request.h
@@ -6,13 +6,13 @@
#include <boost/enable_shared_from_this.hpp>
#include "Swiften/Base/String.h"
#include "Swiften/Queries/IQHandler.h"
#include "Swiften/Elements/IQ.h"
#include "Swiften/Elements/Payload.h"
-#include "Swiften/Elements/Error.h"
+#include "Swiften/Elements/ErrorPayload.h"
#include "Swiften/JID/JID.h"
namespace Swift {
class Request : public IQHandler, public boost::enable_shared_from_this<Request> {
public:
Request(
@@ -29,13 +29,13 @@ namespace Swift {
protected:
virtual void setPayload(boost::shared_ptr<Payload> p) {
payload_ = p;
}
- virtual void handleResponse(boost::shared_ptr<Payload>, boost::optional<Error>) = 0;
+ virtual void handleResponse(boost::shared_ptr<Payload>, boost::optional<ErrorPayload>) = 0;
private:
bool handleIQ(boost::shared_ptr<IQ>);
private:
IQRouter* router_;
diff --git a/Swiften/Queries/Requests/GetPrivateStorageRequest.h b/Swiften/Queries/Requests/GetPrivateStorageRequest.h
index c5f8aef..5d6440e 100644
--- a/Swiften/Queries/Requests/GetPrivateStorageRequest.h
+++ b/Swiften/Queries/Requests/GetPrivateStorageRequest.h
@@ -2,29 +2,29 @@
#include <boost/signals.hpp>
#include <boost/shared_ptr.hpp>
#include "Swiften/Queries/Request.h"
#include "Swiften/Elements/PrivateStorage.h"
-#include "Swiften/Elements/Error.h"
+#include "Swiften/Elements/ErrorPayload.h"
namespace Swift {
template<typename PAYLOAD_TYPE>
class GetPrivateStorageRequest : public Request {
public:
GetPrivateStorageRequest(IQRouter* router) : Request(IQ::Get, JID(), boost::shared_ptr<PrivateStorage>(new PrivateStorage(boost::shared_ptr<Payload>(new PAYLOAD_TYPE()))), router) {
}
- virtual void handleResponse(boost::shared_ptr<Payload> payload, boost::optional<Error> error) {
+ virtual void handleResponse(boost::shared_ptr<Payload> payload, boost::optional<ErrorPayload> error) {
boost::shared_ptr<PrivateStorage> storage = boost::dynamic_pointer_cast<PrivateStorage>(payload);
if (storage) {
onResponse(boost::dynamic_pointer_cast<PAYLOAD_TYPE>(storage->getPayload()), error);
}
else {
onResponse(boost::shared_ptr<PAYLOAD_TYPE>(), error);
}
}
public:
- boost::signal<void (boost::shared_ptr<PAYLOAD_TYPE>, const boost::optional<Error>&)> onResponse;
+ boost::signal<void (boost::shared_ptr<PAYLOAD_TYPE>, const boost::optional<ErrorPayload>&)> onResponse;
};
}
diff --git a/Swiften/Queries/Requests/SetPrivateStorageRequest.h b/Swiften/Queries/Requests/SetPrivateStorageRequest.h
index 63ac8dc..834ddd8 100644
--- a/Swiften/Queries/Requests/SetPrivateStorageRequest.h
+++ b/Swiften/Queries/Requests/SetPrivateStorageRequest.h
@@ -2,23 +2,23 @@
#include <boost/signals.hpp>
#include <boost/shared_ptr.hpp>
#include "Swiften/Queries/Request.h"
#include "Swiften/Elements/PrivateStorage.h"
-#include "Swiften/Elements/Error.h"
+#include "Swiften/Elements/ErrorPayload.h"
namespace Swift {
template<typename PAYLOAD_TYPE>
class SetPrivateStorageRequest : public Request {
public:
SetPrivateStorageRequest(boost::shared_ptr<PAYLOAD_TYPE> payload, IQRouter* router) : Request(IQ::Set, JID(), boost::shared_ptr<PrivateStorage>(new PrivateStorage(payload)), router) {
}
- virtual void handleResponse(boost::shared_ptr<Payload> payload, boost::optional<Error> error) {
+ virtual void handleResponse(boost::shared_ptr<Payload> payload, boost::optional<ErrorPayload> error) {
onResponse(error);
}
public:
- boost::signal<void (const boost::optional<Error>&)> onResponse;
+ boost::signal<void (const boost::optional<ErrorPayload>&)> onResponse;
};
}
diff --git a/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp b/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp
index 14e04cf..a86a111 100644
--- a/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp
+++ b/Swiften/Queries/Requests/UnitTest/GetPrivateStorageRequestTest.cpp
@@ -69,13 +69,13 @@ class GetPrivateStorageRequestTest : public CppUnit::TestFixture
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(responses.size()));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(errors.size()));
}
private:
- void handleResponse(boost::shared_ptr<Payload> p, const boost::optional<Error>& e) {
+ void handleResponse(boost::shared_ptr<Payload> p, const boost::optional<ErrorPayload>& e) {
if (e) {
errors.push_back(*e);
}
else {
responses.push_back(p);
}
@@ -96,11 +96,11 @@ class GetPrivateStorageRequestTest : public CppUnit::TestFixture
return iq;
}
private:
IQRouter* router;
DummyIQChannel* channel;
- std::vector< Error > errors;
+ std::vector< ErrorPayload > errors;
std::vector< boost::shared_ptr<Payload> > responses;
};
CPPUNIT_TEST_SUITE_REGISTRATION(GetPrivateStorageRequestTest);
diff --git a/Swiften/Queries/Responder.h b/Swiften/Queries/Responder.h
index e6e8ca6..9c025eb 100644
--- a/Swiften/Queries/Responder.h
+++ b/Swiften/Queries/Responder.h
@@ -1,12 +1,12 @@
#ifndef SWIFTEN_Responder_H
#define SWIFTEN_Responder_H
#include "Swiften/Queries/IQHandler.h"
#include "Swiften/Queries/IQRouter.h"
-#include "Swiften/Elements/Error.h"
+#include "Swiften/Elements/ErrorPayload.h"
namespace Swift {
template<typename PAYLOAD_TYPE>
class Responder : public IQHandler {
public:
Responder(IQRouter* router) : router_(router) {
@@ -22,13 +22,13 @@ 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) {
router_->sendIQ(IQ::createResult(to, id, payload));
}
- void sendError(const JID& to, const String& id, Error::Condition condition, Error::Type type) {
+ void sendError(const JID& to, const String& id, ErrorPayload::Condition condition, ErrorPayload::Type type) {
router_->sendIQ(IQ::createError(to, id, condition, type));
}
private:
virtual bool handleIQ(boost::shared_ptr<IQ> iq) {
if (iq->getType() == IQ::Set || iq->getType() == IQ::Get) {
@@ -39,13 +39,13 @@ namespace Swift {
result = handleSetRequest(iq->getFrom(), iq->getID(), payload);
}
else {
result = handleGetRequest(iq->getFrom(), iq->getID(), payload);
}
if (!result) {
- router_->sendIQ(IQ::createError(iq->getFrom(), iq->getID(), Error::NotAllowed, Error::Cancel));
+ router_->sendIQ(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::NotAllowed, ErrorPayload::Cancel));
}
return true;
}
}
return false;
}
diff --git a/Swiften/Queries/Responders/DiscoInfoResponder.cpp b/Swiften/Queries/Responders/DiscoInfoResponder.cpp
index a114fbc..572f83f 100644
--- a/Swiften/Queries/Responders/DiscoInfoResponder.cpp
+++ b/Swiften/Queries/Responders/DiscoInfoResponder.cpp
@@ -24,13 +24,13 @@ bool DiscoInfoResponder::handleGetRequest(const JID& from, const String& id, boo
else {
std::map<String,DiscoInfo>::const_iterator i = nodeInfo_.find(info->getNode());
if (i != nodeInfo_.end()) {
sendResponse(from, id, boost::shared_ptr<DiscoInfo>(new DiscoInfo((*i).second)));
}
else {
- sendError(from, id, Error::ItemNotFound, Error::Cancel);
+ sendError(from, id, ErrorPayload::ItemNotFound, ErrorPayload::Cancel);
}
}
return true;
}
}
diff --git a/Swiften/Queries/Responders/UnitTest/DiscoInfoResponderTest.cpp b/Swiften/Queries/Responders/UnitTest/DiscoInfoResponderTest.cpp
index 6ed7b9e..5993d0c 100644
--- a/Swiften/Queries/Responders/UnitTest/DiscoInfoResponderTest.cpp
+++ b/Swiften/Queries/Responders/UnitTest/DiscoInfoResponderTest.cpp
@@ -69,13 +69,13 @@ class DiscoInfoResponderTest : public CppUnit::TestFixture {
boost::shared_ptr<DiscoInfo> query(new DiscoInfo());
query->setNode("bar-node");
channel_->onIQReceived(IQ::createRequest(IQ::Get, JID("foo@bar.com"), "id-1", query));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
- boost::shared_ptr<Error> payload(channel_->iqs_[0]->getPayload<Error>());
+ boost::shared_ptr<ErrorPayload> payload(channel_->iqs_[0]->getPayload<ErrorPayload>());
CPPUNIT_ASSERT(payload);
}
private:
IQRouter* router_;
DummyIQChannel* channel_;
diff --git a/Swiften/Queries/UnitTest/IQRouterTest.cpp b/Swiften/Queries/UnitTest/IQRouterTest.cpp
index 94b7de8..5760b09 100644
--- a/Swiften/Queries/UnitTest/IQRouterTest.cpp
+++ b/Swiften/Queries/UnitTest/IQRouterTest.cpp
@@ -84,13 +84,13 @@ class IQRouterTest : public CppUnit::TestFixture
IQRouter testling(channel_);
DummyIQHandler handler(false, &testling);
channel_->onIQReceived(boost::shared_ptr<IQ>(new IQ()));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
- CPPUNIT_ASSERT(channel_->iqs_[0]->getPayload<Error>());
+ CPPUNIT_ASSERT(channel_->iqs_[0]->getPayload<ErrorPayload>());
}
void testHandleIQ_HandlerRemovedDuringHandle() {
IQRouter testling(channel_);
RemovingIQHandler handler1(&testling);
diff --git a/Swiften/Queries/UnitTest/RequestTest.cpp b/Swiften/Queries/UnitTest/RequestTest.cpp
index ea6dee6..51d5a51 100644
--- a/Swiften/Queries/UnitTest/RequestTest.cpp
+++ b/Swiften/Queries/UnitTest/RequestTest.cpp
@@ -110,13 +110,13 @@ class RequestTest : public CppUnit::TestFixture
CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
CPPUNIT_ASSERT_EQUAL(0, errorsReceived_);
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(channel_->iqs_.size()));
}
private:
- void handleResponse(boost::shared_ptr<Payload> p, const boost::optional<Error>& e) {
+ void handleResponse(boost::shared_ptr<Payload> p, const boost::optional<ErrorPayload>& e) {
if (e) {
++errorsReceived_;
}
else {
boost::shared_ptr<MyPayload> payload(boost::dynamic_pointer_cast<MyPayload>(p));
CPPUNIT_ASSERT(payload);