OdbcLog.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* -*- C++ -*- */
  2. /****************************************************************************
  3. ** Copyright (c) 2001-2014
  4. **
  5. ** This file is part of the QuickFIX FIX Engine
  6. **
  7. ** This file may be distributed under the terms of the quickfixengine.org
  8. ** license as defined by quickfixengine.org and appearing in the file
  9. ** LICENSE included in the packaging of this file.
  10. **
  11. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  12. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  13. **
  14. ** See http://www.quickfixengine.org/LICENSE for licensing information.
  15. **
  16. ** Contact ask@quickfixengine.org if any conditions of this licensing are
  17. ** not clear to you.
  18. **
  19. ****************************************************************************/
  20. #ifndef HAVE_ODBC
  21. #error OdbcLog.h included, but HAVE_ODBC not defined
  22. #endif
  23. #ifdef HAVE_ODBC
  24. #ifndef FIX_ODBCLOG_H
  25. #define FIX_ODBCLOG_H
  26. #ifdef _MSC_VER
  27. #pragma warning( disable : 4503 4355 4786 4290 )
  28. #endif
  29. #include "OdbcConnection.h"
  30. #include "Log.h"
  31. #include "SessionSettings.h"
  32. #include <fstream>
  33. #include <string>
  34. namespace FIX
  35. {
  36. /// ODBC based implementation of Log.
  37. class OdbcLog : public Log
  38. {
  39. public:
  40. OdbcLog( const SessionID& s, const std::string& user, const std::string& password,
  41. const std::string& connectionString );
  42. OdbcLog( const std::string& user, const std::string& password,
  43. const std::string& connectionString );
  44. ~OdbcLog();
  45. void clear();
  46. void backup();
  47. void setIncomingTable( const std::string& incomingTable )
  48. { m_incomingTable = incomingTable; }
  49. void setOutgoingTable( const std::string& outgoingTable )
  50. { m_outgoingTable = outgoingTable; }
  51. void setEventTable( const std::string& eventTable )
  52. { m_eventTable = eventTable; }
  53. void onIncoming( const std::string& value )
  54. { insert( m_incomingTable, value ); }
  55. void onOutgoing( const std::string& value )
  56. { insert( m_outgoingTable, value ); }
  57. void onEvent( const std::string& value )
  58. { insert( m_eventTable, value ); }
  59. private:
  60. void init();
  61. void insert( const std::string& table, const std::string value );
  62. std::string m_incomingTable;
  63. std::string m_outgoingTable;
  64. std::string m_eventTable;
  65. OdbcConnection* m_pConnection;
  66. SessionID* m_pSessionID;
  67. };
  68. /// Creates a ODBC based implementation of Log.
  69. class OdbcLogFactory : public LogFactory
  70. {
  71. public:
  72. static const std::string DEFAULT_USER;
  73. static const std::string DEFAULT_PASSWORD;
  74. static const std::string DEFAULT_CONNECTION_STRING;
  75. OdbcLogFactory( const SessionSettings& settings )
  76. : m_settings( settings ), m_useSettings( true ) {}
  77. OdbcLogFactory( const std::string& user, const std::string& password,
  78. const std::string& connectionString );
  79. OdbcLogFactory();
  80. ~OdbcLogFactory();
  81. Log* create();
  82. Log* create( const SessionID& );
  83. void destroy( Log* );
  84. private:
  85. void init( const Dictionary& settings,
  86. std::string& user, std::string& password,
  87. std::string& connectionString );
  88. void initLog( const Dictionary& settings, OdbcLog& log );
  89. SessionSettings m_settings;
  90. std::string m_user;
  91. std::string m_password;
  92. std::string m_connectionString;
  93. bool m_useSettings;
  94. };
  95. }
  96. #endif
  97. #endif