summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Examples/EchoBot/EchoBot.cpp')
-rw-r--r--Swiften/Examples/EchoBot/EchoBot.cpp17
1 files changed, 9 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
14using namespace Swift; 14using namespace Swift;
15using namespace boost; 15using namespace boost;
16 16
17class EchoBot { 17class 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
57int main(int, char**) { 54int 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}