diff options
| author | Remko Tronçon <git@el-tramo.be> | 2010-09-05 12:44:38 (GMT) |
|---|---|---|
| committer | Remko Tronçon <git@el-tramo.be> | 2010-09-05 12:45:53 (GMT) |
| commit | 5b974445a8ce78ca73bdfae9a8114857e4fc3d36 (patch) | |
| tree | b4743fc1f2c34472ab56e1a7b58d1e81666dbce2 | |
| parent | c9ab4b6c41eef3ccfe6627f62e7bc085c6743a41 (diff) | |
| download | swift-5b974445a8ce78ca73bdfae9a8114857e4fc3d36.zip swift-5b974445a8ce78ca73bdfae9a8114857e4fc3d36.tar.bz2 | |
Added EchoBot.
| -rw-r--r-- | Swiften/Examples/EchoBot/EchoBot.cpp | 17 | ||||
| -rw-r--r-- | Swiften/Examples/EchoBot/SConscript | 13 | ||||
| -rw-r--r-- | Swiften/Examples/SConscript | 1 |
3 files changed, 23 insertions, 8 deletions
diff --git a/Swiften/Examples/EchoBot/EchoBot.cpp b/Swiften/Examples/EchoBot/EchoBot.cpp index 9d11c61..1c576c9 100644 --- a/Swiften/Examples/EchoBot/EchoBot.cpp +++ b/Swiften/Examples/EchoBot/EchoBot.cpp | |||
| @@ -3,42 +3,40 @@ | |||
| 3 | * Licensed under the GNU General Public License v3. | 3 | * Licensed under the GNU General Public License v3. |
| 4 | * See Documentation/Licenses/GPLv3.txt for more information. | 4 | * See Documentation/Licenses/GPLv3.txt for more information. |
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | #include <boost/bind.hpp> | 7 | #include <boost/bind.hpp> |
| 8 | #include <iostream> | ||
| 8 | 9 | ||
| 9 | #include "Swiften/Client/Client.h" | 10 | #include "Swiften/Client/Client.h" |
| 10 | #include "Swiften/Client/ClientXMLTracer.h" | ||
| 11 | #include "Swiften/EventLoop/SimpleEventLoop.h" | 11 | #include "Swiften/EventLoop/SimpleEventLoop.h" |
| 12 | #include "Swiften/Queries/Requests/GetRosterRequest.h" | 12 | #include "Swiften/Queries/Requests/GetRosterRequest.h" |
| 13 | 13 | ||
| 14 | using namespace Swift; | 14 | using namespace Swift; |
| 15 | using namespace boost; | 15 | using namespace boost; |
| 16 | 16 | ||
| 17 | class EchoBot { | 17 | class EchoBot { |
| 18 | public: | 18 | public: |
| 19 | EchoBot(const JID& jid, const String& pass) : tracer(0) { | 19 | EchoBot(const JID& jid, const String& pass) { |
| 20 | client = new Client(jid, pass); | 20 | client = new Client(jid, pass); |
| 21 | tracer = new ClientXMLTracer(client); | ||
| 22 | client->onConnected.connect(bind(&EchoBot::handleConnected, this)); | 21 | client->onConnected.connect(bind(&EchoBot::handleConnected, this)); |
| 23 | client->onMessageReceived.connect(bind(&EchoBot::handleMessageReceived, this, _1)); | 22 | client->onMessageReceived.connect(bind(&EchoBot::handleMessageReceived, this, _1)); |
| 24 | client->connect(); | 23 | client->connect(); |
| 25 | } | 24 | } |
| 26 | 25 | ||
| 27 | ~EchoBot() { | 26 | ~EchoBot() { |
| 28 | delete tracer; | ||
| 29 | delete client; | 27 | delete client; |
| 30 | } | 28 | } |
| 31 | 29 | ||
| 32 | private: | 30 | private: |
| 33 | void handleConnected() { | 31 | void handleConnected() { |
| 34 | shared_ptr<GetRosterRequest> rosterRequest(new GetRosterRequest(client)); | 32 | shared_ptr<GetRosterRequest> rosterRequest(new GetRosterRequest(client)); |
| 35 | rosterRequest->onResponse.connect(bind(&EchoBot::handleRosterReceived, this, _2)); | 33 | rosterRequest->onResponse.connect(bind(&EchoBot::handleRosterReceived, this, _2)); |
| 36 | rosterRequest->send(); | 34 | rosterRequest->send(); |
| 37 | } | 35 | } |
| 38 | 36 | ||
| 39 | void handleRosterReceived(const optional<Error>& error) { | 37 | void handleRosterReceived(const optional<ErrorPayload>& error) { |
| 40 | if (error) { | 38 | if (error) { |
| 41 | std::cerr << "Error receiving roster. Continuing anyway."; | 39 | std::cerr << "Error receiving roster. Continuing anyway."; |
| 42 | } | 40 | } |
| 43 | client->sendPresence(shared_ptr<Presence>(new Presence("Send me a message"))); | 41 | client->sendPresence(shared_ptr<Presence>(new Presence("Send me a message"))); |
| 44 | } | 42 | } |
| @@ -49,14 +47,17 @@ class EchoBot { | |||
| 49 | client->sendMessage(message); | 47 | client->sendMessage(message); |
| 50 | } | 48 | } |
| 51 | 49 | ||
| 52 | private: | 50 | private: |
| 53 | Client* client; | 51 | Client* client; |
| 54 | ClientXMLTracer* tracer; | ||
| 55 | }; | 52 | }; |
| 56 | 53 | ||
| 57 | int main(int, char**) { | 54 | int main(int argc, char* argv[]) { |
| 55 | if (argc != 3) { | ||
| 56 | std::cerr << "Usage: " << argv[0] << " <jid> <pass>" << std::endl; | ||
| 57 | return -1; | ||
| 58 | } | ||
| 58 | SimpleEventLoop eventLoop; | 59 | SimpleEventLoop eventLoop; |
| 59 | EchoBot bot(JID("echobot@wonderland.lit"), "mypass"); | 60 | EchoBot bot(JID(argv[1]), argv[2]); |
| 60 | eventLoop.run(); | 61 | eventLoop.run(); |
| 61 | return 0; | 62 | return 0; |
| 62 | } | 63 | } |
diff --git a/Swiften/Examples/EchoBot/SConscript b/Swiften/Examples/EchoBot/SConscript new file mode 100644 index 0000000..711d8ea --- /dev/null +++ b/Swiften/Examples/EchoBot/SConscript | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | Import("env") | ||
| 2 | |||
| 3 | myenv = env.Clone() | ||
| 4 | myenv.MergeFlags(myenv["SWIFTEN_FLAGS"]) | ||
| 5 | myenv.MergeFlags(myenv["LIBIDN_FLAGS"]) | ||
| 6 | myenv.MergeFlags(myenv["BOOST_FLAGS"]) | ||
| 7 | myenv.MergeFlags(myenv.get("SQLITE_FLAGS", {})) | ||
| 8 | myenv.MergeFlags(myenv["ZLIB_FLAGS"]) | ||
| 9 | myenv.MergeFlags(myenv["OPENSSL_FLAGS"]) | ||
| 10 | myenv.MergeFlags(myenv.get("LIBXML_FLAGS", "")) | ||
| 11 | myenv.MergeFlags(myenv.get("EXPAT_FLAGS", "")) | ||
| 12 | myenv.MergeFlags(myenv["PLATFORM_FLAGS"]) | ||
| 13 | tester = myenv.Program("EchoBot", ["EchoBot.cpp"]) | ||
diff --git a/Swiften/Examples/SConscript b/Swiften/Examples/SConscript index 1a06df2..1c95e85 100644 --- a/Swiften/Examples/SConscript +++ b/Swiften/Examples/SConscript | |||
| @@ -4,6 +4,7 @@ myenv = swiften_env.Clone() | |||
| 4 | 4 | ||
| 5 | SConscript(dirs = [ | 5 | SConscript(dirs = [ |
| 6 | "SendMessage", | 6 | "SendMessage", |
| 7 | "ConnectivityTest", | 7 | "ConnectivityTest", |
| 8 | "LinkLocalTool", | 8 | "LinkLocalTool", |
| 9 | "EchoBot", | ||
| 9 | ]) | 10 | ]) |
Swift