diff options
Diffstat (limited to 'vmime-master/examples/example6_tracer.hpp')
-rw-r--r-- | vmime-master/examples/example6_tracer.hpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/vmime-master/examples/example6_tracer.hpp b/vmime-master/examples/example6_tracer.hpp new file mode 100644 index 0000000..27090cf --- /dev/null +++ b/vmime-master/examples/example6_tracer.hpp @@ -0,0 +1,59 @@ + +/** Tracer used to demonstrate logging communication between client and server. + */ +class myTracer : public vmime::net::tracer { + +public: + + myTracer( + const vmime::shared_ptr <std::ostringstream>& stream, + const vmime::shared_ptr <vmime::net::service>& serv, + const int connectionId + ) + : m_stream(stream), + m_service(serv), + m_connectionId(connectionId) { + + } + + void traceSend(const vmime::string& line) { + + *m_stream << "[" << m_service->getProtocolName() << ":" << m_connectionId + << "] C: " << line << std::endl; + } + + void traceReceive(const vmime::string& line) { + + *m_stream << "[" << m_service->getProtocolName() << ":" << m_connectionId + << "] S: " << line << std::endl; + } + +private: + + vmime::shared_ptr <std::ostringstream> m_stream; + vmime::shared_ptr <vmime::net::service> m_service; + const int m_connectionId; +}; + + +class myTracerFactory : public vmime::net::tracerFactory { + +public: + + myTracerFactory(const vmime::shared_ptr <std::ostringstream>& stream) + : m_stream(stream) { + + } + + vmime::shared_ptr <vmime::net::tracer> create( + const vmime::shared_ptr <vmime::net::service>& serv, + const int connectionId + ) { + + return vmime::make_shared <myTracer>(m_stream, serv, connectionId); + } + +private: + + vmime::shared_ptr <std::ostringstream> m_stream; +}; |