summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot6.cpp')
-rw-r--r--Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot6.cpp174
1 files changed, 87 insertions, 87 deletions
diff --git a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot6.cpp b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot6.cpp
index b3239c8..b1a1c37 100644
--- a/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot6.cpp
+++ b/Documentation/SwiftenDevelopersGuide/Examples/EchoBot/EchoBot6.cpp
@@ -20,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;
- //...
- }
- //...
-
- 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() {
+ client->removePayloadSerializer(&echoPayloadSerializer);
+ client->removePayloadParserFactory(&echoPayloadParserFactory);
+ //...
+ softwareVersionResponder->stop();
+ delete softwareVersionResponder;
+ delete tracer;
+ delete client;
+ //...
+ }
+ //...
- void handleConnected() {
- // Request the roster
- GetRosterRequest::ref rosterRequest =
- GetRosterRequest::create(client->getIQRouter());
- rosterRequest->onResponse.connect(
- bind(&EchoBot::handleRosterReceived, this, _2));
- rosterRequest->send();
- }
+ 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 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 handleConnected() {
+ // Request the roster
+ GetRosterRequest::ref rosterRequest =
+ GetRosterRequest::create(client->getIQRouter());
+ rosterRequest->onResponse.connect(
+ bind(&EchoBot::handleRosterReceived, this, _2));
+ rosterRequest->send();
+ }
- //...
- 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 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"));
+ }
- //...
- private:
- //...
- Client* client;
- ClientXMLTracer* tracer;
- SoftwareVersionResponder* softwareVersionResponder;
- //...
- EchoPayloadParserFactory echoPayloadParserFactory;
- EchoPayloadSerializer echoPayloadSerializer;
+ //...
+ 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);
+ }
+ }
+ //...
+
+ //...
+ 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;
}
//...