summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Queries/IQRouter.cpp5
-rw-r--r--Swiften/Queries/UnitTest/IQRouterTest.cpp8
2 files changed, 7 insertions, 6 deletions
diff --git a/Swiften/Queries/IQRouter.cpp b/Swiften/Queries/IQRouter.cpp
index a1689e9..7fa2dcf 100644
--- a/Swiften/Queries/IQRouter.cpp
+++ b/Swiften/Queries/IQRouter.cpp
@@ -33,8 +33,9 @@ void IQRouter::handleIQ(boost::shared_ptr<IQ> iq) {
queueRemoves_ = true;
bool handled = false;
- foreach(boost::shared_ptr<IQHandler> handler, handlers_) {
- handled |= handler->handleIQ(iq);
+ // Go through the handlers in reverse order, to give precedence to the last added handler
+ for (std::vector<boost::shared_ptr<IQHandler> >::const_reverse_iterator i = handlers_.rbegin(); i != handlers_.rend(); ++i) {
+ handled |= (*i)->handleIQ(iq);
if (handled) {
break;
}
diff --git a/Swiften/Queries/UnitTest/IQRouterTest.cpp b/Swiften/Queries/UnitTest/IQRouterTest.cpp
index 2d6b2cb..864108c 100644
--- a/Swiften/Queries/UnitTest/IQRouterTest.cpp
+++ b/Swiften/Queries/UnitTest/IQRouterTest.cpp
@@ -54,8 +54,8 @@ class IQRouterTest : public CppUnit::TestFixture
void testRemoveHandler_AfterHandleIQ() {
IQRouter testling(channel_);
- DummyIQHandler handler1(true, &testling);
DummyIQHandler handler2(true, &testling);
+ DummyIQHandler handler1(true, &testling);
channel_->onIQReceived(boost::shared_ptr<IQ>(new IQ()));
testling.removeHandler(&handler1);
@@ -67,8 +67,8 @@ class IQRouterTest : public CppUnit::TestFixture
void testHandleIQ_SuccesfulHandlerFirst() {
IQRouter testling(channel_);
- DummyIQHandler handler1(true, &testling);
DummyIQHandler handler2(false, &testling);
+ DummyIQHandler handler1(true, &testling);
channel_->onIQReceived(boost::shared_ptr<IQ>(new IQ()));
@@ -79,8 +79,8 @@ class IQRouterTest : public CppUnit::TestFixture
void testHandleIQ_SuccesfulHandlerLast() {
IQRouter testling(channel_);
- DummyIQHandler handler1(false, &testling);
DummyIQHandler handler2(true, &testling);
+ DummyIQHandler handler1(false, &testling);
channel_->onIQReceived(boost::shared_ptr<IQ>(new IQ()));
@@ -102,8 +102,8 @@ class IQRouterTest : public CppUnit::TestFixture
void testHandleIQ_HandlerRemovedDuringHandle() {
IQRouter testling(channel_);
- RemovingIQHandler handler1(&testling);
DummyIQHandler handler2(true, &testling);
+ RemovingIQHandler handler1(&testling);
channel_->onIQReceived(boost::shared_ptr<IQ>(new IQ()));
channel_->onIQReceived(boost::shared_ptr<IQ>(new IQ()));