diff options
Diffstat (limited to 'Swiften/Queries/IQRouter.cpp')
-rw-r--r-- | Swiften/Queries/IQRouter.cpp | 95 |
1 files changed, 47 insertions, 48 deletions
diff --git a/Swiften/Queries/IQRouter.cpp b/Swiften/Queries/IQRouter.cpp index b6b957e..286b65f 100644 --- a/Swiften/Queries/IQRouter.cpp +++ b/Swiften/Queries/IQRouter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -9,86 +9,85 @@ #include <boost/bind.hpp> #include <Swiften/Base/Algorithm.h> -#include <Swiften/Base/foreach.h> -#include <Swiften/Queries/IQHandler.h> -#include <Swiften/Queries/IQChannel.h> #include <Swiften/Elements/ErrorPayload.h> +#include <Swiften/Queries/IQChannel.h> +#include <Swiften/Queries/IQHandler.h> namespace Swift { static void noop(IQHandler*) {} IQRouter::IQRouter(IQChannel* channel) : channel_(channel), queueRemoves_(false) { - channel->onIQReceived.connect(boost::bind(&IQRouter::handleIQ, this, _1)); + channel->onIQReceived.connect(boost::bind(&IQRouter::handleIQ, this, _1)); } IQRouter::~IQRouter() { - channel_->onIQReceived.disconnect(boost::bind(&IQRouter::handleIQ, this, _1)); + channel_->onIQReceived.disconnect(boost::bind(&IQRouter::handleIQ, this, _1)); } bool IQRouter::isAvailable() { - return channel_->isAvailable(); + return channel_->isAvailable(); } -void IQRouter::handleIQ(boost::shared_ptr<IQ> iq) { - queueRemoves_ = true; - - bool handled = false; - // Go through the handlers in reverse order, to give precedence to the last added handler - std::vector<boost::shared_ptr<IQHandler> >::const_reverse_iterator i = handlers_.rbegin(); - std::vector<boost::shared_ptr<IQHandler> >::const_reverse_iterator rend = handlers_.rend(); - for (; i != rend; ++i) { - handled |= (*i)->handleIQ(iq); - if (handled) { - break; - } - } - if (!handled && (iq->getType() == IQ::Get || iq->getType() == IQ::Set) ) { - sendIQ(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::FeatureNotImplemented, ErrorPayload::Cancel)); - } - - processPendingRemoves(); - - queueRemoves_ = false; +void IQRouter::handleIQ(std::shared_ptr<IQ> iq) { + queueRemoves_ = true; + + bool handled = false; + // Go through the handlers in reverse order, to give precedence to the last added handler + std::vector<std::shared_ptr<IQHandler> >::const_reverse_iterator i = handlers_.rbegin(); + std::vector<std::shared_ptr<IQHandler> >::const_reverse_iterator rend = handlers_.rend(); + for (; i != rend; ++i) { + handled |= (*i)->handleIQ(iq); + if (handled) { + break; + } + } + if (!handled && (iq->getType() == IQ::Get || iq->getType() == IQ::Set) ) { + sendIQ(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::FeatureNotImplemented, ErrorPayload::Cancel)); + } + + processPendingRemoves(); + + queueRemoves_ = false; } void IQRouter::processPendingRemoves() { - foreach(boost::shared_ptr<IQHandler> handler, queuedRemoves_) { - erase(handlers_, handler); - } - queuedRemoves_.clear(); + for (auto&& handler : queuedRemoves_) { + erase(handlers_, handler); + } + queuedRemoves_.clear(); } void IQRouter::addHandler(IQHandler* handler) { - addHandler(boost::shared_ptr<IQHandler>(handler, noop)); + addHandler(std::shared_ptr<IQHandler>(handler, noop)); } void IQRouter::removeHandler(IQHandler* handler) { - removeHandler(boost::shared_ptr<IQHandler>(handler, noop)); + removeHandler(std::shared_ptr<IQHandler>(handler, noop)); } -void IQRouter::addHandler(boost::shared_ptr<IQHandler> handler) { - handlers_.push_back(handler); +void IQRouter::addHandler(std::shared_ptr<IQHandler> handler) { + handlers_.push_back(handler); } -void IQRouter::removeHandler(boost::shared_ptr<IQHandler> handler) { - if (queueRemoves_) { - queuedRemoves_.push_back(handler); - } - else { - erase(handlers_, handler); - } +void IQRouter::removeHandler(std::shared_ptr<IQHandler> handler) { + if (queueRemoves_) { + queuedRemoves_.push_back(handler); + } + else { + erase(handlers_, handler); + } } -void IQRouter::sendIQ(boost::shared_ptr<IQ> iq) { - if (from_.isValid() && !iq->getFrom().isValid()) { - iq->setFrom(from_); - } - channel_->sendIQ(iq); +void IQRouter::sendIQ(std::shared_ptr<IQ> iq) { + if (from_.isValid() && !iq->getFrom().isValid()) { + iq->setFrom(from_); + } + channel_->sendIQ(iq); } std::string IQRouter::getNewIQID() { - return channel_->getNewIQID(); + return channel_->getNewIQID(); } } |