diff options
Diffstat (limited to 'Documentation/SwiftenDevelopersGuide/Examples/EchoBot')
13 files changed, 432 insertions, 439 deletions
diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/.gitignore b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/.gitignore index aca6fe1..ef95cc1 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/.gitignore +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/.gitignore @@ -1,4 +1,5 @@ EchoBot? +EchoBot0x *.cpp.xml *.h.xml EchoComponent diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot0x.cpp b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot0x.cpp index 11773ae..9a7301a 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot0x.cpp +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot0x.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Swiften.h> @@ -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 8a64b56..6e04eee 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot1.cpp +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot1.cpp @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swiften/Swiften.h> @@ -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 8b81489..d928db8 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot2.cpp +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot2.cpp @@ -1,10 +1,11 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 e3e3560..470753d 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot3.cpp +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot3.cpp @@ -1,10 +1,11 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 c8d8c84..9ab7864 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot4.cpp +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot4.cpp @@ -1,11 +1,12 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 810424c..3475a6c 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot5.cpp +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot5.cpp @@ -1,11 +1,12 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 92a2ab6..e1d5528 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot6.cpp +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot6.cpp @@ -1,13 +1,14 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 a6e6ca0..16d7e4e 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoComponent.cpp +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoComponent.cpp @@ -1,10 +1,11 @@ /* - * Copyright (c) 2010-2013 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 62ea495..1e5fc98 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayload.h +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayload.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ //... #pragma once @@ -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 33a8c41..48d08bd 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadParserFactory.h +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadParserFactory.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once @@ -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 068113c..faf1080 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadSerializer.h +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoPayloadSerializer.h @@ -1,19 +1,20 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * 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 aa9f691..268ab9a 100644 --- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/SConscript +++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/SConscript @@ -6,27 +6,12 @@ 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" +# 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" 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 -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") |