00001
00002
00003
00004
00005
00006
00007 #pragma once
00008
00009 #include <vector>
00010 #include <set>
00011
00012 #include <Swiften/Base/API.h>
00013 #include <boost/shared_ptr.hpp>
00014 #include <Swiften/Base/boost_bsignals.h>
00015 #include <string>
00016 #include <Swiften/JID/JID.h>
00017 #include <Swiften/Elements/DiscoInfo.h>
00018 #include <Swiften/Elements/DiscoItems.h>
00019 #include <Swiften/Elements/ErrorPayload.h>
00020 #include <Swiften/Disco/GetDiscoInfoRequest.h>
00021 #include <Swiften/Disco/GetDiscoItemsRequest.h>
00022
00023 namespace Swift {
00024 class IQRouter;
00029 class SWIFTEN_API DiscoServiceWalker {
00030 public:
00031 DiscoServiceWalker(const JID& service, IQRouter* iqRouter, size_t maxSteps = 200);
00032
00038 void beginWalk();
00039
00043 void endWalk();
00044
00045 bool isActive() const {
00046 return active_;
00047 }
00048
00050 boost::signal<void(const JID&, boost::shared_ptr<DiscoInfo>)> onServiceFound;
00051
00053 boost::signal<void()> onWalkComplete;
00054
00055 private:
00056 void walkNode(const JID& jid);
00057 void markNodeCompleted(const JID& jid);
00058 void handleDiscoInfoResponse(boost::shared_ptr<DiscoInfo> info, ErrorPayload::ref error, GetDiscoInfoRequest::ref request);
00059 void handleDiscoItemsResponse(boost::shared_ptr<DiscoItems> items, ErrorPayload::ref error, GetDiscoItemsRequest::ref request);
00060 void handleDiscoError(const JID& jid, ErrorPayload::ref error);
00061
00062 private:
00063 JID service_;
00064 IQRouter* iqRouter_;
00065 size_t maxSteps_;
00066 bool active_;
00067 std::set<JID> servicesBeingSearched_;
00068 std::set<JID> searchedServices_;
00069 std::set<GetDiscoInfoRequest::ref> pendingDiscoInfoRequests_;
00070 std::set<GetDiscoItemsRequest::ref> pendingDiscoItemsRequests_;
00071 };
00072 }