Log.h
Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 /****************************************************************************
00004 ** Copyright (c) 2001-2014
00005 **
00006 ** This file is part of the QuickFIX FIX Engine
00007 **
00008 ** This file may be distributed under the terms of the quickfixengine.org
00009 ** license as defined by quickfixengine.org and appearing in the file
00010 ** LICENSE included in the packaging of this file.
00011 **
00012 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014 **
00015 ** See http://www.quickfixengine.org/LICENSE for licensing information.
00016 **
00017 ** Contact ask@quickfixengine.org if any conditions of this licensing are
00018 ** not clear to you.
00019 **
00020 ****************************************************************************/
00021 
00022 #ifndef FIX_LOG_H
00023 #define FIX_LOG_H
00024 
00025 #ifdef _MSC_VER
00026 #pragma warning( disable : 4503 4355 4786 4290 )
00027 #endif
00028 
00029 #include "Message.h"
00030 #include "Mutex.h"
00031 #include "SessionSettings.h"
00032 #include <map>
00033 #include <vector>
00034 
00035 namespace FIX
00036 {
00037 class Log;
00038 
00042 class LogFactory
00043 {
00044 public:
00045   virtual ~LogFactory() {}
00046   virtual Log* create() = 0;
00047   virtual Log* create( const SessionID& ) = 0;
00048   virtual void destroy( Log* ) = 0;
00049 };
00050 
00056 class ScreenLogFactory : public LogFactory
00057 {
00058 public:
00059   ScreenLogFactory( const SessionSettings& settings )
00060 : m_useSettings( true ), m_settings( settings ) {};
00061   ScreenLogFactory( bool incoming, bool outgoing, bool event )
00062 : m_incoming( incoming ), m_outgoing( outgoing ), m_event( event ), m_useSettings( false ) {}
00063 
00064   Log* create();
00065   Log* create( const SessionID& );
00066   void destroy( Log* log );
00067 
00068 private:
00069   void init( const Dictionary& settings, bool& incoming, bool& outgoing, bool& event );
00070 
00071   bool m_incoming;
00072   bool m_outgoing;
00073   bool m_event;
00074   bool m_useSettings;
00075   SessionSettings m_settings;
00076 };
00077 
00081 class Log
00082 {
00083 public:
00084   virtual ~Log() {}
00085 
00086   virtual void clear() = 0;
00087   virtual void backup() = 0;
00088   virtual void onIncoming( const std::string& ) = 0;
00089   virtual void onOutgoing( const std::string& ) = 0;
00090   virtual void onEvent( const std::string& ) = 0;
00091 };
00100 class NullLog : public Log
00101 {
00102 public:
00103   void clear() {}
00104   void backup() {}
00105   void onIncoming( const std::string& ) {}
00106   void onOutgoing( const std::string& ) {}
00107   void onEvent( const std::string& ) {}
00108 };
00109 
00115 class ScreenLog : public Log
00116 {
00117 public:
00118   ScreenLog( bool incoming, bool outgoing, bool event ) 
00119 : m_prefix( "GLOBAL" ),
00120   m_incoming( incoming ), m_outgoing( outgoing ), m_event( event ), m_millisecondsInTimeStamp( true ) {}
00121 
00122   ScreenLog( const SessionID& sessionID,
00123              bool incoming, bool outgoing, bool event )
00124 : m_prefix( sessionID.toString() ),
00125   m_incoming( incoming ), m_outgoing( outgoing ), m_event( event ), m_millisecondsInTimeStamp( true ) {}
00126 
00127   void clear() {}
00128   void backup() {}
00129 
00130   void onIncoming( const std::string& value )
00131   {
00132     if ( !m_incoming ) return ;
00133     Locker l( s_mutex );
00134     m_time.setCurrent();
00135     std::cout << "<" << UtcTimeStampConvertor::convert(m_time, m_millisecondsInTimeStamp)
00136               << ", " << m_prefix
00137               << ", " << "incoming>" << std::endl
00138               << "  (" << value << ")" << std::endl;
00139   }
00140 
00141   void onOutgoing( const std::string& value )
00142   {
00143     if ( !m_outgoing ) return ;
00144     Locker l( s_mutex );
00145     m_time.setCurrent();
00146     std::cout << "<" << UtcTimeStampConvertor::convert(m_time, m_millisecondsInTimeStamp)
00147               << ", " << m_prefix
00148               << ", " << "outgoing>" << std::endl
00149               << "  (" << value << ")" << std::endl;
00150   }
00151 
00152   void onEvent( const std::string& value )
00153   {
00154     if ( !m_event ) return ;
00155     Locker l( s_mutex );
00156     m_time.setCurrent();
00157     std::cout << "<" << UtcTimeStampConvertor::convert(m_time, m_millisecondsInTimeStamp)
00158               << ", " << m_prefix
00159               << ", " << "event>" << std::endl
00160               << "  (" << value << ")" << std::endl;
00161   }
00162 
00163   bool getMillisecondsInTimeStamp() const
00164   { return m_millisecondsInTimeStamp; }
00165   void setMillisecondsInTimeStamp ( bool value )
00166   { m_millisecondsInTimeStamp = value; }
00167 
00168 private:
00169   std::string m_prefix;
00170   UtcTimeStamp m_time;
00171   bool m_incoming;
00172   bool m_outgoing;
00173   bool m_event;
00174   static Mutex s_mutex;
00175   bool m_millisecondsInTimeStamp;
00176 };
00177 }
00178 
00179 #endif //FIX_LOG_H

Generated on Mon Sep 15 2014 01:23:54 for QuickFIX by doxygen 1.7.6.1 written by Dimitri van Heesch, © 1997-2001