summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-06-12 09:18:57 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-06-12 09:35:26 (GMT)
commitf5dbf49d8e5d88e8ea45a029a5436e91f2754293 (patch)
treeea363efb0b4880d46cccb4bb92cb1b450f937a2b /Swiften/Queries
parent0fa21303c2ea99ff8b89507889de82f768978f23 (diff)
downloadswift-contrib-f5dbf49d8e5d88e8ea45a029a5436e91f2754293.zip
swift-contrib-f5dbf49d8e5d88e8ea45a029a5436e91f2754293.tar.bz2
Allow IQHandlers to be passed as shared_ptr<> to IQRouter.
Diffstat (limited to 'Swiften/Queries')
-rw-r--r--Swiften/Queries/IQRouter.cpp21
-rw-r--r--Swiften/Queries/IQRouter.h4
2 files changed, 22 insertions, 3 deletions
diff --git a/Swiften/Queries/IQRouter.cpp b/Swiften/Queries/IQRouter.cpp
index b474640..671566a 100644
--- a/Swiften/Queries/IQRouter.cpp
+++ b/Swiften/Queries/IQRouter.cpp
@@ -10,13 +10,22 @@
namespace Swift {
+namespace {
+ void noop(IQHandler*) {}
+ struct PointerEquals {
+ PointerEquals(IQHandler* handler) : handler_(handler) {}
+ bool operator()(boost::shared_ptr<IQHandler> o) { return handler_ == o.get(); }
+ IQHandler* handler_;
+ };
+}
+
IQRouter::IQRouter(IQChannel* channel) : channel_(channel) {
channel->onIQReceived.connect(boost::bind(&IQRouter::handleIQ, this, _1));
}
void IQRouter::handleIQ(boost::shared_ptr<IQ> iq) {
bool handled = false;
- foreach(IQHandler* handler, handlers_) {
+ foreach(boost::shared_ptr<IQHandler> handler, handlers_) {
handled |= handler->handleIQ(iq);
if (handled) {
break;
@@ -28,11 +37,19 @@ void IQRouter::handleIQ(boost::shared_ptr<IQ> iq) {
}
void IQRouter::addHandler(IQHandler* handler) {
+ handlers_.push_back(boost::shared_ptr<IQHandler>(handler, noop));
+}
+
+void IQRouter::addHandler(boost::shared_ptr<IQHandler> handler) {
handlers_.push_back(handler);
}
void IQRouter::removeHandler(IQHandler* handler) {
- handlers_.erase(std::remove(handlers_.begin(), handlers_.end(), handler), handlers_.end());
+ handlers_.erase(std::remove_if(handlers_.begin(), handlers_.end(), PointerEquals(handler)), handlers_.end());
+}
+
+void IQRouter::removeHandler(boost::shared_ptr<IQHandler> handler) {
+ handlers_.erase(std::remove(handlers_.begin(), handlers_.end(), handler));
}
void IQRouter::sendIQ(boost::shared_ptr<IQ> iq) {
diff --git a/Swiften/Queries/IQRouter.h b/Swiften/Queries/IQRouter.h
index 2240dfb..ea80bf5 100644
--- a/Swiften/Queries/IQRouter.h
+++ b/Swiften/Queries/IQRouter.h
@@ -16,7 +16,9 @@ namespace Swift {
IQRouter(IQChannel* channel);
void addHandler(IQHandler* handler);
+ void addHandler(boost::shared_ptr<IQHandler> handler);
void removeHandler(IQHandler* handler);
+ void removeHandler(boost::shared_ptr<IQHandler> handler);
void sendIQ(boost::shared_ptr<IQ> iq);
String getNewIQID();
@@ -26,7 +28,7 @@ namespace Swift {
private:
IQChannel* channel_;
- std::vector<IQHandler*> handlers_;
+ std::vector< boost::shared_ptr<IQHandler> > handlers_;
};
}