diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-06-01 08:48:42 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-06-01 09:24:28 (GMT) |
commit | 2812bddd81f8a1b804c7460f4e14cd0aa393d129 (patch) | |
tree | d46294f35150c4f0f43deaf2d31fceaf945ae715 /Swiften/Examples/TuneBot | |
download | swift-2812bddd81f8a1b804c7460f4e14cd0aa393d129.zip swift-2812bddd81f8a1b804c7460f4e14cd0aa393d129.tar.bz2 |
Import.
Diffstat (limited to 'Swiften/Examples/TuneBot')
-rw-r--r-- | Swiften/Examples/TuneBot/Makefile.inc | 11 | ||||
-rw-r--r-- | Swiften/Examples/TuneBot/TuneBot.cpp | 72 |
2 files changed, 83 insertions, 0 deletions
diff --git a/Swiften/Examples/TuneBot/Makefile.inc b/Swiften/Examples/TuneBot/Makefile.inc new file mode 100644 index 0000000..c7c00c7 --- /dev/null +++ b/Swiften/Examples/TuneBot/Makefile.inc @@ -0,0 +1,11 @@ +TUNEBOT_TARGET = Swiften/Examples/TuneBot/TuneBot +TUNEBOT_SOURCES += \ + Swiften/Examples/TuneBot/TuneBot.cpp +TUNEBOT_OBJECTS = \ + $(TUNEBOT_SOURCES:.cpp=.o) + +CLEANFILES += $(TUNEBOT_OBJECTS) $(TUNEBOT_TARGET) +EXAMPLES_TARGETS += $(TUNEBOT_TARGET) + +$(TUNEBOT_TARGET): $(SWIFTEN_TARGET) $(TUNEBOT_OBJECTS) + $(QUIET_LINK)$(CXX) -o $(TUNEBOT_TARGET) $(TUNEBOT_OBJECTS) $(LDFLAGS) $(CPPCLIENT_LDFLAGS) $(SWIFTEN_TARGET) $(LIBS) diff --git a/Swiften/Examples/TuneBot/TuneBot.cpp b/Swiften/Examples/TuneBot/TuneBot.cpp new file mode 100644 index 0000000..d2bb100 --- /dev/null +++ b/Swiften/Examples/TuneBot/TuneBot.cpp @@ -0,0 +1,72 @@ +#include <boost/bind.hpp> +#include <boost/thread.hpp> + +#include "Swiften/Client/Client.h" +#include "Swiften/EventLoop/SimpleEventLoop.h" +#include "Swiften/EventLoop/MainEventLoop.h" +#include "Swiften/Queries/Requests/GetRosterRequest.h" +#include "Swiften/Queries/IQRouter.h" +#include "Swiften/Elements/DiscoInfo.h" +#include "Swiften/Elements/CapsInfo.h" +#include "Swiften/Queries/Responders/DiscoInfoResponder.h" +#include "Swiften/Disco/CapsInfoGenerator.h" + +using namespace Swift; +using namespace boost; + +class TuneBot { + public: + TuneBot(const JID& jid, const String& password) { + client_ = new Client(jid, password); + router_ = new IQRouter(client_); + + DiscoInfo discoInfo; + discoInfo.addIdentity(DiscoInfo::Identity("TuneBot", "client", "bot")); + discoInfo.addFeature("http://jabber.org/protocol/tune+notify"); + capsInfo_ = boost::shared_ptr<CapsInfo>(new CapsInfo(CapsInfoGenerator("http://el-tramo.be/tunebot").generateCapsInfo(discoInfo))); + discoResponder_ = new DiscoInfoResponder(router_); + discoResponder_->setDiscoInfo(discoInfo); + discoResponder_->setDiscoInfo(capsInfo_->getNode() + "#" + capsInfo_->getVersion(), discoInfo); + + client_->onSessionStarted.connect(bind(&TuneBot::handleSessionStarted, this)); + client_->onMessageReceived.connect(bind(&TuneBot::handleMessage, this, _1)); + client_->connect(); + } + + void handleSessionStarted() { + GetRosterRequest* rosterRequest = new GetRosterRequest(router_, Request::AutoDeleteAfterResponse); + rosterRequest->onResponse.connect(bind(&TuneBot::handleRosterReceived, this, _1)); + rosterRequest->send(); + } + + void handleRosterReceived(shared_ptr<Payload>) { + boost::shared_ptr<Presence> presence(new Presence()); + presence->addPayload(capsInfo_); + presence->setPriority(-1); + client_->send(presence); + } + + void handleMessage(shared_ptr<Message> message) { + // TODO + } + + private: + Client* client_; + IQRouter* router_; + DiscoInfoResponder* discoResponder_; + boost::shared_ptr<CapsInfo> capsInfo_; +}; + + +int main(int argc, char* argv[]) +{ + if (argc != 3) { + std::cerr << "Usage: " << argv[0] << " <jid> <password>" << std::endl; + return -1; + } + + SimpleEventLoop eventLoop; + + TuneBot bot(argv[1], argv[2]); + eventLoop.run(); +} |