MySQLLog.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 HAVE_MYSQL
00023 #error MySQLLog.h included, but HAVE_MYSQL not defined
00024 #endif
00025 
00026 #ifdef HAVE_MYSQL
00027 #ifndef FIX_MYSQLLOG_H
00028 #define FIX_MYSQLLOG_H
00029 
00030 #ifdef _MSC_VER
00031 #pragma warning( disable : 4503 4355 4786 4290 )
00032 #pragma comment( lib, "libMySQL" )
00033 #endif
00034 
00035 #include "Log.h"
00036 #include "SessionSettings.h"
00037 #include "MySQLConnection.h"
00038 #include <fstream>
00039 #include <string>
00040 
00041 namespace FIX
00042 {
00044 class MySQLLog : public Log
00045 {
00046 public:
00047   MySQLLog( const SessionID& s, const DatabaseConnectionID& d, MySQLConnectionPool* p );
00048   MySQLLog( const DatabaseConnectionID& d, MySQLConnectionPool* p );
00049   MySQLLog( const SessionID& s, const std::string& database, const std::string& user,
00050             const std::string& password, const std::string& host, short port );
00051   MySQLLog( const std::string& database, const std::string& user,
00052             const std::string& password, const std::string& host, short port );
00053 
00054   ~MySQLLog();
00055 
00056   void clear();
00057   void backup();
00058   void setIncomingTable( const std::string& incomingTable )
00059   { m_incomingTable = incomingTable; }
00060   void setOutgoingTable( const std::string& outgoingTable )
00061   { m_outgoingTable = outgoingTable; }
00062   void setEventTable( const std::string& eventTable )
00063   { m_eventTable = eventTable; }
00064 
00065   void onIncoming( const std::string& value )
00066   { insert( m_incomingTable, value ); }
00067   void onOutgoing( const std::string& value )
00068   { insert( m_outgoingTable, value ); }
00069   void onEvent( const std::string& value )
00070   { insert( m_eventTable, value ); }
00071 
00072 private:
00073   void init();
00074   void insert( const std::string& table, const std::string value );
00075 
00076   std::string m_incomingTable;
00077   std::string m_outgoingTable;
00078   std::string m_eventTable;
00079   MySQLConnection* m_pConnection;
00080   MySQLConnectionPool* m_pConnectionPool;
00081   SessionID* m_pSessionID;
00082 };
00083 
00085 class MySQLLogFactory : public LogFactory
00086 {
00087 public:
00088   static const std::string DEFAULT_DATABASE;
00089   static const std::string DEFAULT_USER;
00090   static const std::string DEFAULT_PASSWORD;
00091   static const std::string DEFAULT_HOST;
00092   static const short DEFAULT_PORT;
00093 
00094   MySQLLogFactory( const SessionSettings& settings )
00095 : m_settings( settings ), m_useSettings( true ) 
00096   {
00097     bool poolConnections = false;
00098     try { poolConnections = settings.get().getBool(MYSQL_LOG_USECONNECTIONPOOL); }
00099     catch( ConfigError& ) {}
00100 
00101     m_connectionPoolPtr = MySQLConnectionPoolPtr
00102       ( new MySQLConnectionPool(poolConnections) );
00103   }
00104 
00105   MySQLLogFactory( const std::string& database, const std::string& user,
00106                    const std::string& password, const std::string& host,
00107                    short port )
00108 : m_database( database ), m_user( user ), m_password( password ), m_host( host ), m_port( port ),
00109   m_useSettings( false ) 
00110   {
00111     m_connectionPoolPtr = MySQLConnectionPoolPtr
00112       ( new MySQLConnectionPool(false) );
00113   }
00114 
00115   MySQLLogFactory()
00116 : m_database( DEFAULT_DATABASE ), m_user( DEFAULT_USER ), m_password( DEFAULT_PASSWORD ),
00117   m_host( DEFAULT_HOST ), m_port( DEFAULT_PORT ), m_useSettings( false ) 
00118   {
00119     m_connectionPoolPtr = MySQLConnectionPoolPtr
00120       ( new MySQLConnectionPool(false) );
00121   }
00122 
00123   Log* create();
00124   Log* create( const SessionID& );
00125   void destroy( Log* );
00126 private:
00127   void init( const Dictionary& settings, std::string& database,
00128              std::string& user, std::string& password,
00129              std::string& host, short& port );
00130 
00131   void initLog( const Dictionary& settings, MySQLLog& log );
00132 
00133   MySQLConnectionPoolPtr m_connectionPoolPtr;
00134   SessionSettings m_settings;
00135   std::string m_database;
00136   std::string m_user;
00137   std::string m_password;
00138   std::string m_host;
00139   short m_port;
00140   bool m_useSettings;
00141 };
00142 }
00143 
00144 #endif //FIX_MYSQLLOG_H
00145 #endif //HAVE_MYSQL

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