summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-10-15 20:40:51 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-10-15 20:40:51 (GMT)
commita49ca97a7b2ad61385d0f6f22ec598a63d889ae7 (patch)
tree332ff85114c4bc6cea5a028a10c111786584be57 /Documentation
parent10d8877b9251d5408da9ac3a5eafb066de121bc6 (diff)
downloadswift-contrib-a49ca97a7b2ad61385d0f6f22ec598a63d889ae7.zip
swift-contrib-a49ca97a7b2ad61385d0f6f22ec598a63d889ae7.tar.bz2
Added EchoComponent.
Diffstat (limited to 'Documentation')
-rw-r--r--Documentation/SwiftenDevelopersGuide/Examples/EchoBot/.gitignore1
-rw-r--r--Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoComponent.cpp64
-rw-r--r--Documentation/SwiftenDevelopersGuide/Examples/EchoBot/SConscript1
3 files changed, 66 insertions, 0 deletions
diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/.gitignore b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/.gitignore
index 28275ad..81f2be3 100644
--- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/.gitignore
+++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/.gitignore
@@ -1,2 +1,3 @@
EchoBot?
*.cpp.xml
+EchoComponent
diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoComponent.cpp b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoComponent.cpp
new file mode 100644
index 0000000..67f469d
--- /dev/null
+++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoComponent.cpp
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <iostream>
+#include <boost/bind.hpp>
+
+#include "Swiften/Swiften.h"
+
+using namespace Swift;
+using namespace boost;
+
+class EchoComponent {
+ public:
+ EchoComponent() {
+ component = new Component(JID("echo.wonderland.lit"), "EchoSecret");
+ component->onConnected.connect(bind(&EchoComponent::handleConnected, this));
+ component->onMessageReceived.connect(
+ bind(&EchoComponent::handleMessageReceived, this, _1));
+ component->onPresenceReceived.connect(
+ bind(&EchoComponent::handlePresenceReceived, this, _1));
+ tracer = new ComponentXMLTracer(component);
+ component->connect("wonderland.lit", 5347);
+ }
+
+ ~EchoComponent() {
+ delete tracer;
+ delete component;
+ }
+
+ private:
+ void handlePresenceReceived(Presence::ref presence) {
+ // Automatically approve subscription requests
+ if (presence->getType() == Presence::Subscribe) {
+ Presence::ref response = Presence::create();
+ response->setTo(presence->getFrom());
+ response->setType(Presence::Subscribed);
+ component->sendPresence(response);
+ }
+ }
+
+ void handleConnected() {
+ }
+
+ void handleMessageReceived(Message::ref message) {
+ // Echo back the incoming message
+ message->setTo(message->getFrom());
+ message->setFrom(JID());
+ component->sendMessage(message);
+ }
+
+ private:
+ Component* component;
+ ComponentXMLTracer* tracer;
+};
+
+int main(int, char**) {
+ SimpleEventLoop eventLoop;
+ EchoComponent bot;
+ eventLoop.run();
+ return 0;
+}
diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/SConscript b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/SConscript
index ceead6b..6a3bcb4 100644
--- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/SConscript
+++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/SConscript
@@ -13,3 +13,4 @@ example_env.MergeFlags(example_env["PLATFORM_FLAGS"])
for i in range(1,6) :
example_env.Program("EchoBot" + str(i), ["EchoBot" + str(i) + ".cpp"])
+example_env.Program("EchoComponent", "EchoComponent.cpp")