summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/SwiftenDevelopersGuide')
-rw-r--r--Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot0x.cpp32
-rw-r--r--Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot1.cpp14
-rw-r--r--Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot2.cpp33
-rw-r--r--Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot3.cpp75
-rw-r--r--Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot4.cpp133
-rw-r--r--Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot5.cpp149
-rw-r--r--Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot6.cpp179
-rw-r--r--Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoComponent.cpp89
-rw-r--r--Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayload.h20
-rw-r--r--Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadParserFactory.h50
-rw-r--r--Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadSerializer.h17
-rw-r--r--Documentation/SwiftenDevelopersGuide/Examples/EchoBot/SConscript29
-rw-r--r--Documentation/SwiftenDevelopersGuide/SConscript138
13 files changed, 473 insertions, 485 deletions
diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot0x.cpp b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot0x.cpp
index 912ba07..9a7301a 100644
--- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot0x.cpp
+++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot0x.cpp
@@ -9,23 +9,23 @@
using namespace Swift;
int main(int, char**) {
- // Set up the event loop and network classes
- SimpleEventLoop eventLoop;
- BoostNetworkFactories networkFactories(&eventLoop);
+ // Set up the event loop and network classes
+ SimpleEventLoop eventLoop;
+ BoostNetworkFactories networkFactories(&eventLoop);
- Client client("echobot@wonderland.lit", "mypass", &networkFactories);
- client.setAlwaysTrustCertificates();
- client.onConnected.connect([&] {
- std::cout << "Connected" << std::endl;
- });
- client.onMessageReceived.connect([&] (Message::ref message) {
- message->setTo(message->getFrom());
- message->setFrom(JID());
- client.sendMessage(message);
- });
- client.connect();
+ Client client("echobot@wonderland.lit", "mypass", &networkFactories);
+ client.setAlwaysTrustCertificates();
+ client.onConnected.connect([&] {
+ std::cout << "Connected" << std::endl;
+ });
+ client.onMessageReceived.connect([&] (Message::ref message) {
+ message->setTo(message->getFrom());
+ message->setFrom(JID());
+ client.sendMessage(message);
+ });
+ client.connect();
- eventLoop.run();
+ eventLoop.run();
- return 0;
+ return 0;
}
diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot1.cpp b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot1.cpp
index 15d1a77..6e04eee 100644
--- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot1.cpp
+++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot1.cpp
@@ -9,14 +9,14 @@
using namespace Swift;
int main(int, char**) {
- SimpleEventLoop eventLoop;
- BoostNetworkFactories networkFactories(&eventLoop);
+ SimpleEventLoop eventLoop;
+ BoostNetworkFactories networkFactories(&eventLoop);
- Client client("echobot@wonderland.lit", "mypass", &networkFactories);
- client.setAlwaysTrustCertificates();
- client.connect();
+ Client client("echobot@wonderland.lit", "mypass", &networkFactories);
+ client.setAlwaysTrustCertificates();
+ client.connect();
- eventLoop.run();
+ eventLoop.run();
- return 0;
+ return 0;
}
diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot2.cpp b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot2.cpp
index 356a115..d928db8 100644
--- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot2.cpp
+++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot2.cpp
@@ -1,10 +1,11 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <iostream>
+
#include <boost/bind.hpp>
#include <Swiften/Swiften.h>
@@ -18,28 +19,28 @@ void handleConnected();
void handleMessageReceived(Message::ref message);
int main(int, char**) {
- SimpleEventLoop eventLoop;
- BoostNetworkFactories networkFactories(&eventLoop);
+ SimpleEventLoop eventLoop;
+ BoostNetworkFactories networkFactories(&eventLoop);
- client = new Client("echobot@wonderland.lit", "mypass", &networkFactories);
- client->setAlwaysTrustCertificates();
- client->onConnected.connect(&handleConnected);
- client->onMessageReceived.connect(bind(&handleMessageReceived, _1));
- client->connect();
+ client = new Client("echobot@wonderland.lit", "mypass", &networkFactories);
+ client->setAlwaysTrustCertificates();
+ client->onConnected.connect(&handleConnected);
+ client->onMessageReceived.connect(bind(&handleMessageReceived, _1));
+ client->connect();
- eventLoop.run();
+ eventLoop.run();
- delete client;
- return 0;
+ delete client;
+ return 0;
}
void handleConnected() {
- std::cout << "Connected" << std::endl;
+ std::cout << "Connected" << std::endl;
}
void handleMessageReceived(Message::ref message) {
- // Echo back the incoming message
- message->setTo(message->getFrom());
- message->setFrom(JID());
- client->sendMessage(message);
+ // Echo back the incoming message
+ message->setTo(message->getFrom());
+ message->setFrom(JID());
+ client->sendMessage(message);
}
diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot3.cpp b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot3.cpp
index 8334b2f..470753d 100644
--- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot3.cpp
+++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot3.cpp
@@ -1,10 +1,11 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <iostream>
+
#include <boost/bind.hpp>
#include <Swiften/Swiften.h>
@@ -13,45 +14,45 @@ using namespace Swift;
using namespace boost;
class EchoBot {
- public:
- EchoBot(NetworkFactories* networkFactories) {
- client = new Client("echobot@wonderland.lit", "mypass", networkFactories);
- client->setAlwaysTrustCertificates();
- client->onConnected.connect(bind(&EchoBot::handleConnected, this));
- client->onMessageReceived.connect(
- bind(&EchoBot::handleMessageReceived, this, _1));
- tracer = new ClientXMLTracer(client);
- client->connect();
- }
-
- ~EchoBot() {
- delete tracer;
- delete client;
- }
-
- private:
- void handleConnected() {
- std::cout << "Connected" << std::endl;
- }
-
- void handleMessageReceived(Message::ref message) {
- // Echo back the incoming message
- message->setTo(message->getFrom());
- message->setFrom(JID());
- client->sendMessage(message);
- }
-
- private:
- Client* client;
- ClientXMLTracer* tracer;
+ public:
+ EchoBot(NetworkFactories* networkFactories) {
+ client = new Client("echobot@wonderland.lit", "mypass", networkFactories);
+ client->setAlwaysTrustCertificates();
+ client->onConnected.connect(bind(&EchoBot::handleConnected, this));
+ client->onMessageReceived.connect(
+ bind(&EchoBot::handleMessageReceived, this, _1));
+ tracer = new ClientXMLTracer(client);
+ client->connect();
+ }
+
+ ~EchoBot() {
+ delete tracer;
+ delete client;
+ }
+
+ private:
+ void handleConnected() {
+ std::cout << "Connected" << std::endl;
+ }
+
+ void handleMessageReceived(Message::ref message) {
+ // Echo back the incoming message
+ message->setTo(message->getFrom());
+ message->setFrom(JID());
+ client->sendMessage(message);
+ }
+
+ private:
+ Client* client;
+ ClientXMLTracer* tracer;
};
int main(int, char**) {
- SimpleEventLoop eventLoop;
- BoostNetworkFactories networkFactories(&eventLoop);
+ SimpleEventLoop eventLoop;
+ BoostNetworkFactories networkFactories(&eventLoop);
- EchoBot bot(&networkFactories);
+ EchoBot bot(&networkFactories);
- eventLoop.run();
- return 0;
+ eventLoop.run();
+ return 0;
}
diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot4.cpp b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot4.cpp
index 1432677..9ab7864 100644
--- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot4.cpp
+++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot4.cpp
@@ -1,11 +1,12 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
//...
#include <iostream>
+
#include <boost/bind.hpp>
#include <Swiften/Swiften.h>
@@ -14,80 +15,80 @@ using namespace Swift;
using namespace boost;
//...
class EchoBot {
- public:
- EchoBot(NetworkFactories* networkFactories) {
- //...
- client = new Client("echobot@wonderland.lit", "mypass", networkFactories);
- client->setAlwaysTrustCertificates();
- client->onConnected.connect(bind(&EchoBot::handleConnected, this));
- client->onMessageReceived.connect(
- bind(&EchoBot::handleMessageReceived, this, _1));
- //...
- client->onPresenceReceived.connect(
- bind(&EchoBot::handlePresenceReceived, this, _1));
- //...
- tracer = new ClientXMLTracer(client);
- client->connect();
- //...
- }
+ public:
+ EchoBot(NetworkFactories* networkFactories) {
+ //...
+ client = new Client("echobot@wonderland.lit", "mypass", networkFactories);
+ client->setAlwaysTrustCertificates();
+ client->onConnected.connect(bind(&EchoBot::handleConnected, this));
+ client->onMessageReceived.connect(
+ bind(&EchoBot::handleMessageReceived, this, _1));
+ //...
+ client->onPresenceReceived.connect(
+ bind(&EchoBot::handlePresenceReceived, this, _1));
+ //...
+ tracer = new ClientXMLTracer(client);
+ client->connect();
+ //...
+ }
+
+ //...
+ ~EchoBot() {
+ delete tracer;
+ delete client;
+ }
+
+ 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);
+ client->sendPresence(response);
+ }
+ }
- //...
- ~EchoBot() {
- delete tracer;
- delete client;
- }
-
- 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);
- client->sendPresence(response);
- }
- }
+ void handleConnected() {
+ // Request the roster
+ GetRosterRequest::ref rosterRequest =
+ GetRosterRequest::create(client->getIQRouter());
+ rosterRequest->onResponse.connect(
+ bind(&EchoBot::handleRosterReceived, this, _2));
+ rosterRequest->send();
+ }
- void handleConnected() {
- // Request the roster
- GetRosterRequest::ref rosterRequest =
- GetRosterRequest::create(client->getIQRouter());
- rosterRequest->onResponse.connect(
- bind(&EchoBot::handleRosterReceived, this, _2));
- rosterRequest->send();
- }
+ void handleRosterReceived(ErrorPayload::ref error) {
+ if (error) {
+ std::cerr << "Error receiving roster. Continuing anyway.";
+ }
+ // Send initial available presence
+ client->sendPresence(Presence::create("Send me a message"));
+ }
+ //...
- void handleRosterReceived(ErrorPayload::ref error) {
- if (error) {
- std::cerr << "Error receiving roster. Continuing anyway.";
- }
- // Send initial available presence
- client->sendPresence(Presence::create("Send me a message"));
- }
- //...
-
- void handleMessageReceived(Message::ref message) {
- // Echo back the incoming message
- message->setTo(message->getFrom());
- message->setFrom(JID());
- client->sendMessage(message);
- }
+ void handleMessageReceived(Message::ref message) {
+ // Echo back the incoming message
+ message->setTo(message->getFrom());
+ message->setFrom(JID());
+ client->sendMessage(message);
+ }
- private:
- Client* client;
- ClientXMLTracer* tracer;
- //...
+ private:
+ Client* client;
+ ClientXMLTracer* tracer;
+ //...
};
//...
int main(int, char**) {
- SimpleEventLoop eventLoop;
- BoostNetworkFactories networkFactories(&eventLoop);
+ SimpleEventLoop eventLoop;
+ BoostNetworkFactories networkFactories(&eventLoop);
- EchoBot bot(&networkFactories);
+ EchoBot bot(&networkFactories);
- eventLoop.run();
- return 0;
+ eventLoop.run();
+ return 0;
}
//...
diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot5.cpp b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot5.cpp
index ace3b7f..3475a6c 100644
--- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot5.cpp
+++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot5.cpp
@@ -1,11 +1,12 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
//...
#include <iostream>
+
#include <boost/bind.hpp>
#include <Swiften/Swiften.h>
@@ -14,88 +15,88 @@ using namespace Swift;
using namespace boost;
//...
class EchoBot {
- public:
- EchoBot(NetworkFactories* networkFactories) {
- //...
- client = new Client("echobot@wonderland.lit", "mypass", networkFactories);
- client->setAlwaysTrustCertificates();
- client->onConnected.connect(bind(&EchoBot::handleConnected, this));
- client->onMessageReceived.connect(
- bind(&EchoBot::handleMessageReceived, this, _1));
- client->onPresenceReceived.connect(
- bind(&EchoBot::handlePresenceReceived, this, _1));
- tracer = new ClientXMLTracer(client);
- //...
- softwareVersionResponder = new SoftwareVersionResponder(client->getIQRouter());
- softwareVersionResponder->setVersion("EchoBot", "1.0");
- softwareVersionResponder->start();
- //...
- client->connect();
- //...
- }
+ public:
+ EchoBot(NetworkFactories* networkFactories) {
+ //...
+ client = new Client("echobot@wonderland.lit", "mypass", networkFactories);
+ client->setAlwaysTrustCertificates();
+ client->onConnected.connect(bind(&EchoBot::handleConnected, this));
+ client->onMessageReceived.connect(
+ bind(&EchoBot::handleMessageReceived, this, _1));
+ client->onPresenceReceived.connect(
+ bind(&EchoBot::handlePresenceReceived, this, _1));
+ tracer = new ClientXMLTracer(client);
+ //...
+ softwareVersionResponder = new SoftwareVersionResponder(client->getIQRouter());
+ softwareVersionResponder->setVersion("EchoBot", "1.0");
+ softwareVersionResponder->start();
+ //...
+ client->connect();
+ //...
+ }
+
+ ~EchoBot() {
+ softwareVersionResponder->stop();
+ delete softwareVersionResponder;
+ //...
+ delete tracer;
+ delete client;
+ //...
+ }
+ //...
+
+ 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);
+ client->sendPresence(response);
+ }
+ }
- ~EchoBot() {
- softwareVersionResponder->stop();
- delete softwareVersionResponder;
- //...
- delete tracer;
- delete client;
- //...
- }
- //...
-
- 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);
- client->sendPresence(response);
- }
- }
+ void handleConnected() {
+ // Request the roster
+ GetRosterRequest::ref rosterRequest =
+ GetRosterRequest::create(client->getIQRouter());
+ rosterRequest->onResponse.connect(
+ bind(&EchoBot::handleRosterReceived, this, _2));
+ rosterRequest->send();
+ }
- void handleConnected() {
- // Request the roster
- GetRosterRequest::ref rosterRequest =
- GetRosterRequest::create(client->getIQRouter());
- rosterRequest->onResponse.connect(
- bind(&EchoBot::handleRosterReceived, this, _2));
- rosterRequest->send();
- }
+ void handleRosterReceived(ErrorPayload::ref error) {
+ if (error) {
+ std::cerr << "Error receiving roster. Continuing anyway.";
+ }
+ // Send initial available presence
+ client->sendPresence(Presence::create("Send me a message"));
+ }
- void handleRosterReceived(ErrorPayload::ref error) {
- if (error) {
- std::cerr << "Error receiving roster. Continuing anyway.";
- }
- // Send initial available presence
- client->sendPresence(Presence::create("Send me a message"));
- }
-
- void handleMessageReceived(Message::ref message) {
- // Echo back the incoming message
- message->setTo(message->getFrom());
- message->setFrom(JID());
- client->sendMessage(message);
- }
+ void handleMessageReceived(Message::ref message) {
+ // Echo back the incoming message
+ message->setTo(message->getFrom());
+ message->setFrom(JID());
+ client->sendMessage(message);
+ }
- //...
- private:
- //...
- Client* client;
- ClientXMLTracer* tracer;
- //...
- SoftwareVersionResponder* softwareVersionResponder;
+ //...
+ private:
+ //...
+ Client* client;
+ ClientXMLTracer* tracer;
+ //...
+ SoftwareVersionResponder* softwareVersionResponder;
};
//...
int main(int, char**) {
- SimpleEventLoop eventLoop;
- BoostNetworkFactories networkFactories(&eventLoop);
+ SimpleEventLoop eventLoop;
+ BoostNetworkFactories networkFactories(&eventLoop);
- EchoBot bot(&networkFactories);
+ EchoBot bot(&networkFactories);
- eventLoop.run();
- return 0;
+ eventLoop.run();
+ return 0;
}
//...
diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot6.cpp b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot6.cpp
index 609b005..e1d5528 100644
--- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot6.cpp
+++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot6.cpp
@@ -1,13 +1,14 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
//...
#include <iostream>
+#include <memory>
+
#include <boost/bind.hpp>
-#include <boost/smart_ptr/make_shared.hpp>
#include <Swiften/Swiften.h>
@@ -19,104 +20,104 @@ using namespace boost;
#include "EchoPayloadSerializer.h"
class EchoBot {
- public:
- EchoBot(NetworkFactories* networkFactories) {
- //...
- client = new Client("echobot@wonderland.lit", "mypass", networkFactories);
- client->setAlwaysTrustCertificates();
- client->onConnected.connect(bind(&EchoBot::handleConnected, this));
- client->onMessageReceived.connect(
- bind(&EchoBot::handleMessageReceived, this, _1));
- client->onPresenceReceived.connect(
- bind(&EchoBot::handlePresenceReceived, this, _1));
- tracer = new ClientXMLTracer(client);
+ public:
+ EchoBot(NetworkFactories* networkFactories) {
+ //...
+ client = new Client("echobot@wonderland.lit", "mypass", networkFactories);
+ client->setAlwaysTrustCertificates();
+ client->onConnected.connect(bind(&EchoBot::handleConnected, this));
+ client->onMessageReceived.connect(
+ bind(&EchoBot::handleMessageReceived, this, _1));
+ client->onPresenceReceived.connect(
+ bind(&EchoBot::handlePresenceReceived, this, _1));
+ tracer = new ClientXMLTracer(client);
+
+ softwareVersionResponder = new SoftwareVersionResponder(client->getIQRouter());
+ softwareVersionResponder->setVersion("EchoBot", "1.0");
+ softwareVersionResponder->start();
+ //...
+ client->addPayloadParserFactory(&echoPayloadParserFactory);
+ client->addPayloadSerializer(&echoPayloadSerializer);
+ //...
+ client->connect();
+ //...
+ }
- softwareVersionResponder = new SoftwareVersionResponder(client->getIQRouter());
- softwareVersionResponder->setVersion("EchoBot", "1.0");
- softwareVersionResponder->start();
- //...
- client->addPayloadParserFactory(&echoPayloadParserFactory);
- client->addPayloadSerializer(&echoPayloadSerializer);
- //...
- client->connect();
- //...
- }
+ ~EchoBot() {
+ client->removePayloadSerializer(&echoPayloadSerializer);
+ client->removePayloadParserFactory(&echoPayloadParserFactory);
+ //...
+ softwareVersionResponder->stop();
+ delete softwareVersionResponder;
+ delete tracer;
+ delete client;
+ //...
+ }
+ //...
- ~EchoBot() {
- client->removePayloadSerializer(&echoPayloadSerializer);
- client->removePayloadParserFactory(&echoPayloadParserFactory);
- //...
- softwareVersionResponder->stop();
- delete softwareVersionResponder;
- delete tracer;
- delete client;
- //...
- }
- //...
-
- 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);
- client->sendPresence(response);
- }
- }
+ 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);
+ client->sendPresence(response);
+ }
+ }
- void handleConnected() {
- // Request the roster
- GetRosterRequest::ref rosterRequest =
- GetRosterRequest::create(client->getIQRouter());
- rosterRequest->onResponse.connect(
- bind(&EchoBot::handleRosterReceived, this, _2));
- rosterRequest->send();
- }
+ void handleConnected() {
+ // Request the roster
+ GetRosterRequest::ref rosterRequest =
+ GetRosterRequest::create(client->getIQRouter());
+ rosterRequest->onResponse.connect(
+ bind(&EchoBot::handleRosterReceived, this, _2));
+ rosterRequest->send();
+ }
- void handleRosterReceived(ErrorPayload::ref error) {
- if (error) {
- std::cerr << "Error receiving roster. Continuing anyway.";
- }
- // Send initial available presence
- client->sendPresence(Presence::create("Send me a message"));
- }
+ void handleRosterReceived(ErrorPayload::ref error) {
+ if (error) {
+ std::cerr << "Error receiving roster. Continuing anyway.";
+ }
+ // Send initial available presence
+ client->sendPresence(Presence::create("Send me a message"));
+ }
- //...
- void handleMessageReceived(Message::ref message) {
- //...
- // Echo back the incoming message
- message->setTo(message->getFrom());
- message->setFrom(JID());
- //...
- if (!message->getPayload<EchoPayload>()) {
- boost::shared_ptr<EchoPayload> echoPayload = boost::make_shared<EchoPayload>();
- echoPayload->setMessage("This is an echoed message");
- message->addPayload(echoPayload);
- client->sendMessage(message);
- }
- }
- //...
+ //...
+ void handleMessageReceived(Message::ref message) {
+ //...
+ // Echo back the incoming message
+ message->setTo(message->getFrom());
+ message->setFrom(JID());
+ //...
+ if (!message->getPayload<EchoPayload>()) {
+ std::shared_ptr<EchoPayload> echoPayload = std::make_shared<EchoPayload>();
+ echoPayload->setMessage("This is an echoed message");
+ message->addPayload(echoPayload);
+ client->sendMessage(message);
+ }
+ }
+ //...
- //...
- private:
- //...
- Client* client;
- ClientXMLTracer* tracer;
- SoftwareVersionResponder* softwareVersionResponder;
- //...
- EchoPayloadParserFactory echoPayloadParserFactory;
- EchoPayloadSerializer echoPayloadSerializer;
+ //...
+ private:
+ //...
+ Client* client;
+ ClientXMLTracer* tracer;
+ SoftwareVersionResponder* softwareVersionResponder;
+ //...
+ EchoPayloadParserFactory echoPayloadParserFactory;
+ EchoPayloadSerializer echoPayloadSerializer;
};
//...
int main(int, char**) {
- SimpleEventLoop eventLoop;
- BoostNetworkFactories networkFactories(&eventLoop);
+ SimpleEventLoop eventLoop;
+ BoostNetworkFactories networkFactories(&eventLoop);
- EchoBot bot(&networkFactories);
+ EchoBot bot(&networkFactories);
- eventLoop.run();
- return 0;
+ eventLoop.run();
+ return 0;
}
//...
diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoComponent.cpp b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoComponent.cpp
index ad51eb9..16d7e4e 100644
--- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoComponent.cpp
+++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoComponent.cpp
@@ -1,10 +1,11 @@
/*
- * Copyright (c) 2010-2013 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <iostream>
+
#include <boost/bind.hpp>
#include <Swiften/Swiften.h>
@@ -13,56 +14,56 @@ using namespace Swift;
using namespace boost;
class EchoComponent {
- public:
- EchoComponent(NetworkFactories* networkFactories) : jid("echo.wonderland.lit") {
- component = new Component(jid, "EchoSecret", networkFactories);
- 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);
- }
+ public:
+ EchoComponent(NetworkFactories* networkFactories) : jid("echo.wonderland.lit") {
+ component = new Component(jid, "EchoSecret", networkFactories);
+ 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;
+ }
- ~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);
- }
- }
+ 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 handleConnected() {
+ }
- void handleMessageReceived(Message::ref message) {
- // Echo back the incoming message
- message->setTo(message->getFrom());
- message->setFrom(jid);
- component->sendMessage(message);
- }
+ void handleMessageReceived(Message::ref message) {
+ // Echo back the incoming message
+ message->setTo(message->getFrom());
+ message->setFrom(jid);
+ component->sendMessage(message);
+ }
- private:
- JID jid;
- Component* component;
- ComponentXMLTracer* tracer;
+ private:
+ JID jid;
+ Component* component;
+ ComponentXMLTracer* tracer;
};
int main(int, char**) {
- SimpleEventLoop eventLoop;
- BoostNetworkFactories networkFactories(&eventLoop);
+ SimpleEventLoop eventLoop;
+ BoostNetworkFactories networkFactories(&eventLoop);
- EchoComponent bot(&networkFactories);
+ EchoComponent bot(&networkFactories);
- eventLoop.run();
- return 0;
+ eventLoop.run();
+ return 0;
}
diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayload.h b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayload.h
index c93b78b..1e5fc98 100644
--- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayload.h
+++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayload.h
@@ -10,17 +10,17 @@
//...
class EchoPayload : public Swift::Payload {
- public:
- EchoPayload() {}
+ public:
+ EchoPayload() {}
- const std::string& getMessage() const {
- return message;
- }
+ const std::string& getMessage() const {
+ return message;
+ }
- void setMessage(const std::string& message) {
- this->message = message;
- }
+ void setMessage(const std::string& message) {
+ this->message = message;
+ }
- private:
- std::string message;
+ private:
+ std::string message;
};
diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadParserFactory.h b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadParserFactory.h
index 9d66204..48d08bd 100644
--- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadParserFactory.h
+++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadParserFactory.h
@@ -10,32 +10,32 @@
#include "EchoPayload.h"
class EchoPayloadParser : public Swift::GenericPayloadParser<EchoPayload> {
- public:
- EchoPayloadParser() : currentDepth(0) {}
-
- void handleStartElement(
- const std::string& /* element */, const std::string& /* ns */, const AttributeMap&) {
- currentDepth++;
- }
-
- void handleEndElement(const std::string& /* element */, const std::string& /* ns */) {
- currentDepth--;
- if (currentDepth == 0) {
- getPayloadInternal()->setMessage(currentText);
- }
- }
-
- void handleCharacterData(const std::string& data) {
- currentText += data;
- }
-
- private:
- int currentDepth;
- std::string currentText;
+ public:
+ EchoPayloadParser() : currentDepth(0) {}
+
+ void handleStartElement(
+ const std::string& /* element */, const std::string& /* ns */, const AttributeMap&) {
+ currentDepth++;
+ }
+
+ void handleEndElement(const std::string& /* element */, const std::string& /* ns */) {
+ currentDepth--;
+ if (currentDepth == 0) {
+ getPayloadInternal()->setMessage(currentText);
+ }
+ }
+
+ void handleCharacterData(const std::string& data) {
+ currentText += data;
+ }
+
+ private:
+ int currentDepth;
+ std::string currentText;
};
class EchoPayloadParserFactory : public Swift::GenericPayloadParserFactory<EchoPayloadParser> {
- public:
- EchoPayloadParserFactory() :
- GenericPayloadParserFactory<EchoPayloadParser>("echo", "http://swift.im/echo") {}
+ public:
+ EchoPayloadParserFactory() :
+ GenericPayloadParserFactory<EchoPayloadParser>("echo", "http://swift.im/echo") {}
};
diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadSerializer.h b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadSerializer.h
index abc4760..faf1080 100644
--- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadSerializer.h
+++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadSerializer.h
@@ -1,19 +1,20 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
-#include <Swiften/Swiften.h>
#include "EchoPayload.h"
+#include <Swiften/Swiften.h>
+
class EchoPayloadSerializer : public Swift::GenericPayloadSerializer<EchoPayload> {
- public:
- std::string serializePayload(boost::shared_ptr<EchoPayload> payload) const {
- XMLElement element("echo", "http://swift.im/protocol/echo");
- element.addNode(XMLTextNode::ref(new XMLTextNode(payload->getMessage())));
- return element.serialize();
- }
+ public:
+ std::string serializePayload(std::shared_ptr<EchoPayload> payload) const {
+ XMLElement element("echo", "http://swift.im/protocol/echo");
+ element.addNode(XMLTextNode::ref(new XMLTextNode(payload->getMessage())));
+ return element.serialize();
+ }
};
diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/SConscript b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/SConscript
index 5d27b70..268ab9a 100644
--- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/SConscript
+++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/SConscript
@@ -7,30 +7,11 @@ example_env.UseFlags(example_env["SWIFTEN_DEP_FLAGS"])
# Precompile Swiften header
# This is useful to slightly speed up compilation.
# if example_env["PLATFORM"] == "win32":
-# example_env.WriteVal("Swiften.cpp", example_env.Value("#include <Swiften/Swiften.h>\n"))
-# example_env["PCH"] = example_env.PCH("Swiften.cpp")[0]
-# example_env["PCHSTOP"] = "Swiften/Swiften.h"
+# example_env.WriteVal("Swiften.cpp", example_env.Value("#include <Swiften/Swiften.h>\n"))
+# example_env["PCH"] = example_env.PCH("Swiften.cpp")[0]
+# example_env["PCHSTOP"] = "Swiften/Swiften.h"
for i in range(1,7) :
- example_env.Program("EchoBot" + str(i), ["EchoBot" + str(i) + ".cpp"])
+ example_env.Program("EchoBot" + str(i), ["EchoBot" + str(i) + ".cpp"])
+example_env.Program("EchoBot0x", "EchoBot0x.cpp")
example_env.Program("EchoComponent", "EchoComponent.cpp")
-
-# C++0x
-cpp0x = False
-cpp0x_env = example_env.Clone()
-if env["PLATFORM"] == "win32" :
- if int(env["MSVS_VERSION"].split(".")[0]) >= 10 :
- cpp0x = True
-elif env["PLATFORM"] == "hpux" :
- pass
-elif env["PLATFORM"] == "sunos" :
- pass
-else :
- if env["CCVERSION"].split(".") >= ["4", "5", "0"] :
- # Temporarily disabling c++0x mode because of problems with boost::thread
- # on some platforms
- #cpp0x = True
- cpp0x_env.Replace(CXXFLAGS = [flag for flag in env["CXXFLAGS"] if flag != "-Werror"])
- cpp0x_env.Append(CXXFLAGS = ["-std=c++0x"])
-if cpp0x :
- cpp0x_env.Program("EchoBot0x", "EchoBot0x.cpp")
diff --git a/Documentation/SwiftenDevelopersGuide/SConscript b/Documentation/SwiftenDevelopersGuide/SConscript
index ba0eb0b..ac7c67a 100644
--- a/Documentation/SwiftenDevelopersGuide/SConscript
+++ b/Documentation/SwiftenDevelopersGuide/SConscript
@@ -9,89 +9,89 @@ env.Tool("DocBook", toolpath = ["#/BuildTools/DocBook/SCons"])
import sys, re, os.path
def generateDocBookCode(env, target, source) :
- # Strips empty lines from the beginning & end of a program
- def stripEmptyLines(program) :
- programLines = program.split('\n')
- newProgramLines = []
- inProgram = False
- for line in programLines :
- if not re.match("^\s*$", line) or inProgram :
- inProgram = True
- newProgramLines.append(line)
- return '\n'.join(newProgramLines).rstrip()
+ # Strips empty lines from the beginning & end of a program
+ def stripEmptyLines(program) :
+ programLines = program.split('\n')
+ newProgramLines = []
+ inProgram = False
+ for line in programLines :
+ if not re.match("^\s*$", line) or inProgram :
+ inProgram = True
+ newProgramLines.append(line)
+ return '\n'.join(newProgramLines).rstrip()
- def createCallouts(program, calloutPrefix) :
- newProgramLines = []
- calloutLines = []
- nextID = 0
- for line in program.split("\n") :
- # FIXME: Takes the largest match
- m = re.match(".*\/* \(\*\) (.*) \*/.*", line)
- if m :
- cobID = "cob-" + calloutPrefix + "-" + str(nextID)
- coID = "co-" + calloutPrefix + "-" + str(nextID)
- nextID += 1
- line = re.sub("/\*.*\*/", "]]><co id=\"%(cobID)s\" linkends=\"%(coID)s\"/><![CDATA[" % {"cobID" : cobID, "coID" : coID}, line)
- calloutLines.append("<callout arearefs=\"%(cobID)s\" id=\"%(coID)s\"><para>%(text)s</para></callout>" % {"cobID": cobID, "coID": coID, "text": m.group(1)})
- newProgramLines.append(line)
- callouts = ""
- if len(calloutLines) > 0 :
- callouts = "<calloutlist>" + "\n".join(calloutLines) + "</calloutlist>"
- return ("\n".join(newProgramLines), callouts)
+ def createCallouts(program, calloutPrefix) :
+ newProgramLines = []
+ calloutLines = []
+ nextID = 0
+ for line in program.split("\n") :
+ # FIXME: Takes the largest match
+ m = re.match(".*\/* \(\*\) (.*) \*/.*", line)
+ if m :
+ cobID = "cob-" + calloutPrefix + "-" + str(nextID)
+ coID = "co-" + calloutPrefix + "-" + str(nextID)
+ nextID += 1
+ line = re.sub("/\*.*\*/", "]]><co id=\"%(cobID)s\" linkends=\"%(coID)s\"/><![CDATA[" % {"cobID" : cobID, "coID" : coID}, line)
+ calloutLines.append("<callout arearefs=\"%(cobID)s\" id=\"%(coID)s\"><para>%(text)s</para></callout>" % {"cobID": cobID, "coID": coID, "text": m.group(1)})
+ newProgramLines.append(line)
+ callouts = ""
+ if len(calloutLines) > 0 :
+ callouts = "<calloutlist>" + "\n".join(calloutLines) + "</calloutlist>"
+ return ("\n".join(newProgramLines), callouts)
- # Parse program
- filename = source[0].abspath
- filenameBase = os.path.basename(filename).replace(".cpp", "")
- inputfile = open(filename)
- program = ""
- programs = {}
- programName = ""
- inEllipsis = False
- for line in inputfile.readlines() :
- if inEllipsis :
- if "//..." in line :
- inEllipsis = False
- else :
- if line.startswith("/*") or line.startswith(" *") :
- continue
- if "//..." in line :
- inEllipsis = True
- line = line.replace("//...", "]]>&#x2026;<![CDATA[")
- else :
- m = re.match("^/// (.*)", line)
- if m :
- if programName :
- programs[programName] = program
- program = ""
- programName = m.group(1).strip().replace(" ", "")
- continue
- line = re.sub("\t", " ", line)
- program += line
- programs[programName] = program
- inputfile.close()
+ # Parse program
+ filename = source[0].abspath
+ filenameBase = os.path.basename(filename).replace(".cpp", "")
+ inputfile = open(filename)
+ program = ""
+ programs = {}
+ programName = ""
+ inEllipsis = False
+ for line in inputfile.readlines() :
+ if inEllipsis :
+ if "//..." in line :
+ inEllipsis = False
+ else :
+ if line.startswith("/*") or line.startswith(" *") :
+ continue
+ if "//..." in line :
+ inEllipsis = True
+ line = line.replace("//...", "]]>&#x2026;<![CDATA[")
+ else :
+ m = re.match("^/// (.*)", line)
+ if m :
+ if programName :
+ programs[programName] = program
+ program = ""
+ programName = m.group(1).strip().replace(" ", "")
+ continue
+ line = re.sub("\t", " ", line)
+ program += line
+ programs[programName] = program
+ inputfile.close()
- for programName, program in programs.items() :
- program = stripEmptyLines(program)
- (program, callouts) = createCallouts(program, filenameBase + "-" + programName)
+ for programName, program in programs.items() :
+ program = stripEmptyLines(program)
+ (program, callouts) = createCallouts(program, filenameBase + "-" + programName)
- document = "<foo><programlisting><![CDATA[" + program + "]]></programlisting>" + callouts + "</foo>"
+ document = "<foo><programlisting><![CDATA[" + program + "]]></programlisting>" + callouts + "</foo>"
- # Generate code
- output = open(target[0].abspath, 'w')
- output.write(document)
- output.close()
+ # Generate code
+ output = open(target[0].abspath, 'w')
+ output.write(document)
+ output.close()
################################################################################
if "doc" in ARGUMENTS :
- env.DocBook("Swiften Developers Guide.xml")
+ env.DocBook("Swiften Developers Guide.xml")
sources = []
for i in range(1, 7) :
- sources.append("Examples/EchoBot/EchoBot" + str(i) + ".cpp")
+ sources.append("Examples/EchoBot/EchoBot" + str(i) + ".cpp")
sources.append("Examples/EchoBot/EchoBot0x.cpp")
sources += ["Examples/EchoBot/" + i for i in ["EchoPayloadParserFactory.h", "EchoPayloadSerializer.h", "EchoPayload.h", "EchoComponent.cpp"]]
for source in sources :
- env.Command(source + ".xml", source, Action(generateDocBookCode, cmdstr = "$GENCOMSTR"))
+ env.Command(source + ".xml", source, Action(generateDocBookCode, cmdstr = "$GENCOMSTR"))
SConscript(dirs = ["Examples"])