summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-09-30 20:58:49 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-09-30 21:04:33 (GMT)
commita1b590f2e469191381b5eb8613b5618ffbcafcc4 (patch)
tree3aa0843c76524d817f0713d6d061cdc380c13a59 /Swiften/Disco/DiscoServiceWalker.h
parentd0081aeea512cc367a1aa9939693d8247b0571af (diff)
downloadswift-a1b590f2e469191381b5eb8613b5618ffbcafcc4.zip
swift-a1b590f2e469191381b5eb8613b5618ffbcafcc4.tar.bz2
Moved DiscoServiceWalker to Swiften.
Diffstat (limited to 'Swiften/Disco/DiscoServiceWalker.h')
-rw-r--r--Swiften/Disco/DiscoServiceWalker.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/Swiften/Disco/DiscoServiceWalker.h b/Swiften/Disco/DiscoServiceWalker.h
new file mode 100644
index 0000000..fd749fc
--- /dev/null
+++ b/Swiften/Disco/DiscoServiceWalker.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2010 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <vector>
+#include <set>
+
+#include <boost/shared_ptr.hpp>
+#include <Swiften/Base/boost_bsignals.h>
+#include <string>
+#include <Swiften/JID/JID.h>
+#include <Swiften/Elements/DiscoInfo.h>
+#include <Swiften/Elements/DiscoItems.h>
+#include <Swiften/Elements/ErrorPayload.h>
+#include <Swiften/Disco/GetDiscoInfoRequest.h>
+#include <Swiften/Disco/GetDiscoItemsRequest.h>
+
+namespace Swift {
+ class IQRouter;
+ /**
+ * Recursively walk service discovery trees to find all services offered.
+ * This stops on any disco item that's not reporting itself as a server.
+ */
+ class DiscoServiceWalker {
+ public:
+ DiscoServiceWalker(const JID& service, IQRouter* iqRouter, size_t maxSteps = 200);
+
+ /**
+ * Start the walk.
+ *
+ * Call this exactly once.
+ */
+ void beginWalk();
+
+ /**
+ * End the walk.
+ */
+ void endWalk();
+
+ bool isActive() const {
+ return active_;
+ }
+
+ /** Emitted for each service found. */
+ boost::signal<void(const JID&, boost::shared_ptr<DiscoInfo>)> onServiceFound;
+
+ /** Emitted when walking is complete.*/
+ boost::signal<void()> onWalkComplete;
+
+ private:
+ void walkNode(const JID& jid);
+ void markNodeCompleted(const JID& jid);
+ void handleDiscoInfoResponse(boost::shared_ptr<DiscoInfo> info, ErrorPayload::ref error, GetDiscoInfoRequest::ref request);
+ void handleDiscoItemsResponse(boost::shared_ptr<DiscoItems> items, ErrorPayload::ref error, GetDiscoItemsRequest::ref request);
+ void handleDiscoError(const JID& jid, ErrorPayload::ref error);
+
+ private:
+ JID service_;
+ IQRouter* iqRouter_;
+ size_t maxSteps_;
+ bool active_;
+ std::set<JID> servicesBeingSearched_;
+ std::set<JID> searchedServices_;
+ std::set<GetDiscoInfoRequest::ref> pendingDiscoInfoRequests_;
+ std::set<GetDiscoItemsRequest::ref> pendingDiscoItemsRequests_;
+ };
+}