quickfix_ruby 1.14.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/quickfix/Acceptor.cpp +248 -0
- data/ext/quickfix/Acceptor.h +127 -0
- data/ext/quickfix/Allocator.h +9 -0
- data/ext/quickfix/Application.h +127 -0
- data/ext/quickfix/AtomicCount.h +109 -0
- data/ext/quickfix/DOMDocument.h +74 -0
- data/ext/quickfix/DataDictionary.cpp +618 -0
- data/ext/quickfix/DataDictionary.h +539 -0
- data/ext/quickfix/DataDictionaryProvider.cpp +71 -0
- data/ext/quickfix/DataDictionaryProvider.h +70 -0
- data/ext/quickfix/DatabaseConnectionID.h +105 -0
- data/ext/quickfix/DatabaseConnectionPool.h +91 -0
- data/ext/quickfix/Dictionary.cpp +162 -0
- data/ext/quickfix/Dictionary.h +94 -0
- data/ext/quickfix/Event.h +95 -0
- data/ext/quickfix/Exceptions.h +299 -0
- data/ext/quickfix/Field.h +672 -0
- data/ext/quickfix/FieldConvertors.h +863 -0
- data/ext/quickfix/FieldMap.cpp +238 -0
- data/ext/quickfix/FieldMap.h +244 -0
- data/ext/quickfix/FieldNumbers.h +46 -0
- data/ext/quickfix/FieldTypes.cpp +64 -0
- data/ext/quickfix/FieldTypes.h +698 -0
- data/ext/quickfix/Fields.h +31 -0
- data/ext/quickfix/FileLog.cpp +200 -0
- data/ext/quickfix/FileLog.h +112 -0
- data/ext/quickfix/FileStore.cpp +332 -0
- data/ext/quickfix/FileStore.h +129 -0
- data/ext/quickfix/FixFieldNumbers.h +1537 -0
- data/ext/quickfix/FixFields.h +1538 -0
- data/ext/quickfix/FixValues.h +3281 -0
- data/ext/quickfix/FlexLexer.h +188 -0
- data/ext/quickfix/Group.cpp +64 -0
- data/ext/quickfix/Group.h +73 -0
- data/ext/quickfix/HtmlBuilder.h +186 -0
- data/ext/quickfix/HttpConnection.cpp +739 -0
- data/ext/quickfix/HttpConnection.h +78 -0
- data/ext/quickfix/HttpMessage.cpp +149 -0
- data/ext/quickfix/HttpMessage.h +133 -0
- data/ext/quickfix/HttpParser.cpp +49 -0
- data/ext/quickfix/HttpParser.h +54 -0
- data/ext/quickfix/HttpServer.cpp +169 -0
- data/ext/quickfix/HttpServer.h +78 -0
- data/ext/quickfix/Initiator.cpp +289 -0
- data/ext/quickfix/Initiator.h +149 -0
- data/ext/quickfix/Log.cpp +77 -0
- data/ext/quickfix/Log.h +179 -0
- data/ext/quickfix/Message.cpp +580 -0
- data/ext/quickfix/Message.h +370 -0
- data/ext/quickfix/MessageCracker.h +188 -0
- data/ext/quickfix/MessageSorters.cpp +105 -0
- data/ext/quickfix/MessageSorters.h +156 -0
- data/ext/quickfix/MessageStore.cpp +146 -0
- data/ext/quickfix/MessageStore.h +174 -0
- data/ext/quickfix/Mutex.h +131 -0
- data/ext/quickfix/MySQLConnection.h +194 -0
- data/ext/quickfix/MySQLLog.cpp +275 -0
- data/ext/quickfix/MySQLLog.h +145 -0
- data/ext/quickfix/MySQLStore.cpp +331 -0
- data/ext/quickfix/MySQLStore.h +142 -0
- data/ext/quickfix/NullStore.cpp +54 -0
- data/ext/quickfix/NullStore.h +99 -0
- data/ext/quickfix/OdbcConnection.h +266 -0
- data/ext/quickfix/OdbcLog.cpp +252 -0
- data/ext/quickfix/OdbcLog.h +117 -0
- data/ext/quickfix/OdbcStore.cpp +338 -0
- data/ext/quickfix/OdbcStore.h +113 -0
- data/ext/quickfix/PUGIXML_DOMDocument.cpp +112 -0
- data/ext/quickfix/PUGIXML_DOMDocument.h +81 -0
- data/ext/quickfix/Parser.cpp +103 -0
- data/ext/quickfix/Parser.h +57 -0
- data/ext/quickfix/PostgreSQLConnection.h +176 -0
- data/ext/quickfix/PostgreSQLLog.cpp +276 -0
- data/ext/quickfix/PostgreSQLLog.h +144 -0
- data/ext/quickfix/PostgreSQLStore.cpp +334 -0
- data/ext/quickfix/PostgreSQLStore.h +141 -0
- data/ext/quickfix/Queue.h +75 -0
- data/ext/quickfix/QuickfixRuby.cpp +252066 -0
- data/ext/quickfix/QuickfixRuby.h +34 -0
- data/ext/quickfix/Responder.h +43 -0
- data/ext/quickfix/Session.cpp +1487 -0
- data/ext/quickfix/Session.h +335 -0
- data/ext/quickfix/SessionFactory.cpp +274 -0
- data/ext/quickfix/SessionFactory.h +86 -0
- data/ext/quickfix/SessionID.h +170 -0
- data/ext/quickfix/SessionSettings.cpp +189 -0
- data/ext/quickfix/SessionSettings.h +171 -0
- data/ext/quickfix/SessionState.h +231 -0
- data/ext/quickfix/Settings.cpp +100 -0
- data/ext/quickfix/Settings.h +53 -0
- data/ext/quickfix/SharedArray.h +150 -0
- data/ext/quickfix/SocketAcceptor.cpp +222 -0
- data/ext/quickfix/SocketAcceptor.h +75 -0
- data/ext/quickfix/SocketConnection.cpp +238 -0
- data/ext/quickfix/SocketConnection.h +103 -0
- data/ext/quickfix/SocketConnector.cpp +116 -0
- data/ext/quickfix/SocketConnector.h +67 -0
- data/ext/quickfix/SocketInitiator.cpp +260 -0
- data/ext/quickfix/SocketInitiator.h +81 -0
- data/ext/quickfix/SocketMonitor.cpp +335 -0
- data/ext/quickfix/SocketMonitor.h +111 -0
- data/ext/quickfix/SocketServer.cpp +177 -0
- data/ext/quickfix/SocketServer.h +100 -0
- data/ext/quickfix/ThreadedSocketAcceptor.cpp +258 -0
- data/ext/quickfix/ThreadedSocketAcceptor.h +98 -0
- data/ext/quickfix/ThreadedSocketConnection.cpp +209 -0
- data/ext/quickfix/ThreadedSocketConnection.h +82 -0
- data/ext/quickfix/ThreadedSocketInitiator.cpp +268 -0
- data/ext/quickfix/ThreadedSocketInitiator.h +84 -0
- data/ext/quickfix/TimeRange.cpp +173 -0
- data/ext/quickfix/TimeRange.h +258 -0
- data/ext/quickfix/Utility.cpp +537 -0
- data/ext/quickfix/Utility.h +219 -0
- data/ext/quickfix/Values.h +62 -0
- data/ext/quickfix/config.h +0 -0
- data/ext/quickfix/config_windows.h +0 -0
- data/ext/quickfix/extconf.rb +12 -0
- data/ext/quickfix/index.h +37 -0
- data/ext/quickfix/pugiconfig.hpp +72 -0
- data/ext/quickfix/pugixml.cpp +10765 -0
- data/ext/quickfix/pugixml.hpp +1341 -0
- data/ext/quickfix/strptime.h +7 -0
- data/lib/quickfix40.rb +274 -0
- data/lib/quickfix41.rb +351 -0
- data/lib/quickfix42.rb +1184 -0
- data/lib/quickfix43.rb +3504 -0
- data/lib/quickfix44.rb +10721 -0
- data/lib/quickfix50.rb +13426 -0
- data/lib/quickfix50sp1.rb +15629 -0
- data/lib/quickfix50sp2.rb +17068 -0
- data/lib/quickfix_fields.rb +19853 -0
- data/lib/quickfix_ruby.rb +82 -0
- data/lib/quickfixt11.rb +70 -0
- data/spec/FIX40.xml +862 -0
- data/spec/FIX41.xml +1285 -0
- data/spec/FIX42.xml +2746 -0
- data/spec/FIX43.xml +4229 -0
- data/spec/FIX44.xml +6596 -0
- data/spec/FIX50.xml +8137 -0
- data/spec/FIX50SP1.xml +9496 -0
- data/spec/FIX50SP2.xml +10011 -0
- data/spec/FIXT11.xml +313 -0
- data/test/test_DataDictionaryTestCase.rb +268 -0
- data/test/test_DictionaryTestCase.rb +112 -0
- data/test/test_FieldBaseTestCase.rb +24 -0
- data/test/test_MessageTestCase.rb +368 -0
- data/test/test_SessionSettingsTestCase.rb +41 -0
- metadata +193 -0
@@ -0,0 +1,200 @@
|
|
1
|
+
/****************************************************************************
|
2
|
+
** Copyright (c) 2001-2014
|
3
|
+
**
|
4
|
+
** This file is part of the QuickFIX FIX Engine
|
5
|
+
**
|
6
|
+
** This file may be distributed under the terms of the quickfixengine.org
|
7
|
+
** license as defined by quickfixengine.org and appearing in the file
|
8
|
+
** LICENSE included in the packaging of this file.
|
9
|
+
**
|
10
|
+
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
11
|
+
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
12
|
+
**
|
13
|
+
** See http://www.quickfixengine.org/LICENSE for licensing information.
|
14
|
+
**
|
15
|
+
** Contact ask@quickfixengine.org if any conditions of this licensing are
|
16
|
+
** not clear to you.
|
17
|
+
**
|
18
|
+
****************************************************************************/
|
19
|
+
|
20
|
+
#ifdef _MSC_VER
|
21
|
+
#include "stdafx.h"
|
22
|
+
#else
|
23
|
+
#include "config.h"
|
24
|
+
#endif
|
25
|
+
|
26
|
+
#include "FileLog.h"
|
27
|
+
|
28
|
+
namespace FIX
|
29
|
+
{
|
30
|
+
Log* FileLogFactory::create()
|
31
|
+
{
|
32
|
+
m_globalLogCount++;
|
33
|
+
if( m_globalLogCount > 1 ) return m_globalLog;
|
34
|
+
|
35
|
+
try
|
36
|
+
{
|
37
|
+
if ( m_path.size() ) return new FileLog( m_path );
|
38
|
+
std::string path;
|
39
|
+
std::string backupPath;
|
40
|
+
|
41
|
+
Dictionary settings = m_settings.get();
|
42
|
+
path = settings.getString( FILE_LOG_PATH );
|
43
|
+
backupPath = path;
|
44
|
+
if( settings.has( FILE_LOG_BACKUP_PATH ) )
|
45
|
+
backupPath = settings.getString( FILE_LOG_BACKUP_PATH );
|
46
|
+
|
47
|
+
return m_globalLog = new FileLog( path, backupPath );
|
48
|
+
}
|
49
|
+
catch( ConfigError& )
|
50
|
+
{
|
51
|
+
m_globalLogCount--;
|
52
|
+
throw;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
Log* FileLogFactory::create( const SessionID& s )
|
57
|
+
{
|
58
|
+
if ( m_path.size() && m_backupPath.size() )
|
59
|
+
return new FileLog( m_path, m_backupPath, s );
|
60
|
+
if ( m_path.size() )
|
61
|
+
return new FileLog( m_path, s );
|
62
|
+
|
63
|
+
std::string path;
|
64
|
+
std::string backupPath;
|
65
|
+
Dictionary settings = m_settings.get( s );
|
66
|
+
path = settings.getString( FILE_LOG_PATH );
|
67
|
+
backupPath = path;
|
68
|
+
if( settings.has( FILE_LOG_BACKUP_PATH ) )
|
69
|
+
backupPath = settings.getString( FILE_LOG_BACKUP_PATH );
|
70
|
+
|
71
|
+
return new FileLog( path, backupPath, s );
|
72
|
+
}
|
73
|
+
|
74
|
+
void FileLogFactory::destroy( Log* pLog )
|
75
|
+
{
|
76
|
+
if( pLog == m_globalLog )
|
77
|
+
{
|
78
|
+
m_globalLogCount--;
|
79
|
+
if( m_globalLogCount == 0 )
|
80
|
+
{
|
81
|
+
delete pLog;
|
82
|
+
m_globalLogCount = 0;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
else
|
86
|
+
{
|
87
|
+
delete pLog;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
FileLog::FileLog( const std::string& path )
|
92
|
+
: m_millisecondsInTimeStamp( true )
|
93
|
+
{
|
94
|
+
init( path, path, "GLOBAL" );
|
95
|
+
}
|
96
|
+
|
97
|
+
FileLog::FileLog( const std::string& path, const std::string& backupPath )
|
98
|
+
: m_millisecondsInTimeStamp( true )
|
99
|
+
{
|
100
|
+
init( path, backupPath, "GLOBAL" );
|
101
|
+
}
|
102
|
+
|
103
|
+
FileLog::FileLog( const std::string& path, const SessionID& s )
|
104
|
+
: m_millisecondsInTimeStamp( true )
|
105
|
+
{
|
106
|
+
init( path, path, generatePrefix(s) );
|
107
|
+
}
|
108
|
+
|
109
|
+
FileLog::FileLog( const std::string& path, const std::string& backupPath, const SessionID& s )
|
110
|
+
: m_millisecondsInTimeStamp( true )
|
111
|
+
{
|
112
|
+
init( path, backupPath, generatePrefix(s) );
|
113
|
+
}
|
114
|
+
|
115
|
+
std::string FileLog::generatePrefix( const SessionID& s )
|
116
|
+
{
|
117
|
+
const std::string& begin =
|
118
|
+
s.getBeginString().getString();
|
119
|
+
const std::string& sender =
|
120
|
+
s.getSenderCompID().getString();
|
121
|
+
const std::string& target =
|
122
|
+
s.getTargetCompID().getString();
|
123
|
+
const std::string& qualifier =
|
124
|
+
s.getSessionQualifier();
|
125
|
+
|
126
|
+
std::string prefix = begin + "-" + sender + "-" + target;
|
127
|
+
if( qualifier.size() )
|
128
|
+
prefix += "-" + qualifier;
|
129
|
+
|
130
|
+
return prefix;
|
131
|
+
}
|
132
|
+
|
133
|
+
void FileLog::init( std::string path, std::string backupPath, const std::string& prefix )
|
134
|
+
{
|
135
|
+
file_mkdir( path.c_str() );
|
136
|
+
file_mkdir( backupPath.c_str() );
|
137
|
+
|
138
|
+
if ( path.empty() ) path = ".";
|
139
|
+
if ( backupPath.empty() ) backupPath = path;
|
140
|
+
|
141
|
+
m_fullPrefix
|
142
|
+
= file_appendpath(path, prefix + ".");
|
143
|
+
m_fullBackupPrefix
|
144
|
+
= file_appendpath(backupPath, prefix + ".");
|
145
|
+
|
146
|
+
m_messagesFileName = m_fullPrefix + "messages.current.log";
|
147
|
+
m_eventFileName = m_fullPrefix + "event.current.log";
|
148
|
+
|
149
|
+
m_messages.open( m_messagesFileName.c_str(), std::ios::out | std::ios::app );
|
150
|
+
if ( !m_messages.is_open() ) throw ConfigError( "Could not open messages file: " + m_messagesFileName );
|
151
|
+
m_event.open( m_eventFileName.c_str(), std::ios::out | std::ios::app );
|
152
|
+
if ( !m_event.is_open() ) throw ConfigError( "Could not open event file: " + m_eventFileName );
|
153
|
+
}
|
154
|
+
|
155
|
+
FileLog::~FileLog()
|
156
|
+
{
|
157
|
+
m_messages.close();
|
158
|
+
m_event.close();
|
159
|
+
}
|
160
|
+
|
161
|
+
void FileLog::clear()
|
162
|
+
{
|
163
|
+
m_messages.close();
|
164
|
+
m_event.close();
|
165
|
+
|
166
|
+
m_messages.open( m_messagesFileName.c_str(), std::ios::out | std::ios::trunc );
|
167
|
+
m_event.open( m_eventFileName.c_str(), std::ios::out | std::ios::trunc );
|
168
|
+
}
|
169
|
+
|
170
|
+
void FileLog::backup()
|
171
|
+
{
|
172
|
+
m_messages.close();
|
173
|
+
m_event.close();
|
174
|
+
|
175
|
+
int i = 0;
|
176
|
+
while( true )
|
177
|
+
{
|
178
|
+
std::stringstream messagesFileName;
|
179
|
+
std::stringstream eventFileName;
|
180
|
+
|
181
|
+
messagesFileName << m_fullBackupPrefix << "messages.backup." << ++i << ".log";
|
182
|
+
eventFileName << m_fullBackupPrefix << "event.backup." << i << ".log";
|
183
|
+
FILE* messagesLogFile = file_fopen( messagesFileName.str().c_str(), "r" );
|
184
|
+
FILE* eventLogFile = file_fopen( eventFileName.str().c_str(), "r" );
|
185
|
+
|
186
|
+
if( messagesLogFile == NULL && eventLogFile == NULL )
|
187
|
+
{
|
188
|
+
file_rename( m_messagesFileName.c_str(), messagesFileName.str().c_str() );
|
189
|
+
file_rename( m_eventFileName.c_str(), eventFileName.str().c_str() );
|
190
|
+
m_messages.open( m_messagesFileName.c_str(), std::ios::out | std::ios::trunc );
|
191
|
+
m_event.open( m_eventFileName.c_str(), std::ios::out | std::ios::trunc );
|
192
|
+
return;
|
193
|
+
}
|
194
|
+
|
195
|
+
if( messagesLogFile != NULL ) file_fclose( messagesLogFile );
|
196
|
+
if( eventLogFile != NULL ) file_fclose( eventLogFile );
|
197
|
+
}
|
198
|
+
}
|
199
|
+
|
200
|
+
} //namespace FIX
|
@@ -0,0 +1,112 @@
|
|
1
|
+
/* -*- C++ -*- */
|
2
|
+
|
3
|
+
/****************************************************************************
|
4
|
+
** Copyright (c) 2001-2014
|
5
|
+
**
|
6
|
+
** This file is part of the QuickFIX FIX Engine
|
7
|
+
**
|
8
|
+
** This file may be distributed under the terms of the quickfixengine.org
|
9
|
+
** license as defined by quickfixengine.org and appearing in the file
|
10
|
+
** LICENSE included in the packaging of this file.
|
11
|
+
**
|
12
|
+
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
13
|
+
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
14
|
+
**
|
15
|
+
** See http://www.quickfixengine.org/LICENSE for licensing information.
|
16
|
+
**
|
17
|
+
** Contact ask@quickfixengine.org if any conditions of this licensing are
|
18
|
+
** not clear to you.
|
19
|
+
**
|
20
|
+
****************************************************************************/
|
21
|
+
|
22
|
+
#ifndef FIX_FILELOG_H
|
23
|
+
#define FIX_FILELOG_H
|
24
|
+
|
25
|
+
#ifdef _MSC_VER
|
26
|
+
#pragma warning( disable : 4503 4355 4786 4290 )
|
27
|
+
#endif
|
28
|
+
|
29
|
+
#include "Log.h"
|
30
|
+
#include "SessionSettings.h"
|
31
|
+
#include <fstream>
|
32
|
+
|
33
|
+
namespace FIX
|
34
|
+
{
|
35
|
+
/**
|
36
|
+
* Creates a file based implementation of Log
|
37
|
+
*
|
38
|
+
* This stores all log events into flat files
|
39
|
+
*/
|
40
|
+
class FileLogFactory : public LogFactory
|
41
|
+
{
|
42
|
+
public:
|
43
|
+
FileLogFactory( const SessionSettings& settings )
|
44
|
+
: m_settings( settings ), m_globalLog(0), m_globalLogCount(0) {};
|
45
|
+
FileLogFactory( const std::string& path )
|
46
|
+
: m_path( path ), m_backupPath( path ), m_globalLog(0), m_globalLogCount(0) {};
|
47
|
+
FileLogFactory( const std::string& path, const std::string& backupPath )
|
48
|
+
: m_path( path ), m_backupPath( backupPath ), m_globalLog(0), m_globalLogCount(0) {};
|
49
|
+
|
50
|
+
public:
|
51
|
+
Log* create();
|
52
|
+
Log* create( const SessionID& );
|
53
|
+
void destroy( Log* log );
|
54
|
+
|
55
|
+
private:
|
56
|
+
std::string m_path;
|
57
|
+
std::string m_backupPath;
|
58
|
+
SessionSettings m_settings;
|
59
|
+
Log* m_globalLog;
|
60
|
+
int m_globalLogCount;
|
61
|
+
};
|
62
|
+
|
63
|
+
/**
|
64
|
+
* File based implementation of Log
|
65
|
+
*
|
66
|
+
* Two files are created by this implementation. One for messages,
|
67
|
+
* and one for events.
|
68
|
+
*
|
69
|
+
*/
|
70
|
+
class FileLog : public Log
|
71
|
+
{
|
72
|
+
public:
|
73
|
+
FileLog( const std::string& path );
|
74
|
+
FileLog( const std::string& path, const std::string& backupPath );
|
75
|
+
FileLog( const std::string& path, const SessionID& sessionID );
|
76
|
+
FileLog( const std::string& path, const std::string& backupPath, const SessionID& sessionID );
|
77
|
+
virtual ~FileLog();
|
78
|
+
|
79
|
+
void clear();
|
80
|
+
void backup();
|
81
|
+
|
82
|
+
void onIncoming( const std::string& value )
|
83
|
+
{ m_messages << UtcTimeStampConvertor::convert(UtcTimeStamp(), m_millisecondsInTimeStamp) << " : " << value << std::endl; }
|
84
|
+
void onOutgoing( const std::string& value )
|
85
|
+
{ m_messages << UtcTimeStampConvertor::convert(UtcTimeStamp(), m_millisecondsInTimeStamp) << " : " << value << std::endl; }
|
86
|
+
void onEvent( const std::string& value )
|
87
|
+
{
|
88
|
+
UtcTimeStamp now;
|
89
|
+
m_event << UtcTimeStampConvertor::convert( now, m_millisecondsInTimeStamp )
|
90
|
+
<< " : " << value << std::endl;
|
91
|
+
}
|
92
|
+
|
93
|
+
bool getMillisecondsInTimeStamp() const
|
94
|
+
{ return m_millisecondsInTimeStamp; }
|
95
|
+
void setMillisecondsInTimeStamp ( bool value )
|
96
|
+
{ m_millisecondsInTimeStamp = value; }
|
97
|
+
|
98
|
+
private:
|
99
|
+
std::string generatePrefix( const SessionID& sessionID );
|
100
|
+
void init( std::string path, std::string backupPath, const std::string& prefix );
|
101
|
+
|
102
|
+
std::ofstream m_messages;
|
103
|
+
std::ofstream m_event;
|
104
|
+
std::string m_messagesFileName;
|
105
|
+
std::string m_eventFileName;
|
106
|
+
std::string m_fullPrefix;
|
107
|
+
std::string m_fullBackupPrefix;
|
108
|
+
bool m_millisecondsInTimeStamp;
|
109
|
+
};
|
110
|
+
}
|
111
|
+
|
112
|
+
#endif //FIX_LOG_H
|
@@ -0,0 +1,332 @@
|
|
1
|
+
/****************************************************************************
|
2
|
+
** Copyright (c) 2001-2014
|
3
|
+
**
|
4
|
+
** This file is part of the QuickFIX FIX Engine
|
5
|
+
**
|
6
|
+
** This file may be distributed under the terms of the quickfixengine.org
|
7
|
+
** license as defined by quickfixengine.org and appearing in the file
|
8
|
+
** LICENSE included in the packaging of this file.
|
9
|
+
**
|
10
|
+
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
11
|
+
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
12
|
+
**
|
13
|
+
** See http://www.quickfixengine.org/LICENSE for licensing information.
|
14
|
+
**
|
15
|
+
** Contact ask@quickfixengine.org if any conditions of this licensing are
|
16
|
+
** not clear to you.
|
17
|
+
**
|
18
|
+
****************************************************************************/
|
19
|
+
|
20
|
+
#ifdef _MSC_VER
|
21
|
+
#include "stdafx.h"
|
22
|
+
#else
|
23
|
+
#include "config.h"
|
24
|
+
#endif
|
25
|
+
|
26
|
+
#include "FileStore.h"
|
27
|
+
#include "SessionID.h"
|
28
|
+
#include "Parser.h"
|
29
|
+
#include "Utility.h"
|
30
|
+
#include <fstream>
|
31
|
+
|
32
|
+
namespace FIX
|
33
|
+
{
|
34
|
+
FileStore::FileStore( std::string path, const SessionID& s )
|
35
|
+
: m_msgFile( 0 ), m_headerFile( 0 ), m_seqNumsFile( 0 ), m_sessionFile( 0 )
|
36
|
+
{
|
37
|
+
file_mkdir( path.c_str() );
|
38
|
+
|
39
|
+
if ( path.empty() ) path = ".";
|
40
|
+
const std::string& begin =
|
41
|
+
s.getBeginString().getString();
|
42
|
+
const std::string& sender =
|
43
|
+
s.getSenderCompID().getString();
|
44
|
+
const std::string& target =
|
45
|
+
s.getTargetCompID().getString();
|
46
|
+
const std::string& qualifier =
|
47
|
+
s.getSessionQualifier();
|
48
|
+
|
49
|
+
std::string sessionid = begin + "-" + sender + "-" + target;
|
50
|
+
if( qualifier.size() )
|
51
|
+
sessionid += "-" + qualifier;
|
52
|
+
|
53
|
+
std::string prefix
|
54
|
+
= file_appendpath(path, sessionid + ".");
|
55
|
+
|
56
|
+
m_msgFileName = prefix + "body";
|
57
|
+
m_headerFileName = prefix + "header";
|
58
|
+
m_seqNumsFileName = prefix + "seqnums";
|
59
|
+
m_sessionFileName = prefix + "session";
|
60
|
+
|
61
|
+
try
|
62
|
+
{
|
63
|
+
open( false );
|
64
|
+
}
|
65
|
+
catch ( IOException & e )
|
66
|
+
{
|
67
|
+
throw ConfigError( e.what() );
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
FileStore::~FileStore()
|
72
|
+
{
|
73
|
+
if( m_msgFile ) fclose( m_msgFile );
|
74
|
+
if( m_headerFile ) fclose( m_headerFile );
|
75
|
+
if( m_seqNumsFile ) fclose( m_seqNumsFile );
|
76
|
+
if( m_sessionFile ) fclose( m_sessionFile );
|
77
|
+
}
|
78
|
+
|
79
|
+
void FileStore::open( bool deleteFile )
|
80
|
+
{
|
81
|
+
if ( m_msgFile ) fclose( m_msgFile );
|
82
|
+
if ( m_headerFile ) fclose( m_headerFile );
|
83
|
+
if ( m_seqNumsFile ) fclose( m_seqNumsFile );
|
84
|
+
if ( m_sessionFile ) fclose( m_sessionFile );
|
85
|
+
|
86
|
+
m_msgFile = 0;
|
87
|
+
m_headerFile = 0;
|
88
|
+
m_seqNumsFile = 0;
|
89
|
+
m_sessionFile = 0;
|
90
|
+
|
91
|
+
if ( deleteFile )
|
92
|
+
{
|
93
|
+
file_unlink( m_msgFileName.c_str() );
|
94
|
+
file_unlink( m_headerFileName.c_str() );
|
95
|
+
file_unlink( m_seqNumsFileName.c_str() );
|
96
|
+
file_unlink( m_sessionFileName.c_str() );
|
97
|
+
}
|
98
|
+
|
99
|
+
populateCache();
|
100
|
+
m_msgFile = file_fopen( m_msgFileName.c_str(), "r+" );
|
101
|
+
if ( !m_msgFile ) m_msgFile = file_fopen( m_msgFileName.c_str(), "w+" );
|
102
|
+
if ( !m_msgFile ) throw ConfigError( "Could not open body file: " + m_msgFileName );
|
103
|
+
|
104
|
+
m_headerFile = file_fopen( m_headerFileName.c_str(), "r+" );
|
105
|
+
if ( !m_headerFile ) m_headerFile = file_fopen( m_headerFileName.c_str(), "w+" );
|
106
|
+
if ( !m_headerFile ) throw ConfigError( "Could not open header file: " + m_headerFileName );
|
107
|
+
|
108
|
+
m_seqNumsFile = file_fopen( m_seqNumsFileName.c_str(), "r+" );
|
109
|
+
if ( !m_seqNumsFile ) m_seqNumsFile = file_fopen( m_seqNumsFileName.c_str(), "w+" );
|
110
|
+
if ( !m_seqNumsFile ) throw ConfigError( "Could not open seqnums file: " + m_seqNumsFileName );
|
111
|
+
|
112
|
+
bool setCreationTime = false;
|
113
|
+
m_sessionFile = file_fopen( m_sessionFileName.c_str(), "r" );
|
114
|
+
if ( !m_sessionFile ) setCreationTime = true;
|
115
|
+
else fclose( m_sessionFile );
|
116
|
+
|
117
|
+
m_sessionFile = file_fopen( m_sessionFileName.c_str(), "r+" );
|
118
|
+
if ( !m_sessionFile ) m_sessionFile = file_fopen( m_sessionFileName.c_str(), "w+" );
|
119
|
+
if ( !m_sessionFile ) throw ConfigError( "Could not open session file" );
|
120
|
+
if ( setCreationTime ) setSession();
|
121
|
+
|
122
|
+
setNextSenderMsgSeqNum( getNextSenderMsgSeqNum() );
|
123
|
+
setNextTargetMsgSeqNum( getNextTargetMsgSeqNum() );
|
124
|
+
}
|
125
|
+
|
126
|
+
void FileStore::populateCache()
|
127
|
+
{
|
128
|
+
FILE* headerFile = file_fopen( m_headerFileName.c_str(), "r+" );
|
129
|
+
if ( headerFile )
|
130
|
+
{
|
131
|
+
int num;
|
132
|
+
long offset;
|
133
|
+
size_t size;
|
134
|
+
|
135
|
+
while ( FILE_FSCANF( headerFile, "%d,%ld,%lu ", &num, &offset, &size ) == 3 )
|
136
|
+
m_offsets[ num ] = std::make_pair( offset, size );
|
137
|
+
fclose( headerFile );
|
138
|
+
}
|
139
|
+
|
140
|
+
FILE* seqNumsFile = file_fopen( m_seqNumsFileName.c_str(), "r+" );
|
141
|
+
if ( seqNumsFile )
|
142
|
+
{
|
143
|
+
int sender, target;
|
144
|
+
if ( FILE_FSCANF( seqNumsFile, "%d : %d", &sender, &target ) == 2 )
|
145
|
+
{
|
146
|
+
m_cache.setNextSenderMsgSeqNum( sender );
|
147
|
+
m_cache.setNextTargetMsgSeqNum( target );
|
148
|
+
}
|
149
|
+
fclose( seqNumsFile );
|
150
|
+
}
|
151
|
+
|
152
|
+
FILE* sessionFile = file_fopen( m_sessionFileName.c_str(), "r+" );
|
153
|
+
if ( sessionFile )
|
154
|
+
{
|
155
|
+
char time[ 22 ];
|
156
|
+
#ifdef HAVE_FSCANF_S
|
157
|
+
int result = FILE_FSCANF( sessionFile, "%s", time, 22 );
|
158
|
+
#else
|
159
|
+
int result = FILE_FSCANF( sessionFile, "%s", time );
|
160
|
+
#endif
|
161
|
+
if( result == 1 )
|
162
|
+
{
|
163
|
+
m_cache.setCreationTime( UtcTimeStampConvertor::convert( time, true ) );
|
164
|
+
}
|
165
|
+
fclose( sessionFile );
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
MessageStore* FileStoreFactory::create( const SessionID& s )
|
170
|
+
{
|
171
|
+
if ( m_path.size() ) return new FileStore( m_path, s );
|
172
|
+
|
173
|
+
std::string path;
|
174
|
+
Dictionary settings = m_settings.get( s );
|
175
|
+
path = settings.getString( FILE_STORE_PATH );
|
176
|
+
return new FileStore( path, s );
|
177
|
+
}
|
178
|
+
|
179
|
+
void FileStoreFactory::destroy( MessageStore* pStore )
|
180
|
+
{
|
181
|
+
delete pStore;
|
182
|
+
}
|
183
|
+
|
184
|
+
bool FileStore::set( int msgSeqNum, const std::string& msg )
|
185
|
+
throw ( IOException )
|
186
|
+
{
|
187
|
+
if ( fseek( m_msgFile, 0, SEEK_END ) )
|
188
|
+
throw IOException( "Cannot seek to end of " + m_msgFileName );
|
189
|
+
if ( fseek( m_headerFile, 0, SEEK_END ) )
|
190
|
+
throw IOException( "Cannot seek to end of " + m_headerFileName );
|
191
|
+
|
192
|
+
long offset = ftell( m_msgFile );
|
193
|
+
if ( offset < 0 )
|
194
|
+
throw IOException( "Unable to get file pointer position from " + m_msgFileName );
|
195
|
+
size_t size = msg.size();
|
196
|
+
|
197
|
+
if ( fprintf( m_headerFile, "%d,%ld,%lu ", msgSeqNum, offset, size ) < 0 )
|
198
|
+
throw IOException( "Unable to write to file " + m_headerFileName );
|
199
|
+
m_offsets[ msgSeqNum ] = std::make_pair( offset, size );
|
200
|
+
fwrite( msg.c_str(), sizeof( char ), msg.size(), m_msgFile );
|
201
|
+
if ( ferror( m_msgFile ) )
|
202
|
+
throw IOException( "Unable to write to file " + m_msgFileName );
|
203
|
+
if ( fflush( m_msgFile ) == EOF )
|
204
|
+
throw IOException( "Unable to flush file " + m_msgFileName );
|
205
|
+
if ( fflush( m_headerFile ) == EOF )
|
206
|
+
throw IOException( "Unable to flush file " + m_headerFileName );
|
207
|
+
return true;
|
208
|
+
}
|
209
|
+
|
210
|
+
void FileStore::get( int begin, int end,
|
211
|
+
std::vector < std::string > & result ) const
|
212
|
+
throw ( IOException )
|
213
|
+
{
|
214
|
+
result.clear();
|
215
|
+
std::string msg;
|
216
|
+
for ( int i = begin; i <= end; ++i )
|
217
|
+
{
|
218
|
+
if ( get( i, msg ) )
|
219
|
+
result.push_back( msg );
|
220
|
+
}
|
221
|
+
}
|
222
|
+
|
223
|
+
int FileStore::getNextSenderMsgSeqNum() const throw ( IOException )
|
224
|
+
{
|
225
|
+
return m_cache.getNextSenderMsgSeqNum();
|
226
|
+
}
|
227
|
+
|
228
|
+
int FileStore::getNextTargetMsgSeqNum() const throw ( IOException )
|
229
|
+
{
|
230
|
+
return m_cache.getNextTargetMsgSeqNum();
|
231
|
+
}
|
232
|
+
|
233
|
+
void FileStore::setNextSenderMsgSeqNum( int value ) throw ( IOException )
|
234
|
+
{
|
235
|
+
m_cache.setNextSenderMsgSeqNum( value );
|
236
|
+
setSeqNum();
|
237
|
+
}
|
238
|
+
|
239
|
+
void FileStore::setNextTargetMsgSeqNum( int value ) throw ( IOException )
|
240
|
+
{
|
241
|
+
m_cache.setNextTargetMsgSeqNum( value );
|
242
|
+
setSeqNum();
|
243
|
+
}
|
244
|
+
|
245
|
+
void FileStore::incrNextSenderMsgSeqNum() throw ( IOException )
|
246
|
+
{
|
247
|
+
m_cache.incrNextSenderMsgSeqNum();
|
248
|
+
setSeqNum();
|
249
|
+
}
|
250
|
+
|
251
|
+
void FileStore::incrNextTargetMsgSeqNum() throw ( IOException )
|
252
|
+
{
|
253
|
+
m_cache.incrNextTargetMsgSeqNum();
|
254
|
+
setSeqNum();
|
255
|
+
}
|
256
|
+
|
257
|
+
UtcTimeStamp FileStore::getCreationTime() const throw ( IOException )
|
258
|
+
{
|
259
|
+
return m_cache.getCreationTime();
|
260
|
+
}
|
261
|
+
|
262
|
+
void FileStore::reset() throw ( IOException )
|
263
|
+
{
|
264
|
+
try
|
265
|
+
{
|
266
|
+
m_cache.reset();
|
267
|
+
open( true );
|
268
|
+
setSession();
|
269
|
+
}
|
270
|
+
catch( std::exception& e )
|
271
|
+
{
|
272
|
+
throw IOException( e.what() );
|
273
|
+
}
|
274
|
+
}
|
275
|
+
|
276
|
+
void FileStore::refresh() throw ( IOException )
|
277
|
+
{
|
278
|
+
try
|
279
|
+
{
|
280
|
+
m_cache.reset();
|
281
|
+
open( false );
|
282
|
+
}
|
283
|
+
catch( std::exception& e )
|
284
|
+
{
|
285
|
+
throw IOException( e.what() );
|
286
|
+
}
|
287
|
+
}
|
288
|
+
|
289
|
+
void FileStore::setSeqNum()
|
290
|
+
{
|
291
|
+
rewind( m_seqNumsFile );
|
292
|
+
fprintf( m_seqNumsFile, "%10.10d : %10.10d",
|
293
|
+
getNextSenderMsgSeqNum(), getNextTargetMsgSeqNum() );
|
294
|
+
if ( ferror( m_seqNumsFile ) )
|
295
|
+
throw IOException( "Unable to write to file " + m_seqNumsFileName );
|
296
|
+
if ( fflush( m_seqNumsFile ) )
|
297
|
+
throw IOException( "Unable to flush file " + m_seqNumsFileName );
|
298
|
+
}
|
299
|
+
|
300
|
+
void FileStore::setSession()
|
301
|
+
{
|
302
|
+
rewind( m_sessionFile );
|
303
|
+
fprintf( m_sessionFile, "%s",
|
304
|
+
UtcTimeStampConvertor::convert( m_cache.getCreationTime() ).c_str() );
|
305
|
+
if ( ferror( m_sessionFile ) )
|
306
|
+
throw IOException( "Unable to write to file " + m_sessionFileName );
|
307
|
+
if ( fflush( m_sessionFile ) )
|
308
|
+
throw IOException( "Unable to flush file " + m_sessionFileName );
|
309
|
+
}
|
310
|
+
|
311
|
+
bool FileStore::get( int msgSeqNum, std::string& msg ) const
|
312
|
+
throw ( IOException )
|
313
|
+
{
|
314
|
+
NumToOffset::const_iterator find = m_offsets.find( msgSeqNum );
|
315
|
+
if ( find == m_offsets.end() ) return false;
|
316
|
+
const OffsetSize& offset = find->second;
|
317
|
+
if ( fseek( m_msgFile, offset.first, SEEK_SET ) )
|
318
|
+
throw IOException( "Unable to seek in file " + m_msgFileName );
|
319
|
+
char* buffer = new char[ offset.second + 1 ];
|
320
|
+
size_t result = fread( buffer, sizeof( char ), offset.second, m_msgFile );
|
321
|
+
if ( ferror( m_msgFile ) || result != (size_t)offset.second )
|
322
|
+
{
|
323
|
+
delete [] buffer;
|
324
|
+
throw IOException( "Unable to read from file " + m_msgFileName );
|
325
|
+
}
|
326
|
+
buffer[ offset.second ] = 0;
|
327
|
+
msg = buffer;
|
328
|
+
delete [] buffer;
|
329
|
+
return true;
|
330
|
+
}
|
331
|
+
|
332
|
+
} //namespace FIX
|