summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-19 15:58:27 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-19 15:58:27 (GMT)
commitbfa7d3d26faaa2db2580d6d7a9388beb71a53c7b (patch)
tree648c0c51aca6e46b938910c39d8f820c8049a45d
parent74e666956ab3b0150ae63885cdf56efae6ca05b3 (diff)
downloadswift-contrib-bfa7d3d26faaa2db2580d6d7a9388beb71a53c7b.zip
swift-contrib-bfa7d3d26faaa2db2580d6d7a9388beb71a53c7b.tar.bz2
Add session tracing.
-rw-r--r--Nim/main.cpp4
-rw-r--r--Swiften/Session/SessionTracer.h29
2 files changed, 33 insertions, 0 deletions
diff --git a/Nim/main.cpp b/Nim/main.cpp
index 2fd5b21..2522a13 100644
--- a/Nim/main.cpp
+++ b/Nim/main.cpp
@@ -2,6 +2,7 @@
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
+#include "Swiften/Session/SessionTracer.h"
#include "Swiften/Network/BoostConnectionFactory.h"
#include "Swiften/Elements/IQ.h"
#include "Swiften/Elements/Presence.h"
@@ -86,6 +87,7 @@ class Server {
serverFromClientSession_ = boost::shared_ptr<ServerFromClientSession>(new ServerFromClientSession(idGenerator_.generateID(), c, &payloadParserFactories_, &payloadSerializers_, &userRegistry_));
serverFromClientSession_->onElementReceived.connect(boost::bind(&Server::handleElementReceived, this, _1, serverFromClientSession_));
serverFromClientSession_->onSessionFinished.connect(boost::bind(&Server::handleSessionFinished, this, serverFromClientSession_));
+ tracers_.push_back(boost::shared_ptr<SessionTracer>(new SessionTracer(serverFromClientSession_)));
serverFromClientSession_->startSession();
}
@@ -243,6 +245,7 @@ class Server {
session->onSessionFinished.connect(boost::bind(&Server::handleLinkLocalSessionFinished, this, session));
session->onElementReceived.connect(boost::bind(&Server::handleLinkLocalElementReceived, this, _1, session));
linkLocalSessions_.push_back(session);
+ tracers_.push_back(boost::shared_ptr<SessionTracer>(new SessionTracer(session)));
session->startSession();
}
@@ -313,6 +316,7 @@ class Server {
boost::shared_ptr<BoostConnectionServer> serverFromClientConnectionServer_;
boost::shared_ptr<ServerFromClientSession> serverFromClientSession_;
boost::shared_ptr<BoostConnectionServer> serverFromNetworkConnectionServer_;
+ std::vector< boost::shared_ptr<SessionTracer> > tracers_;
std::vector< boost::shared_ptr<Session> > linkLocalSessions_;
std::vector< boost::shared_ptr<LinkLocalConnector> > connectors_;
FullPayloadParserFactoryCollection payloadParserFactories_;
diff --git a/Swiften/Session/SessionTracer.h b/Swiften/Session/SessionTracer.h
new file mode 100644
index 0000000..29a07e0
--- /dev/null
+++ b/Swiften/Session/SessionTracer.h
@@ -0,0 +1,29 @@
+#pragma once
+
+#include <iostream>
+
+#include "Swiften/Session/Session.h"
+#include "Swiften/Base/String.h"
+#include "Swiften/Base/ByteArray.h"
+
+namespace Swift {
+ class SessionTracer {
+ public:
+ SessionTracer(boost::shared_ptr<Session> session) : session(session) {
+ session->onDataRead.connect(boost::bind(&SessionTracer::printData, this, '<', _1));
+ session->onDataWritten.connect(boost::bind(&SessionTracer::printData, this, '>', _1));
+ }
+
+ private:
+ void printData(char direction, const ByteArray& data) {
+ std::cerr << direction << direction << " " << session->getLocalJID() << " ";
+ for (unsigned int i = 0; i < 72 - session->getLocalJID().toString().getLength() - session->getRemoteJID().toString().getLength(); ++i) {
+ std::cerr << direction;
+ }
+ std::cerr << " " << session->getRemoteJID()<< " " << direction << direction << std::endl;
+ std::cerr << String(data.getData(), data.getSize()) << std::endl;
+ }
+
+ boost::shared_ptr<Session> session;
+ };
+}