This commit is contained in:
Pedro Pinto committed 2017-10-15 17:59:31 -04:00
1 parent a19415dfe9
commit 2ddd467151
671 files changed
+124855

No files matched your search

+127
View File
@@ -0,0 +1,127 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_ACCEPTOR_H
#define FIX_ACCEPTOR_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Application.h"
#include "MessageStore.h"
#include "Log.h"
#include "Responder.h"
#include "SessionSettings.h"
#include "Exceptions.h"
#include <map>
#include <string>
namespace FIX
{
class Client;
class Session;
/**
* Base for classes which act as an acceptor for incoming connections.
*
* Most users will not need to implement one of these. The default
* SocketAcceptor implementation will be used in most cases.
*/
class Acceptor
{
public:
Acceptor( Application&, MessageStoreFactory&,
const SessionSettings& ) throw( ConfigError );
Acceptor( Application&, MessageStoreFactory&,
const SessionSettings&, LogFactory& ) throw( ConfigError );
virtual ~Acceptor();
Log* getLog()
{
if( m_pLog ) return m_pLog;
return &m_nullLog;
}
/// Start acceptor.
void start() throw ( ConfigError, RuntimeError );
/// Block on the acceptor
void block() throw ( ConfigError, RuntimeError );
/// Poll the acceptor
bool poll( double timeout = 0.0 ) throw ( ConfigError, RuntimeError );
/// Stop acceptor.
void stop( bool force = false );
/// Check to see if any sessions are currently logged on
bool isLoggedOn();
Session* getSession( const std::string& msg, Responder& );
const std::set<SessionID>& getSessions() const { return m_sessionIDs; }
Session* getSession( const SessionID& sessionID ) const;
const Dictionary* const getSessionSettings( const SessionID& sessionID ) const;
bool has( const SessionID& id )
{ return m_sessions.find( id ) != m_sessions.end(); }
bool isStopped() { return m_stop; }
Application& getApplication() { return m_application; }
MessageStoreFactory& getMessageStoreFactory()
{ return m_messageStoreFactory; }
private:
void initialize() throw ( ConfigError );
/// Implemented to configure acceptor
virtual void onConfigure( const SessionSettings& ) throw ( ConfigError ) {};
/// Implemented to initialize acceptor
virtual void onInitialize( const SessionSettings& ) throw ( RuntimeError ) {};
/// Implemented to start listening for connections.
virtual void onStart() = 0;
/// Implemented to connect and poll for events.
virtual bool onPoll( double second ) = 0;
/// Implemented to stop a running acceptor.
virtual void onStop() = 0;
static THREAD_PROC startThread( void* p );
typedef std::set < SessionID > SessionIDs;
typedef std::map < SessionID, Session* > Sessions;
thread_id m_threadid;
Sessions m_sessions;
SessionIDs m_sessionIDs;
Application& m_application;
MessageStoreFactory& m_messageStoreFactory;
SessionSettings m_settings;
LogFactory* m_pLogFactory;
Log* m_pLog;
NullLog m_nullLog;
bool m_firstPoll;
bool m_stop;
};
/*! @} */
}
#endif // FIX_ACCEPTOR_H
+9
View File
@@ -0,0 +1,9 @@
/* #undef ENABLE_BITMAP_ALLOCATOR */
/* #undef ENABLE_BOOST_FAST_POOL_ALLOCATOR */
/* #undef ENABLE_BOOST_POOL_ALLOCATOR */
/* #undef ENABLE_DEBUG_ALLOCATOR */
/* #undef ENABLE_MT_ALLOCATOR */
/* #undef ENABLE_NEW_ALLOCATOR */
/* #undef ENABLE_POOL_ALLOCATOR */
/* #undef ENABLE_TBB_ALLOCATOR */
/* #undef HAVE_ALLOCATOR_CONFIG */
+127
View File
@@ -0,0 +1,127 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_APPLICATION_H
#define FIX_APPLICATION_H
#include "Message.h"
#include "SessionID.h"
#include "Mutex.h"
namespace FIX
{
/**
* This interface must be implemented to define what your %FIX application
* does.
*
* These methods notify your application about events that happen on
* active %FIX sessions. There is no guarantee how many threads will be calling
* these functions. If the application is sharing resources among multiple sessions,
* you must synchronize those resources. You can also use the SynchronizedApplication
* class to automatically synchronize all function calls into your application.
* The various MessageCracker classes can be used to parse the generic message
* structure into specific %FIX messages.
*/
class Application
{
public:
virtual ~Application() {};
/// Notification of a session begin created
virtual void onCreate( const SessionID& ) = 0;
/// Notification of a session successfully logging on
virtual void onLogon( const SessionID& ) = 0;
/// Notification of a session logging off or disconnecting
virtual void onLogout( const SessionID& ) = 0;
/// Notification of admin message being sent to target
virtual void toAdmin( Message&, const SessionID& ) = 0;
/// Notification of app message being sent to target
virtual void toApp( Message&, const SessionID& )
throw( DoNotSend ) = 0;
/// Notification of admin message being received from target
virtual void fromAdmin( const Message&, const SessionID& )
throw( FieldNotFound, IncorrectDataFormat, IncorrectTagValue, RejectLogon ) = 0;
/// Notification of app message being received from target
virtual void fromApp( const Message&, const SessionID& )
throw( FieldNotFound, IncorrectDataFormat, IncorrectTagValue, UnsupportedMessageType ) = 0;
};
/**
* This is a special implementation of the Application interface that takes
* in another Application interface and synchronizes all of its callbacks. This
* will guarantee that only one thread will access the applications code at a time.
*
* This class is a great convenience for writing applications where you
* don't want to worry about synchronization. There is of course a tradeoff
* in that you may be synchronizing more than you need to. There is also a very
* minor performance penalty due to the extra virtual table lookup.
*/
class SynchronizedApplication : public Application
{
public:
SynchronizedApplication( Application& app ) : m_app( app ) {}
void onCreate( const SessionID& sessionID )
{ Locker l( m_mutex ); app().onCreate( sessionID ); }
void onLogon( const SessionID& sessionID )
{ Locker l( m_mutex ); app().onLogon( sessionID ); }
void onLogout( const SessionID& sessionID )
{ Locker l( m_mutex ); app().onLogout( sessionID ); }
void toAdmin( Message& message, const SessionID& sessionID )
{ Locker l( m_mutex ); app().toAdmin( message, sessionID ); }
void toApp( Message& message, const SessionID& sessionID )
throw( DoNotSend )
{ Locker l( m_mutex ); app().toApp( message, sessionID ); }
void fromAdmin( const Message& message, const SessionID& sessionID )
throw( FieldNotFound, IncorrectDataFormat, IncorrectTagValue, RejectLogon )
{ Locker l( m_mutex ); app().fromAdmin( message, sessionID ); }
void fromApp( const Message& message, const SessionID& sessionID )
throw( FieldNotFound, IncorrectDataFormat, IncorrectTagValue, UnsupportedMessageType )
{ Locker l( m_mutex ); app().fromApp( message, sessionID ); }
Mutex m_mutex;
Application& app() { return m_app; }
Application& m_app;
};
/**
* An empty implementation of an Application. This can be used if you
* do not want to provide an implementation for all the callback methods.
* It is also useful for unit tests writing unit tests where the callback
* values of some or all methods are not of interest.
*/
class NullApplication : public Application
{
void onCreate( const SessionID& ) {}
void onLogon( const SessionID& ) {}
void onLogout( const SessionID& ) {}
void toAdmin( Message&, const SessionID& ) {}
void toApp( Message&, const SessionID& )
throw( DoNotSend ) {}
void fromAdmin( const Message&, const SessionID& )
throw( FieldNotFound, IncorrectDataFormat, IncorrectTagValue, RejectLogon ) {}
void fromApp( const Message&, const SessionID& )
throw( FieldNotFound, IncorrectDataFormat, IncorrectTagValue, UnsupportedMessageType ) {}
};
/*! @} */
}
#endif //FIX_APPLICATION_H
+109
View File
@@ -0,0 +1,109 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef ATOMIC_COUNT
#define ATOMIC_COUNT
#include "Mutex.h"
namespace FIX
{
/// Atomic count class - consider using interlocked functions
#ifdef ENABLE_BOOST_ATOMIC_COUNT
#include <boost/smart_ptr/detail/atomic_count.hpp>
typedef boost::detail::atomic_count atomic_count;
#elif _MSC_VER
//atomic counter based on interlocked functions for Win32
class atomic_count
{
public:
explicit atomic_count( long v ): m_counter( v )
{
}
long operator++()
{
return ::InterlockedIncrement( &m_counter );
}
long operator--()
{
return ::InterlockedDecrement( &m_counter );
}
operator long() const
{
return static_cast<long const volatile &>( m_counter );
}
private:
atomic_count( atomic_count const & );
atomic_count & operator=( atomic_count const & );
long volatile m_counter;
};
#else
// general purpose atomic counter using mutexes
class atomic_count
{
public:
explicit atomic_count( long v ): m_counter( v )
{
}
long operator++()
{
Locker _lock(m_mutex);
return ++m_counter;
}
long operator--()
{
Locker _lock(m_mutex);
return --m_counter;
}
operator long() const
{
return static_cast<long const volatile &>( m_counter );
}
private:
atomic_count( atomic_count const & );
atomic_count & operator=( atomic_count const & );
Mutex m_mutex;
long m_counter;
};
#endif
}
#endif
+74
View File
@@ -0,0 +1,74 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_DOMDOCUMENT_H
#define FIX_DOMDOCUMENT_H
#include <string>
#include <map>
#include <iostream>
#include <memory>
namespace FIX
{
/// Interface that represents attribute from underlying XML parser.
class DOMAttributes
{
public:
typedef std::map<std::string, std::string> map;
virtual ~DOMAttributes() {}
virtual bool get( const std::string&, std::string& ) = 0;
virtual map toMap() = 0;
};
typedef std::auto_ptr<DOMAttributes> DOMAttributesPtr;
/// Interface that represents node from underlying XML parser.
class DOMNode
{
public:
virtual ~DOMNode() {}
virtual std::auto_ptr<DOMNode> getFirstChildNode() = 0;
virtual std::auto_ptr<DOMNode> getNextSiblingNode() = 0;
virtual std::auto_ptr<DOMAttributes> getAttributes() = 0;
virtual std::string getName() = 0;
virtual std::string getText() = 0;
};
typedef std::auto_ptr<DOMNode> DOMNodePtr;
/// Interface that represents document of underlying XML parser.
class DOMDocument
{
public:
virtual ~DOMDocument() {}
virtual bool load( std::istream& ) = 0;
virtual bool load( const std::string& ) = 0;
virtual bool xml( std::ostream& ) = 0;
virtual std::auto_ptr<DOMNode> getNode( const std::string& ) = 0;
};
typedef std::auto_ptr<DOMDocument> DOMDocumentPtr;
}
#endif
+539
View File
@@ -0,0 +1,539 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_DATADICTIONARY_H
#define FIX_DATADICTIONARY_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Fields.h"
#include "FieldMap.h"
#include "DOMDocument.h"
#include "Exceptions.h"
#include <set>
#include <map>
#include <string.h>
namespace FIX
{
class FieldMap;
class Message;
/**
* Represents a data dictionary for a version of %FIX.
*
* Generally loaded from an XML document. The DataDictionary is also
* responsible for validation beyond the basic structure of a message.
*/
class DataDictionary
{
typedef std::set < int > MsgFields;
typedef std::map < std::string, MsgFields > MsgTypeToField;
typedef std::set < std::string > MsgTypes;
typedef std::set < int > Fields;
typedef std::map < int, bool > NonBodyFields;
typedef std::vector< int > OrderedFields;
typedef message_order OrderedFieldsArray;
typedef std::map < int, TYPE::Type > FieldTypes;
typedef std::set < std::string > Values;
typedef std::map < int, Values > FieldToValue;
typedef std::map < int, std::string > FieldToName;
typedef std::map < std::string, int > NameToField;
typedef std::map < std::pair < int, std::string > , std::string > ValueToName;
// while FieldToGroup structure seems to be overcomplicated
// in reality it yields a lot of performance because:
// 1) avoids memory copying;
// 2) first lookup is done by comparing integers and not string objects
// TODO: use hash_map with good hashing algorithm
typedef std::map < std::string, std::pair < int, DataDictionary* > > FieldPresenceMap;
typedef std::map < int, FieldPresenceMap > FieldToGroup;
public:
DataDictionary();
DataDictionary( const DataDictionary& copy );
DataDictionary( std::istream& stream ) throw( ConfigError );
DataDictionary( const std::string& url ) throw( ConfigError );
virtual ~DataDictionary();
void readFromURL( const std::string& url ) throw( ConfigError );
void readFromDocument( DOMDocumentPtr pDoc ) throw( ConfigError );
void readFromStream( std::istream& stream ) throw( ConfigError );
message_order const& getOrderedFields() const;
// storage functions
void setVersion( const std::string& beginString )
{
m_beginString = beginString;
m_hasVersion = true;
}
std::string getVersion() const
{
return m_beginString.getString();
}
void addField( int field )
{
m_fields.insert( field );
m_orderedFields.push_back( field );
}
void addFieldName( int field, const std::string& name )
{
if( m_names.insert( std::make_pair(name, field) ).second == false )
throw ConfigError( "Field named " + name + " defined multiple times" );
m_fieldNames[field] = name;
}
bool getFieldName( int field, std::string& name ) const
{
FieldToName::const_iterator i = m_fieldNames.find( field );
if(i == m_fieldNames.end()) return false;
name = i->second;
return true;
}
bool getFieldTag( const std::string& name, int& field ) const
{
NameToField::const_iterator i = m_names.find( name );
if(i == m_names.end()) return false;
field = i->second;
return true;
}
void addValueName( int field, const std::string& value, const std::string& name )
{
m_valueNames[std::make_pair(field, value)] = name;
}
bool getValueName( int field, const std::string& value, std::string& name ) const
{
ValueToName::const_iterator i = m_valueNames.find( std::make_pair(field, value) );
if(i == m_valueNames.end()) return false;
name = i->second;
return true;
}
bool isField( int field ) const
{
return m_fields.find( field ) != m_fields.end();
}
void addMsgType( const std::string& msgType )
{
m_messages.insert( msgType );
}
bool isMsgType( const std::string& msgType ) const
{
return m_messages.find( msgType ) != m_messages.end();
}
void addMsgField( const std::string& msgType, int field )
{
m_messageFields[ msgType ].insert( field );
}
bool isMsgField( const std::string& msgType, int field ) const
{
MsgTypeToField::const_iterator i = m_messageFields.find( msgType );
if ( i == m_messageFields.end() ) return false;
return i->second.find( field ) != i->second.end();
}
void addHeaderField( int field, bool required )
{
m_headerFields[ field ] = required;
}
bool isHeaderField( int field ) const
{
return m_headerFields.find( field ) != m_headerFields.end();
}
void addTrailerField( int field, bool required )
{
m_trailerFields[ field ] = required;
}
bool isTrailerField( int field ) const
{
return m_trailerFields.find( field ) != m_trailerFields.end();
}
void addFieldType( int field, FIX::TYPE::Type type )
{
m_fieldTypes[ field ] = type;
if( type == FIX::TYPE::Data )
m_dataFields.insert( field );
}
bool getFieldType( int field, FIX::TYPE::Type& type ) const
{
FieldTypes::const_iterator i = m_fieldTypes.find( field );
if ( i == m_fieldTypes.end() ) return false;
type = i->second;
return true;
}
void addRequiredField( const std::string& msgType, int field )
{
m_requiredFields[ msgType ].insert( field );
}
bool isRequiredField( const std::string& msgType, int field ) const
{
MsgTypeToField::const_iterator i = m_requiredFields.find( msgType );
if ( i == m_requiredFields.end() ) return false;
return i->second.find( field ) != i->second.end();
}
void addFieldValue( int field, const std::string& value )
{
m_fieldValues[ field ].insert( value );
}
bool hasFieldValue( int field ) const
{
FieldToValue::const_iterator i = m_fieldValues.find( field );
return i != m_fieldValues.end();
}
bool isFieldValue( int field, const std::string& value ) const
{
FieldToValue::const_iterator i = m_fieldValues.find( field );
if ( i == m_fieldValues.end() )
return false;
if( !isMultipleValueField( field ) )
return i->second.find( value ) != i->second.end();
// MultipleValue
std::string::size_type startPos = 0;
std::string::size_type endPos = 0;
do
{
endPos = value.find_first_of(' ', startPos);
std::string singleValue =
value.substr( startPos, endPos - startPos );
if( i->second.find( singleValue ) == i->second.end() )
return false;
startPos = endPos + 1;
} while( endPos != std::string::npos );
return true;
}
void addGroup( const std::string& msg, int field, int delim,
const DataDictionary& dataDictionary )
{
DataDictionary * pDD = new DataDictionary( dataDictionary );
pDD->setVersion( getVersion() );
FieldPresenceMap& presenceMap = m_groups[ field ];
presenceMap[ msg ] = std::make_pair( delim, pDD );
}
bool isGroup( const std::string& msg, int field ) const
{
FieldToGroup::const_iterator i = m_groups.find( field );
if ( i == m_groups.end() ) return false;
const FieldPresenceMap& presenceMap = i->second;
FieldPresenceMap::const_iterator iter = presenceMap.find( msg );
return ( iter != presenceMap.end() );
}
bool getGroup( const std::string& msg, int field, int& delim,
const DataDictionary*& pDataDictionary ) const
{
FieldToGroup::const_iterator i = m_groups.find( field );
if ( i == m_groups.end() ) return false;
const FieldPresenceMap& presenceMap = i->second;
FieldPresenceMap::const_iterator iter = presenceMap.find( msg );
if( iter == presenceMap.end() ) return false;
std::pair < int, DataDictionary* > pair = iter->second;
delim = pair.first;
pDataDictionary = pair.second;
return true;
}
bool isDataField( int field ) const
{
MsgFields::const_iterator iter = m_dataFields.find( field );
return iter != m_dataFields.end();
}
bool isMultipleValueField( int field ) const
{
FieldTypes::const_iterator i = m_fieldTypes.find( field );
return i != m_fieldTypes.end()
&& (i->second == TYPE::MultipleValueString
|| i->second == TYPE::MultipleCharValue
|| i->second == TYPE::MultipleStringValue );
}
void checkFieldsOutOfOrder( bool value )
{ m_checkFieldsOutOfOrder = value; }
void checkFieldsHaveValues( bool value )
{ m_checkFieldsHaveValues = value; }
void checkUserDefinedFields( bool value )
{ m_checkUserDefinedFields = value; }
/// Validate a message.
static void validate( const Message& message,
const DataDictionary* const pSessionDD,
const DataDictionary* const pAppID ) throw( FIX::Exception );
void validate( const Message& message ) const throw ( FIX::Exception )
{ validate( message, false ); }
void validate( const Message& message, bool bodyOnly ) const throw( FIX::Exception )
{ validate( message, bodyOnly ? (DataDictionary*)0 : this, this ); }
DataDictionary& operator=( const DataDictionary& rhs );
private:
/// Iterate through fields while applying checks.
void iterate( const FieldMap& map, const MsgType& msgType ) const;
/// Check if message type is defined in spec.
void checkMsgType( const MsgType& msgType ) const
{
if ( !isMsgType( msgType.getValue() ) )
throw InvalidMessageType();
}
/// If we need to check for the tag in the dictionary
bool shouldCheckTag( const FieldBase& field ) const
{
if( !m_checkUserDefinedFields && field.getField() >= FIELD::UserMin )
return false;
else
return true;
}
/// Check if field tag number is defined in spec.
void checkValidTagNumber( const FieldBase& field ) const
throw( InvalidTagNumber )
{
if( m_fields.find( field.getField() ) == m_fields.end() )
throw InvalidTagNumber( field.getField() );
}
void checkValidFormat( const FieldBase& field ) const
throw( IncorrectDataFormat )
{
try
{
TYPE::Type type = TYPE::Unknown;
getFieldType( field.getField(), type );
switch ( type )
{
case TYPE::String:
STRING_CONVERTOR::convert( field.getString() ); break;
case TYPE::Char:
CHAR_CONVERTOR::convert( field.getString() ); break;
case TYPE::Price:
PRICE_CONVERTOR::convert( field.getString() ); break;
case TYPE::Int:
INT_CONVERTOR::convert( field.getString() ); break;
case TYPE::Amt:
AMT_CONVERTOR::convert( field.getString() ); break;
case TYPE::Qty:
QTY_CONVERTOR::convert( field.getString() ); break;
case TYPE::Currency:
CURRENCY_CONVERTOR::convert( field.getString() ); break;
case TYPE::MultipleValueString:
MULTIPLEVALUESTRING_CONVERTOR::convert( field.getString() ); break;
case TYPE::MultipleStringValue:
MULTIPLESTRINGVALUE_CONVERTOR::convert( field.getString() ); break;
case TYPE::MultipleCharValue:
MULTIPLECHARVALUE_CONVERTOR::convert( field.getString() ); break;
case TYPE::Exchange:
EXCHANGE_CONVERTOR::convert( field.getString() ); break;
case TYPE::UtcTimeStamp:
UTCTIMESTAMP_CONVERTOR::convert( field.getString() ); break;
case TYPE::Boolean:
BOOLEAN_CONVERTOR::convert( field.getString() ); break;
case TYPE::LocalMktDate:
LOCALMKTDATE_CONVERTOR::convert( field.getString() ); break;
case TYPE::Data:
DATA_CONVERTOR::convert( field.getString() ); break;
case TYPE::Float:
FLOAT_CONVERTOR::convert( field.getString() ); break;
case TYPE::PriceOffset:
PRICEOFFSET_CONVERTOR::convert( field.getString() ); break;
case TYPE::MonthYear:
MONTHYEAR_CONVERTOR::convert( field.getString() ); break;
case TYPE::DayOfMonth:
DAYOFMONTH_CONVERTOR::convert( field.getString() ); break;
case TYPE::UtcDate:
UTCDATE_CONVERTOR::convert( field.getString() ); break;
case TYPE::UtcTimeOnly:
UTCTIMEONLY_CONVERTOR::convert( field.getString() ); break;
case TYPE::NumInGroup:
NUMINGROUP_CONVERTOR::convert( field.getString() ); break;
case TYPE::Percentage:
PERCENTAGE_CONVERTOR::convert( field.getString() ); break;
case TYPE::SeqNum:
SEQNUM_CONVERTOR::convert( field.getString() ); break;
case TYPE::Length:
LENGTH_CONVERTOR::convert( field.getString() ); break;
case TYPE::Country:
COUNTRY_CONVERTOR::convert( field.getString() ); break;
case TYPE::TzTimeOnly:
TZTIMEONLY_CONVERTOR::convert( field.getString() ); break;
case TYPE::TzTimeStamp:
TZTIMESTAMP_CONVERTOR::convert( field.getString() ); break;
case TYPE::XmlData:
XMLDATA_CONVERTOR::convert( field.getString() ); break;
case TYPE::Language:
LANGUAGE_CONVERTOR::convert( field.getString() ); break;
case TYPE::Unknown: break;
}
}
catch ( FieldConvertError& )
{ throw IncorrectDataFormat( field.getField(), field.getString() ); }
}
void checkValue( const FieldBase& field ) const
throw( IncorrectTagValue )
{
if ( !hasFieldValue( field.getField() ) ) return ;
const std::string& value = field.getString();
if ( !isFieldValue( field.getField(), value ) )
throw IncorrectTagValue( field.getField() );
}
/// Check if a field has a value.
void checkHasValue( const FieldBase& field ) const
throw( NoTagValue )
{
if ( m_checkFieldsHaveValues && !field.getString().length() )
throw NoTagValue( field.getField() );
}
/// Check if a field is in this message type.
void checkIsInMessage
( const FieldBase& field, const MsgType& msgType ) const
throw( TagNotDefinedForMessage )
{
if ( !isMsgField( msgType, field.getField() ) )
throw TagNotDefinedForMessage( field.getField() );
}
/// Check if group count matches number of groups in
void checkGroupCount
( const FieldBase& field, const FieldMap& fieldMap, const MsgType& msgType ) const
throw( RepeatingGroupCountMismatch )
{
int fieldNum = field.getField();
if( isGroup(msgType, fieldNum) )
{
if( (int)fieldMap.groupCount(fieldNum)
!= IntConvertor::convert(field.getString()) )
throw RepeatingGroupCountMismatch(fieldNum);
}
}
/// Check if a message has all required fields.
void checkHasRequired
( const FieldMap& header, const FieldMap& body, const FieldMap& trailer,
const MsgType& msgType ) const
throw( RequiredTagMissing )
{
NonBodyFields::const_iterator iNBF;
for( iNBF = m_headerFields.begin(); iNBF != m_headerFields.end(); ++iNBF )
{
if( iNBF->second == true && !header.isSetField(iNBF->first) )
throw RequiredTagMissing( iNBF->first );
}
for( iNBF = m_trailerFields.begin(); iNBF != m_trailerFields.end(); ++iNBF )
{
if( iNBF->second == true && !trailer.isSetField(iNBF->first) )
throw RequiredTagMissing( iNBF->first );
}
MsgTypeToField::const_iterator iM
= m_requiredFields.find( msgType.getString() );
if ( iM == m_requiredFields.end() ) return ;
const MsgFields& fields = iM->second;
MsgFields::const_iterator iF;
for( iF = fields.begin(); iF != fields.end(); ++iF )
{
if( !body.isSetField(*iF) )
throw RequiredTagMissing( *iF );
}
FieldMap::g_iterator groups;
for( groups = body.g_begin(); groups != body.g_end(); ++groups )
{
int delim;
const DataDictionary* DD = 0;
int field = groups->first;
if( getGroup( msgType.getValue(), field, delim, DD ) )
{
std::vector<FieldMap*>::const_iterator group;
for( group = groups->second.begin(); group != groups->second.end(); ++group )
DD->checkHasRequired( **group, **group, **group, msgType );
}
}
}
int lookupXMLFieldNumber( DOMDocument*, DOMNode* ) const;
int lookupXMLFieldNumber( DOMDocument*, const std::string& name ) const;
int addXMLComponentFields( DOMDocument*, DOMNode*, const std::string& msgtype, DataDictionary&, bool );
void addXMLGroup( DOMDocument*, DOMNode*, const std::string& msgtype, DataDictionary&, bool );
TYPE::Type XMLTypeToType( const std::string& xmlType ) const;
bool m_hasVersion;
bool m_checkFieldsOutOfOrder;
bool m_checkFieldsHaveValues;
bool m_checkUserDefinedFields;
BeginString m_beginString;
MsgTypeToField m_messageFields;
MsgTypeToField m_requiredFields;
MsgTypes m_messages;
Fields m_fields;
OrderedFields m_orderedFields;
mutable OrderedFieldsArray m_orderedFieldsArray;
NonBodyFields m_headerFields;
NonBodyFields m_trailerFields;
FieldTypes m_fieldTypes;
FieldToValue m_fieldValues;
FieldToName m_fieldNames;
NameToField m_names;
ValueToName m_valueNames;
FieldToGroup m_groups;
MsgFields m_dataFields;
};
}
#endif //FIX_DATADICTIONARY_H
@@ -0,0 +1,70 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_DATADICTIONARYPROVIDER_H
#define FIX_DATADICTIONARYPROVIDER_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "DataDictionary.h"
#include "Exceptions.h"
#include "Utility.h"
namespace FIX
{
class BeginString;
class ApplVerID;
/**
* Queries for DataDictionary based on appropriate version of %FIX.
*/
class DataDictionaryProvider
{
public:
DataDictionaryProvider() {}
DataDictionaryProvider( const DataDictionaryProvider& copy );
const DataDictionary& getSessionDataDictionary(const BeginString& beginString) const
throw( DataDictionaryNotFound );
const DataDictionary& getApplicationDataDictionary(const ApplVerID& applVerID) const
throw( DataDictionaryNotFound );
void addTransportDataDictionary(const BeginString& beginString, ptr::shared_ptr<DataDictionary>);
void addApplicationDataDictionary(const ApplVerID& applVerID, ptr::shared_ptr<DataDictionary>);
void addTransportDataDictionary(const BeginString& beginString, const std::string& path)
{ addTransportDataDictionary(beginString, ptr::shared_ptr<DataDictionary>( new DataDictionary(path) )); }
void addApplicationDataDictionary(const ApplVerID& applVerID, const std::string& path)
{ addApplicationDataDictionary(applVerID, ptr::shared_ptr<DataDictionary>( new DataDictionary(path) )); }
private:
std::map<std::string, ptr::shared_ptr<DataDictionary> > m_transportDictionaries;
std::map<std::string, ptr::shared_ptr<DataDictionary> > m_applicationDictionaries;
DataDictionary emptyDataDictionary;
};
}
#endif //FIX_DATADICTIONARYPROVIDER_H
@@ -0,0 +1,105 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_DATABASECONNECTIONID_H
#define FIX_DATABASECONNECTIONID_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include <string>
#include <map>
namespace FIX
{
class DatabaseConnectionID
{
public:
DatabaseConnectionID
( const std::string& database, const std::string& user,
const std::string& password, const std::string& host, short port )
: m_database( database ), m_user( user ), m_password( password ),
m_host( host ), m_port( port ) {}
friend bool operator<( const DatabaseConnectionID&, const DatabaseConnectionID& );
friend bool operator==( const DatabaseConnectionID&, const DatabaseConnectionID& );
friend bool operator!=( const DatabaseConnectionID&, const DatabaseConnectionID& );
const std::string& getDatabase() const
{ return m_database; }
const std::string& getUser() const
{ return m_user; }
const std::string& getPassword() const
{ return m_password; }
const std::string& getHost() const
{ return m_host; }
short getPort() const
{ return m_port; }
private:
std::string m_database;
std::string m_user;
std::string m_password;
std::string m_host;
short m_port;
};
inline bool operator<( const DatabaseConnectionID& lhs, const DatabaseConnectionID& rhs )
{
if ( lhs.m_database < rhs.m_database )
return true;
else if ( rhs.m_database < lhs.m_database )
return false;
else if ( lhs.m_user < rhs.m_user )
return true;
else if ( rhs.m_user < lhs.m_user )
return false;
else if ( lhs.m_password < rhs.m_password )
return true;
else if ( rhs.m_password < lhs.m_password )
return false;
else if ( lhs.m_host < rhs.m_host )
return true;
else if ( rhs.m_host < lhs.m_host )
return false;
else if ( lhs.m_port < rhs.m_port )
return true;
else if ( rhs.m_port < lhs.m_port )
return false;
else
return false;
}
inline bool operator==( const DatabaseConnectionID& lhs, const DatabaseConnectionID& rhs )
{
return ( ( lhs.m_database == rhs.m_database ) &&
( lhs.m_user == rhs.m_user ) &&
( lhs.m_password == rhs.m_password ) &&
( lhs.m_host == rhs.m_host ) &&
( lhs.m_port == rhs.m_port ));
}
inline bool operator!=( const DatabaseConnectionID& lhs, const DatabaseConnectionID& rhs )
{
return !( lhs == rhs );
}
}
#endif
@@ -0,0 +1,91 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_DATABASECONNECTIONPOOL_H
#define FIX_DATABASECONNECTIONPOOL_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "DatabaseConnectionID.h"
#include <string>
#include <map>
namespace FIX
{
template< typename T > class DatabaseConnectionPool
{
public:
DatabaseConnectionPool( bool poolConnections )
: m_poolConnections( poolConnections ) {}
T* create( const DatabaseConnectionID& id )
{
if( !m_poolConnections )
return new T( id );
if( m_connections.find( id ) == m_connections.end() )
{
m_connections[id] = Connection
( new T(id), 0 );
}
m_connections[id].second++;
return m_connections[id].first;
}
bool destroy( T* pConnection )
{
if( !m_poolConnections )
{
delete pConnection;
return true;
}
const DatabaseConnectionID& id = pConnection->connectionID();
if( m_connections.find( id ) == m_connections.end() )
return false;
Connection& connection = m_connections[id];
if( connection.first != pConnection )
return false;
connection.second--;
if( connection.second == 0 )
{
m_connections.erase( id );
delete pConnection;
}
return true;
}
private:
typedef std::pair<T*, int>
Connection;
typedef std::map<DatabaseConnectionID, Connection>
Connections;
Connections m_connections;
bool m_poolConnections;
};
}
#endif
+94
View File
@@ -0,0 +1,94 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_DICTIONARY_H
#define FIX_DICTIONARY_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include <map>
#include <string>
#include "Exceptions.h"
namespace FIX
{
/// For storage and retrieval of key/value pairs.
class Dictionary
{
public:
Dictionary( const std::string& name ) : m_name( name ) {}
Dictionary() {}
virtual ~Dictionary() {}
typedef std::map < std::string, std::string > Data;
typedef Data::const_iterator iterator;
typedef iterator const_iterator;
/// Get the name of the dictionary.
std::string getName() const { return m_name; }
/// Return the number of key/value pairs.
size_t size() const { return m_data.size(); }
/// Get a value as a string.
std::string getString( const std::string&, bool capitalize = false ) const
throw( ConfigError, FieldConvertError );
/// Get a value as a int.
int getInt( const std::string& ) const
throw( ConfigError, FieldConvertError );
/// Get a value as a double.
double getDouble( const std::string& ) const
throw( ConfigError, FieldConvertError );
/// Get a value as a bool
bool getBool( const std::string& ) const
throw( ConfigError, FieldConvertError );
/// Get a value as a day of week
int getDay( const std::string& ) const
throw( ConfigError, FieldConvertError );
/// Set a value from a string.
void setString( const std::string&, const std::string& );
/// Set a value from a int.
void setInt( const std::string&, int );
/// Set a value from a double.
void setDouble( const std::string&, double );
/// Set a value from a bool
void setBool( const std::string&, bool );
/// Set a value from a day
void setDay( const std::string&, int );
/// Check if the dictionary contains a value for key.
bool has( const std::string& ) const;
/// Merge two dictionaries.
void merge( const Dictionary& );
iterator begin() const { return m_data.begin(); }
iterator end() const { return m_data.end(); }
private:
Data m_data;
std::string m_name;
};
/*! @} */
}
#endif //FIX_DICTIONARY_H
+95
View File
@@ -0,0 +1,95 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_EVENT_H
#define FIX_EVENT_H
#include "Utility.h"
#include <math.h>
#ifndef _MSC_VER
#include <pthread.h>
#include <cmath>
#endif
namespace FIX
{
/// Portable implementation of an event/conditional mutex
class Event
{
public:
Event()
{
#ifdef _MSC_VER
m_event = CreateEvent( 0, false, false, 0 );
#else
pthread_mutex_init( &m_mutex, 0 );
pthread_cond_init( &m_event, 0 );
#endif
}
~Event()
{
#ifdef _MSC_VER
CloseHandle( m_event );
#else
pthread_cond_destroy( &m_event );
pthread_mutex_destroy( &m_mutex );
#endif
}
void signal()
{
#ifdef _MSC_VER
SetEvent( m_event );
#else
pthread_mutex_lock( &m_mutex );
pthread_cond_broadcast( &m_event );
pthread_mutex_unlock( &m_mutex );
#endif
}
void wait( double s )
{
#ifdef _MSC_VER
WaitForSingleObject( m_event, (long)(s * 1000) );
#else
pthread_mutex_lock( &m_mutex );
timespec time, remainder;
double intpart;
time.tv_nsec = (long)(modf(s, &intpart) * 1e9);
time.tv_sec = (int)intpart;
pthread_cond_timedwait( &m_event, &m_mutex, &time );
pthread_mutex_unlock( &m_mutex );
#endif
}
private:
#ifdef _MSC_VER
HANDLE m_event;
#else
pthread_cond_t m_event;
pthread_mutex_t m_mutex;
#endif
};
}
#endif
+299
View File
@@ -0,0 +1,299 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_EXCEPTIONS_H
#define FIX_EXCEPTIONS_H
#include <string>
#include <stdexcept>
#include "Utility.h"
namespace FIX
{
/// Base QuickFIX exception type.
struct Exception : public std::logic_error
{
Exception( const std::string& t, const std::string& d )
: std::logic_error( d.size() ? t + ": " + d : t ),
type( t ), detail( d )
{}
~Exception() throw() {}
std::string type;
std::string detail;
};
/// DataDictionary not found for BeginString or ApplVerID
struct DataDictionaryNotFound : public Exception
{
DataDictionaryNotFound( const std::string& v, const std::string& what = "" )
: Exception( "Could not find data dictionary", what ),
version( v ) {}
~DataDictionaryNotFound() throw() {}
std::string version;
};
/// Field not found inside a message
struct FieldNotFound : public Exception
{
FieldNotFound( int f = 0, const std::string& what = "" )
: Exception( "Field not found", what ),
field( f ) {}
int field;
};
/// Unable to convert field into its native format
struct FieldConvertError : public Exception
{
FieldConvertError( const std::string& what = "" )
: Exception( "Could not convert field", what ) {}
};
/// Unable to parse message
struct MessageParseError : public Exception
{
MessageParseError( const std::string& what = "" )
: Exception( "Could not parse message", what ) {}
};
/// Not a recognizable message
struct InvalidMessage : public Exception
{
InvalidMessage( const std::string& what = "" )
: Exception( "Invalid message", what ) {}
};
/// %Application is not configured correctly
struct ConfigError : public Exception
{
ConfigError( const std::string& what = "" )
: Exception( "Configuration failed", what ) {}
};
/// %Application encountered serious error during runtime
struct RuntimeError : public Exception
{
RuntimeError( const std::string& what = "" )
: Exception( "Runtime error", what ) {}
};
/// Tag number does not exist in specification
struct InvalidTagNumber : public Exception
{
InvalidTagNumber( int f = 0, const std::string& what = "" )
: Exception( "Invalid tag number", what ),
field( f ) {}
int field;
};
/// Required field is not in message
struct RequiredTagMissing : public Exception
{
RequiredTagMissing( int f = 0, const std::string& what = "" )
: Exception( "Required tag missing", what ),
field( f ) {}
int field;
};
/// Field does not belong to message
struct TagNotDefinedForMessage : public Exception
{
TagNotDefinedForMessage( int f = 0, const std::string& what = "" )
: Exception( "Tag not defined for this message type", what ),
field( f ) {}
int field;
};
/// Field exists in message without a value
struct NoTagValue : public Exception
{
NoTagValue( int f = 0, const std::string& what = "" )
: Exception( "Tag specified without a value", what ),
field( f ) {}
int field;
};
/// Field has a value that is out of range
struct IncorrectTagValue : public Exception
{
IncorrectTagValue( int f = 0, const std::string& what = "" )
: Exception( "Value is incorrect (out of range) for this tag", what ),
field( f ) {}
int field;
};
/// Field has a badly formatted value
struct IncorrectDataFormat : public Exception
{
IncorrectDataFormat( int f = 0, const std::string& what = "" )
: Exception( "Incorrect data format for value", what ),
field( f ) {}
int field;
};
/// Message is not structured correctly
struct IncorrectMessageStructure : public Exception
{
IncorrectMessageStructure( const std::string& what = "" )
: Exception( "Incorrect message structure", what ) {}
};
/// Field shows up twice in the message
struct DuplicateFieldNumber : public Exception
{
DuplicateFieldNumber( const std::string& what = "" )
: Exception( "Duplicate field number", what ) {}
};
/// Not a known message type
struct InvalidMessageType : public Exception
{
InvalidMessageType( const std::string& what = "" )
: Exception( "Invalid Message Type", what ) {}
};
/// Message type not supported by application
struct UnsupportedMessageType : public Exception
{
UnsupportedMessageType( const std::string& what = "" )
: Exception( "Unsupported Message Type", what ) {}
};
/// Version of %FIX is not supported
struct UnsupportedVersion : public Exception
{
UnsupportedVersion( const std::string& what = "" )
: Exception( "Unsupported Version", what ) {}
};
/// Tag is not in the correct order
struct TagOutOfOrder : public Exception
{
TagOutOfOrder( int f = 0, const std::string& what = "" )
: Exception( "Tag specified out of required order", what ),
field( f ) {}
int field;
};
/// Repeated tag not part of repeating group
struct RepeatedTag : public Exception
{
RepeatedTag( int f = 0, const std::string& what = "" )
: Exception( "Repeated tag not part of repeating group", what ),
field( f ) {}
int field;
};
/// Repeated group count not equal to actual count
struct RepeatingGroupCountMismatch : public Exception
{
RepeatingGroupCountMismatch( int f = 0, const std::string& what = "" )
: Exception( "Repeating group count mismatch", what ),
field( f ) {}
int field;
};
/// Indicates user does not want to send a message
struct DoNotSend : public Exception
{
DoNotSend( const std::string& what = "" )
: Exception( "Do Not Send Message", what ) {}
};
/// User wants to reject permission to logon
struct RejectLogon : public Exception
{
RejectLogon( const std::string& what = "" )
: Exception( "Rejected Logon Attempt", what ) {}
};
/// Session cannot be found for specified action
struct SessionNotFound : public Exception
{
SessionNotFound( const std::string& what = "" )
: Exception( "Session Not Found", what ) {}
};
/// IO Error
struct IOException : public Exception
{
IOException( const std::string& what = "" )
: Exception( "IO Error", what ) {}
};
/// Socket Error
struct SocketException : public Exception
{
SocketException()
: Exception( "Socket Error", errorToWhat() ) {}
SocketException( const std::string& what )
: Exception( "Socket Error", what ) {}
std::string errorToWhat()
{
#ifdef _MSC_VER
error = WSAGetLastError();
char buffer[2048];
FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM, NULL, error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
buffer, 2048, NULL );
return buffer;
#else
error = errno;
return strerror( error );
#endif
}
int error;
};
/// Socket send operation failed
struct SocketSendFailed : public SocketException
{
SocketSendFailed() {}
SocketSendFailed( const std::string& what )
: SocketException( what ) {}
};
/// Socket recv operation failed
struct SocketRecvFailed : public SocketException
{
SocketRecvFailed( ssize_t size )
: SocketException( size == 0 ? "Connection reset by peer." : size < 0 ? errorToWhat() : "Success." ) {}
SocketRecvFailed( const std::string& what )
: SocketException( what ) {}
};
/// Socket close operation failed
struct SocketCloseFailed : public SocketException
{
SocketCloseFailed() {}
SocketCloseFailed( const std::string& what )
: SocketException( what ) {}
};
/*! @} */
}
#endif //FIX_EXCEPTIONS_H
+672
View File
@@ -0,0 +1,672 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_FIELD
#define FIX_FIELD
#ifdef _MSC_VER
#pragma warning( disable : 4786 )
#endif
#include <sstream>
#include <numeric>
#include "FieldNumbers.h"
#include "FieldConvertors.h"
#include "FieldTypes.h"
#include "Utility.h"
namespace FIX
{
/**
* Base representation of all Field classes.
*
* This base class is the lowest common denominator of all fields. It
* keeps all fields in its most generic string representation with its
* integer tag.
*/
class FieldBase
{
/// Class used to store field metrics like total length and checksum
class field_metrics
{
public:
field_metrics( const size_t length, const int checksum )
: m_length( length )
, m_checksum( checksum )
{}
size_t getLength() const
{ return m_length; }
int getCheckSum() const
{ return m_checksum; }
bool isValid() const
{ return m_length > 0; }
private:
size_t m_length;
int m_checksum;
};
friend class Message;
/// Constructor which also calculates field metrics
FieldBase( int field,
std::string::const_iterator valueStart,
std::string::const_iterator valueEnd,
std::string::const_iterator tagStart,
std::string::const_iterator tagEnd )
: m_field( field )
, m_string( valueStart, valueEnd )
, m_metrics( calculateMetrics( tagStart, tagEnd ) )
{}
public:
FieldBase( int field, const std::string& string )
: m_field( field ), m_string(string), m_metrics( no_metrics() )
{}
virtual ~FieldBase() {}
void setField( int field )
{
m_field = field;
m_metrics = no_metrics();
m_data.clear();
}
void setString( const std::string& string )
{
m_string = string;
m_metrics = no_metrics();
m_data.clear();
}
/// Get the fields integer tag.
int getField() const
{ return m_field; }
/// Get the string representation of the fields value.
const std::string& getString() const
{ return m_string; }
/// Get the string representation of the Field (i.e.) 55=MSFT[SOH]
const std::string& getFixString() const
{
if( m_data.empty() )
encodeTo( m_data );
return m_data;
}
/// Get the length of the fields string representation
size_t getLength() const
{
calculate();
return m_metrics.getLength();
}
/// Get the total value the fields characters added together
int getTotal() const
{
calculate();
return m_metrics.getCheckSum();
}
/// Compares fields based on their tag numbers
bool operator < ( const FieldBase& field ) const
{ return m_field < field.m_field; }
private:
void calculate() const
{
if( m_metrics.isValid() ) return;
m_metrics = calculateMetrics( getFixString() );
}
/// Serializes string representation of the Field to input string
void encodeTo( std::string& result ) const
{
size_t tagLength = FIX::number_of_symbols_in( m_field ) + 1;
size_t totalLength = tagLength + m_string.length() + 1;
result.resize( totalLength );
char * buf = (char*)result.c_str();
FIX::integer_to_string( buf, tagLength, m_field );
buf[tagLength - 1] = '=';
memcpy( buf + tagLength, m_string.data(), m_string.length() );
buf[totalLength - 1] = '\001';
}
static field_metrics no_metrics()
{
return field_metrics( 0, 0 );
}
/// Calculate metrics for any input string
static field_metrics calculateMetrics(
std::string::const_iterator const start,
std::string::const_iterator const end )
{
int checksum = 0;
for ( std::string::const_iterator str = start; str != end; ++str )
checksum += (unsigned char)( *str );
return field_metrics( std::distance( start, end ), checksum );
}
static field_metrics calculateMetrics( const std::string& field )
{
return calculateMetrics( field.begin(), field.end() );
}
int m_field;
std::string m_string;
mutable std::string m_data;
mutable field_metrics m_metrics;
};
/*! @} */
inline std::ostream& operator <<
( std::ostream& stream, const FieldBase& field )
{
stream << field.getString();
return stream;
}
/**
* MSC doesn't support partial template specialization so we have this.
* this is here to provide equality checking against native char arrays.
*/
class StringField : public FieldBase
{
public:
explicit StringField( int field, const std::string& data )
: FieldBase( field, data ) {}
StringField( int field )
: FieldBase( field, "" ) {}
void setValue( const std::string& value )
{ setString( value ); }
const std::string& getValue() const
{ return getString(); }
operator const std::string&() const
{ return getString(); }
bool operator<( const StringField& rhs ) const
{ return getString() < rhs.getString(); }
bool operator>( const StringField& rhs ) const
{ return getString() > rhs.getString(); }
bool operator==( const StringField& rhs ) const
{ return getString() == rhs.getString(); }
bool operator!=( const StringField& rhs ) const
{ return getString() != rhs.getString(); }
bool operator<=( const StringField& rhs ) const
{ return getString() <= rhs.getString(); }
bool operator>=( const StringField& rhs ) const
{ return getString() >= rhs.getString(); }
friend bool operator<( const StringField&, const char* );
friend bool operator<( const char*, const StringField& );
friend bool operator>( const StringField&, const char* );
friend bool operator>( const char*, const StringField& );
friend bool operator==( const StringField&, const char* );
friend bool operator==( const char*, const StringField& );
friend bool operator!=( const StringField&, const char* );
friend bool operator!=( const char*, const StringField& );
friend bool operator<=( const StringField&, const char* );
friend bool operator<=( const char*, const StringField& );
friend bool operator>=( const StringField&, const char* );
friend bool operator>=( const char*, const StringField& );
friend bool operator<( const StringField&, const std::string& );
friend bool operator<( const std::string&, const StringField& );
friend bool operator>( const StringField&, const std::string& );
friend bool operator>( const std::string&, const StringField& );
friend bool operator==( const StringField&, const std::string& );
friend bool operator==( const std::string&, const StringField& );
friend bool operator!=( const StringField&, const std::string& );
friend bool operator!=( const std::string&, const StringField& );
friend bool operator<=( const StringField&, const std::string& );
friend bool operator<=( const std::string&, const StringField& );
friend bool operator>=( const StringField&, const std::string& );
friend bool operator>=( const std::string&, const StringField& );
};
inline bool operator<( const StringField& lhs, const char* rhs )
{ return lhs.getValue() < rhs; }
inline bool operator<( const char* lhs, const StringField& rhs )
{ return lhs < rhs.getValue(); }
inline bool operator>( const StringField& lhs, const char* rhs )
{ return lhs.getValue() > rhs; }
inline bool operator>( const char* lhs, const StringField& rhs )
{ return lhs > rhs.getValue(); }
inline bool operator==( const StringField& lhs, const char* rhs )
{ return lhs.getValue() == rhs; }
inline bool operator==( const char* lhs, const StringField& rhs )
{ return lhs == rhs.getValue(); }
inline bool operator!=( const StringField& lhs, const char* rhs )
{ return lhs.getValue() != rhs; }
inline bool operator!=( const char* lhs, const StringField& rhs )
{ return lhs != rhs.getValue(); }
inline bool operator<=( const StringField& lhs, const char* rhs )
{ return lhs.getValue() <= rhs; }
inline bool operator<=( const char* lhs, const StringField& rhs )
{ return lhs <= rhs.getValue(); }
inline bool operator>=( const StringField& lhs, const char* rhs )
{ return lhs.getValue() >= rhs; }
inline bool operator>=( const char* lhs, const StringField& rhs )
{ return lhs >= rhs.getValue(); }
inline bool operator<( const StringField& lhs, const std::string& rhs )
{ return lhs.getValue() < rhs; }
inline bool operator<( const std::string& lhs, const StringField& rhs )
{ return lhs < rhs.getValue(); }
inline bool operator>( const StringField& lhs, const std::string& rhs )
{ return lhs.getValue() > rhs; }
inline bool operator>( const std::string& lhs, const StringField& rhs )
{ return lhs > rhs.getValue(); }
inline bool operator==( const StringField& lhs, const std::string& rhs )
{ return lhs.getValue() == rhs; }
inline bool operator==( const std::string& lhs, const StringField& rhs )
{ return lhs == rhs.getValue(); }
inline bool operator!=( const StringField& lhs, const std::string& rhs )
{ return lhs.getValue() != rhs; }
inline bool operator!=( const std::string& lhs, const StringField& rhs )
{ return lhs != rhs.getValue(); }
inline bool operator<=( const StringField& lhs, const std::string& rhs )
{ return lhs.getValue() <= rhs; }
inline bool operator<=( const std::string& lhs, const StringField& rhs )
{ return lhs <= rhs.getValue(); }
inline bool operator>=( const StringField& lhs, const std::string& rhs )
{ return lhs.getValue() >= rhs; }
inline bool operator>=( const std::string& lhs, const StringField& rhs )
{ return lhs >= rhs.getValue(); }
/// Field that contains a character value
class CharField : public FieldBase
{
public:
explicit CharField( int field, char data )
: FieldBase( field, CharConvertor::convert( data ) ) {}
CharField( int field )
: FieldBase( field, "" ) {}
void setValue( char value )
{ setString( CharConvertor::convert( value ) ); }
char getValue() const throw ( IncorrectDataFormat )
{ try
{ return CharConvertor::convert( getString() ); }
catch( FieldConvertError& )
{ throw IncorrectDataFormat( getField(), getString() ); } }
operator char() const
{ return getValue(); }
};
/// Field that contains a double value
class DoubleField : public FieldBase
{
public:
explicit DoubleField( int field, double data, int padding = 0 )
: FieldBase( field, DoubleConvertor::convert( data, padding ) ) {}
DoubleField( int field )
: FieldBase( field, "" ) {}
void setValue( double value, int padding = 0 )
{ setString( DoubleConvertor::convert( value, padding ) ); }
double getValue() const throw ( IncorrectDataFormat )
{ try
{ return DoubleConvertor::convert( getString() ); }
catch( FieldConvertError& )
{ throw IncorrectDataFormat( getField(), getString() ); } }
operator double() const
{ return getValue(); }
};
/// Field that contains an integer value
class IntField : public FieldBase
{
public:
explicit IntField( int field, int data )
: FieldBase( field, IntConvertor::convert( data ) ) {}
IntField( int field )
: FieldBase( field, "" ) {}
void setValue( int value )
{ setString( IntConvertor::convert( value ) ); }
int getValue() const throw ( IncorrectDataFormat )
{ try
{ return IntConvertor::convert( getString() ); }
catch( FieldConvertError& )
{ throw IncorrectDataFormat( getField(), getString() ); } }
operator const int() const
{ return getValue(); }
};
/// Field that contains a boolean value
class BoolField : public FieldBase
{
public:
explicit BoolField( int field, bool data )
: FieldBase( field, BoolConvertor::convert( data ) ) {}
BoolField( int field )
: FieldBase( field, "" ) {}
void setValue( bool value )
{ setString( BoolConvertor::convert( value ) ); }
bool getValue() const throw ( IncorrectDataFormat )
{ try
{ return BoolConvertor::convert( getString() ); }
catch( FieldConvertError& )
{ throw IncorrectDataFormat( getField(), getString() ); } }
operator bool() const
{ return getValue(); }
};
/// Field that contains a UTC time stamp value
class UtcTimeStampField : public FieldBase
{
public:
explicit UtcTimeStampField( int field, const UtcTimeStamp& data, bool showMilliseconds = false )
: FieldBase( field, UtcTimeStampConvertor::convert( data, showMilliseconds ) ) {}
UtcTimeStampField( int field, bool showMilliseconds = false )
: FieldBase( field, UtcTimeStampConvertor::convert( UtcTimeStamp(), showMilliseconds ) ) {}
void setValue( const UtcTimeStamp& value )
{ setString( UtcTimeStampConvertor::convert( value ) ); }
UtcTimeStamp getValue() const throw ( IncorrectDataFormat )
{ try
{ return UtcTimeStampConvertor::convert( getString() ); }
catch( FieldConvertError& )
{ throw IncorrectDataFormat( getField(), getString() ); } }
operator UtcTimeStamp() const
{ return getValue(); }
bool operator<( const UtcTimeStampField& rhs ) const
{ return getValue() < rhs.getValue(); }
bool operator==( const UtcTimeStampField& rhs ) const
{ return getValue() == rhs.getValue(); }
bool operator!=( const UtcTimeStampField& rhs ) const
{ return getValue() != rhs.getValue(); }
};
/// Field that contains a UTC date value
class UtcDateField : public FieldBase
{
public:
explicit UtcDateField( int field, const UtcDate& data )
: FieldBase( field, UtcDateConvertor::convert( data ) ) {}
UtcDateField( int field )
: FieldBase( field, UtcDateConvertor::convert( UtcDate() ) ) {}
void setValue( const UtcDate& value )
{ setString( UtcDateConvertor::convert( value ) ); }
UtcDate getValue() const throw ( IncorrectDataFormat )
{ try
{ return UtcDateConvertor::convert( getString() ); }
catch( FieldConvertError& )
{ throw IncorrectDataFormat( getField(), getString() ); } }
operator UtcDate() const
{ return getValue(); }
bool operator<( const UtcDateField& rhs ) const
{ return getValue() < rhs.getValue(); }
bool operator==( const UtcDateField& rhs ) const
{ return getValue() == rhs.getValue(); }
bool operator!=( const UtcDateField& rhs ) const
{ return getValue() != rhs.getValue(); }
};
/// Field that contains a UTC time value
class UtcTimeOnlyField : public FieldBase
{
public:
explicit UtcTimeOnlyField( int field, const UtcTimeOnly& data, bool showMilliseconds = false )
: FieldBase( field, UtcTimeOnlyConvertor::convert( data, showMilliseconds ) ) {}
UtcTimeOnlyField( int field, bool showMilliseconds = false )
: FieldBase( field, UtcTimeOnlyConvertor::convert( UtcTimeOnly(), showMilliseconds ) ) {}
void setValue( const UtcTimeOnly& value )
{ setString( UtcTimeOnlyConvertor::convert( value ) ); }
UtcTimeOnly getValue() const throw ( IncorrectDataFormat )
{ try
{ return UtcTimeOnlyConvertor::convert( getString() ); }
catch( FieldConvertError& )
{ throw IncorrectDataFormat( getField(), getString() ); } }
operator UtcTimeOnly() const
{ return getValue(); }
bool operator<( const UtcTimeOnlyField& rhs ) const
{ return getValue() < rhs.getValue(); }
bool operator==( const UtcTimeOnlyField& rhs ) const
{ return getValue() == rhs.getValue(); }
bool operator!=( const UtcTimeOnlyField& rhs ) const
{ return getValue() != rhs.getValue(); }
};
/// Field that contains a checksum value
class CheckSumField : public FieldBase
{
public:
explicit CheckSumField( int field, int data )
: FieldBase( field, CheckSumConvertor::convert( data ) ) {}
CheckSumField( int field )
: FieldBase( field, "" ) {}
void setValue( int value )
{ setString( CheckSumConvertor::convert( value ) ); }
int getValue() const throw ( IncorrectDataFormat )
{ try
{ return CheckSumConvertor::convert( getString() ); }
catch( FieldConvertError& )
{ throw IncorrectDataFormat( getField(), getString() ); } }
operator const int() const
{ return getValue(); }
};
typedef DoubleField PriceField;
typedef DoubleField AmtField;
typedef DoubleField QtyField;
typedef StringField CurrencyField;
typedef StringField MultipleValueStringField;
typedef StringField MultipleStringValueField;
typedef StringField MultipleCharValueField;
typedef StringField ExchangeField;
typedef StringField LocalMktDateField;
typedef StringField DataField;
typedef DoubleField FloatField;
typedef DoubleField PriceOffsetField;
typedef StringField MonthField;
typedef StringField MonthYearField;
typedef StringField DayOfMonthField;
typedef UtcDateField UtcDateOnlyField;
typedef IntField LengthField;
typedef IntField NumInGroupField;
typedef IntField SeqNumField;
typedef DoubleField PercentageField;
typedef StringField CountryField;
typedef StringField TzTimeOnlyField;
typedef StringField TzTimeStampField;
}
#define DEFINE_FIELD_CLASS_NUM( NAME, TOK, TYPE, NUM ) \
class NAME : public TOK##Field { public: \
NAME() : TOK##Field(NUM) {} \
NAME(const TYPE& value) : TOK##Field(NUM, value) {} \
}
#define DEFINE_FIELD_CLASS( NAME, TOK, TYPE ) \
DEFINE_FIELD_CLASS_NUM(NAME, TOK, TYPE, FIELD::NAME)
#define DEFINE_DEPRECATED_FIELD_CLASS( NAME, TOK, TYPE ) \
DEFINE_FIELD_CLASS_NUM(NAME, TOK, TYPE, DEPRECATED_FIELD::NAME)
#define DEFINE_FIELD_TIMECLASS_NUM( NAME, TOK, TYPE, NUM ) \
class NAME : public TOK##Field { public: \
NAME() : TOK##Field(NUM, false) {} \
NAME(bool showMilliseconds) : TOK##Field(NUM, showMilliseconds) {} \
NAME(const TYPE& value) : TOK##Field(NUM, value) {} \
NAME(const TYPE& value, bool showMilliseconds) : TOK##Field(NUM, value, showMilliseconds) {} \
}
#define DEFINE_FIELD_TIMECLASS( NAME, TOK, TYPE ) \
DEFINE_FIELD_TIMECLASS_NUM(NAME, TOK, TYPE, FIELD::NAME)
#define DEFINE_DEPRECATED_FIELD_TIMECLASS( NAME, TOK, TYPE ) \
DEFINE_FIELD_TIMECLASS_NUM(NAME, TOK, TYPE, DEPRECATED_FIELD::NAME)
#define DEFINE_CHECKSUM( NAME ) \
DEFINE_FIELD_CLASS(NAME, CheckSum, FIX::INT)
#define DEFINE_STRING( NAME ) \
DEFINE_FIELD_CLASS(NAME, String, FIX::STRING)
#define DEFINE_CHAR( NAME ) \
DEFINE_FIELD_CLASS(NAME, Char, FIX::CHAR)
#define DEFINE_PRICE( NAME ) \
DEFINE_FIELD_CLASS(NAME, Price, FIX::PRICE)
#define DEFINE_INT( NAME ) \
DEFINE_FIELD_CLASS(NAME, Int, FIX::INT)
#define DEFINE_AMT( NAME ) \
DEFINE_FIELD_CLASS(NAME, Amt, FIX::AMT)
#define DEFINE_QTY( NAME ) \
DEFINE_FIELD_CLASS(NAME, Qty, FIX::QTY)
#define DEFINE_CURRENCY( NAME ) \
DEFINE_FIELD_CLASS(NAME, Currency, FIX::CURRENCY)
#define DEFINE_MULTIPLEVALUESTRING( NAME ) \
DEFINE_FIELD_CLASS(NAME, MultipleValueString, FIX::MULTIPLEVALUESTRING)
#define DEFINE_MULTIPLESTRINGVALUE( NAME ) \
DEFINE_FIELD_CLASS(NAME, MultipleStringValue, FIX::MULTIPLESTRINGVALUE)
#define DEFINE_MULTIPLECHARVALUE( NAME ) \
DEFINE_FIELD_CLASS(NAME, MultipleCharValue, FIX::MULTIPLECHARVALUE)
#define DEFINE_EXCHANGE( NAME ) \
DEFINE_FIELD_CLASS(NAME, Exchange, FIX::EXCHANGE)
#define DEFINE_UTCTIMESTAMP( NAME ) \
DEFINE_FIELD_TIMECLASS(NAME, UtcTimeStamp, FIX::UTCTIMESTAMP)
#define DEFINE_BOOLEAN( NAME ) \
DEFINE_FIELD_CLASS(NAME, Bool, FIX::BOOLEAN)
#define DEFINE_LOCALMKTDATE( NAME ) \
DEFINE_FIELD_CLASS(NAME, String, FIX::LOCALMKTDATE)
#define DEFINE_DATA( NAME ) \
DEFINE_FIELD_CLASS(NAME, Data, FIX::DATA)
#define DEFINE_FLOAT( NAME ) \
DEFINE_FIELD_CLASS(NAME, Float, FIX::FLOAT)
#define DEFINE_PRICEOFFSET( NAME ) \
DEFINE_FIELD_CLASS(NAME, PriceOffset, FIX::PRICEOFFSET)
#define DEFINE_MONTHYEAR( NAME ) \
DEFINE_FIELD_CLASS(NAME, MonthYear, FIX::MONTHYEAR)
#define DEFINE_DAYOFMONTH( NAME ) \
DEFINE_FIELD_CLASS(NAME, DayOfMonth, FIX::DAYOFMONTH)
#define DEFINE_UTCDATE( NAME ) \
DEFINE_FIELD_CLASS(NAME, UtcDate, FIX::UTCDATE)
#define DEFINE_UTCDATEONLY( NAME ) \
DEFINE_FIELD_CLASS(NAME, UtcDateOnly, FIX::UTCDATEONLY)
#define DEFINE_UTCTIMEONLY( NAME ) \
DEFINE_FIELD_CLASS(NAME, UtcTimeOnly, FIX::UTCTIMEONLY)
#define DEFINE_NUMINGROUP( NAME ) \
DEFINE_FIELD_CLASS(NAME, NumInGroup, FIX::NUMINGROUP)
#define DEFINE_SEQNUM( NAME ) \
DEFINE_FIELD_CLASS(NAME, SeqNum, FIX::SEQNUM)
#define DEFINE_LENGTH( NAME ) \
DEFINE_FIELD_CLASS(NAME, Length, FIX::LENGTH)
#define DEFINE_PERCENTAGE( NAME ) \
DEFINE_FIELD_CLASS(NAME, Percentage, FIX::PERCENTAGE)
#define DEFINE_COUNTRY( NAME ) \
DEFINE_FIELD_CLASS(NAME, Country, FIX::COUNTRY)
#define DEFINE_TZTIMEONLY( NAME ) \
DEFINE_FIELD_CLASS(NAME, String, FIX::TZTIMEONLY)
#define DEFINE_TZTIMESTAMP( NAME ) \
DEFINE_FIELD_CLASS(NAME, String, FIX::TZTIMESTAMP)
#define DEFINE_XMLDATA( NAME ) \
DEFINE_FIELD_CLASS(NAME, String, FIX::XMLDATA)
#define DEFINE_LANGUAGE( NAME ) \
DEFINE_FIELD_CLASS(NAME, String, FIX::LANGUAGE)
#define USER_DEFINE_STRING( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, String, FIX::STRING, NUM)
#define USER_DEFINE_CHAR( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, Char, FIX::CHAR, NUM)
#define USER_DEFINE_PRICE( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, Price, FIX::PRICE, NUM)
#define USER_DEFINE_INT( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, Int, FIX::INT, NUM)
#define USER_DEFINE_AMT( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, Amt, FIX::AMT, NUM)
#define USER_DEFINE_QTY( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, Qty, FIX::QTY, NUM)
#define USER_DEFINE_CURRENCY( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, Currency, FIX::CURRENCY, NUM)
#define USER_DEFINE_MULTIPLEVALUESTRING( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, MultipleValueString, FIX::MULTIPLEVALUESTRING, NUM)
#define USER_DEFINE_MULTIPLESTRINGVALUE( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, MultipleStringValue, FIX::MULTIPLESTRINGVALUE, NUM)
#define USER_DEFINE_MULTIPLECHARVALUE( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, MultipleCharValue, FIX::MULTIPLECHARVALUE, NUM)
#define USER_DEFINE_EXCHANGE( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, Exchange, FIX::EXCHANGE, NUM)
#define USER_DEFINE_UTCTIMESTAMP( NAME, NUM ) \
DEFINE_FIELD_TIMECLASS_NUM(NAME, UtcTimeStamp, FIX::UTCTIMESTAMP, NUM)
#define USER_DEFINE_BOOLEAN( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, Bool, FIX::BOOLEAN, NUM)
#define USER_DEFINE_LOCALMKTDATE( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, String, FIX::STRING, NUM)
#define USER_DEFINE_DATA( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, Data, FIX::DATA, NUM)
#define USER_DEFINE_FLOAT( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, Float, FIX::FLOAT, NUM)
#define USER_DEFINE_PRICEOFFSET( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, PriceOffset, FIX::PRICEOFFSET, NUM)
#define USER_DEFINE_MONTHYEAR( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, MonthYear, FIX::MONTHYEAR, NUM)
#define USER_DEFINE_DAYOFMONTH( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, DayOfMonth, FIX::DAYOFMONTH, NUM)
#define USER_DEFINE_UTCDATE( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, UtcDate, FIX::UTCDATE, NUM)
#define USER_DEFINE_UTCDATEONLY( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, UtcDateOnly, FIX::UTCDATEONLY, NUM)
#define USER_DEFINE_UTCTIMEONLY( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, UtcTimeOnly, FIX::UTCTIMEONLY, NUM)
#define USER_DEFINE_NUMINGROUP( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, NumInGroup, FIX::NUMINGROUP, NUM)
#define USER_DEFINE_SEQNUM( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, SeqNum, FIX::SEQNUM, NUM)
#define USER_DEFINE_LENGTH( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, Length, FIX::LENGTH, NUM)
#define USER_DEFINE_PERCENTAGE( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, Percentage, FIX::PERCENTAGE, NUM)
#define USER_DEFINE_COUNTRY( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, Country, FIX::COUNTRY, NUM)
#define USER_DEFINE_TZTIMEONLY( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, String, FIX::TZTIMEONLY, NUM)
#define USER_DEFINE_TZTIMESTAMP( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, String, FIX::TZTIMESTAMP, NUM)
#define USER_DEFINE_XMLDATA( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, String, FIX::XMLDATA, NUM)
#define USER_DEFINE_LANGUAGE( NAME, NUM ) \
DEFINE_FIELD_CLASS_NUM(NAME, String, FIX::LANGUAGE, NUM)
#endif
+863
View File
@@ -0,0 +1,863 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_FIELDCONVERTORS_H
#define FIX_FIELDCONVERTORS_H
#include "FieldTypes.h"
#include "Exceptions.h"
#include "Utility.h"
#include <string>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <limits>
namespace FIX
{
typedef int signed_int;
typedef unsigned int unsigned_int;
#define UNSIGNED_VALUE_OF( x ) unsigned_int( x < 0 ? -x : x )
#define IS_SPACE( x ) ( x == ' ' )
#define IS_DIGIT( x ) ( unsigned_int( x - '0' ) < 10 )
inline int number_of_symbols_in( const signed_int value )
{
unsigned_int number = UNSIGNED_VALUE_OF( value );
int symbols = 0;
while( number > 9999 )
{
symbols += 4;
number /= 10000;
}
// small tweak to make comparison times consistent
// always 2 comparisons instead of [1 - 4]
if( number > 99 )
{
if( number > 999 )
symbols += 4;
else
symbols += 3;
}
else
{
if( number > 9 )
symbols += 2;
else
symbols += 1;
}
if( value < 0 )
symbols += 1;
return symbols;
}
static const char digit_pairs[201] = {
"00010203040506070809"
"10111213141516171819"
"20212223242526272829"
"30313233343536373839"
"40414243444546474849"
"50515253545556575859"
"60616263646566676869"
"70717273747576777879"
"80818283848586878889"
"90919293949596979899"
};
inline char* integer_to_string( char* buf, const size_t len, signed_int t )
{
const bool isNegative = t < 0;
char* p = buf + len;
*--p = '\0';
unsigned_int number = UNSIGNED_VALUE_OF( t );
while( number > 99 )
{
unsigned_int pos = number % 100;
number /= 100;
p -= 2;
*(short*)(p) = *(short*)(digit_pairs + 2 * pos);
}
if( number > 9 )
{
p -= 2;
*(short*)(p) = *(short*)(digit_pairs + 2 * number);
}
else
{
*--p = '0' + char(number);
}
if( isNegative )
*--p = '-';
return p;
}
inline char* integer_to_string_padded
( char* buf, const size_t len, signed_int t,
const size_t width = 0,
const char paddingChar = '0')
{
char* p = integer_to_string( buf, len, t );
if( !width )
return p;
const char* stop_p = buf + len - width - 1;
if( stop_p < buf ) stop_p = buf;
while( p > stop_p )
*--p = paddingChar;
return p;
}
/// Empty converter is a no-op.
struct EmptyConvertor
{
static const std::string& convert( const std::string& value )
{ return value; }
};
typedef EmptyConvertor StringConvertor;
/// Converts integer to/from a string
struct IntConvertor
{
static std::string convert( signed_int value )
{
// buffer is big enough for significant digits and extra digit,
// minus and null
char buffer[std::numeric_limits<signed_int>::digits10 + 3];
const char* const start
= integer_to_string( buffer, sizeof (buffer), value );
return std::string( start, buffer + sizeof (buffer) - start - 1 );
}
static bool convert(
std::string::const_iterator str,
std::string::const_iterator end,
signed_int& result )
{
bool isNegative = false;
signed_int x = 0;
if( str == end )
return false;
if( *str == '-' )
{
isNegative = true;
if( ++str == end )
return false;
}
do
{
const unsigned_int c = *str - '0';
if( c > 9 ) return false;
x = 10 * x + c;
} while ( ++str != end );
if( isNegative )
x = -x;
result = x;
return true;
}
static bool convert( const std::string& value, signed_int& result )
{
return convert( value.begin(), value.end(), result );
}
static signed_int convert( const std::string& value )
throw( FieldConvertError )
{
signed_int result = 0;
if( !convert( value.begin(), value.end(), result ) )
throw FieldConvertError(value);
else
return result;
}
/// Converts only positive number e.g. FIX field ID: [1 ... 2147483647]
/// No leading whitespace/zero/plus/sign symbols allowed
/// Value is fixed to not make difference between 32bit and 64bit code
static bool convertPositive(
std::string::const_iterator str,
std::string::const_iterator end,
signed_int& result )
{
const int MAX_VALUE = 2147483647; // max value for 32-bit signed integer
const int HIGH_MARK = MAX_VALUE / 10;
const unsigned_int STOP_SYMBOL = MAX_VALUE % 10;
const std::size_t MAX_DIGITS = 10; // integer can hold up to 10 digits
const std::size_t length = std::distance( str, end );
if( length < 1 || length > MAX_DIGITS)
return false;
if( length == MAX_DIGITS )
{
end = str;
std::advance( end, length - 1 );
}
const unsigned_int ch = *str - '1';
if( ch > 8 )
return false;
unsigned_int x = 0;
do
{
const unsigned_int c = *str - '0';
if( c > 9 ) return false;
x = 10 * x + c;
} while( ++str < end );
// complete overflow condition check and value calculation
// this saves about 25% of speed when executed out of the main loop
if( length == MAX_DIGITS )
{
if( x > (unsigned int)HIGH_MARK )
return false;
const unsigned_int c = *str - '0';
if( x == (unsigned int)HIGH_MARK && c > STOP_SYMBOL )
return false;
x = 10 * x + c;
}
result = x;
return true;
}
static signed_int convertPositive( const std::string& value )
throw( FieldConvertError )
{
signed_int result = 0;
if( !convertPositive( value.begin(), value.end(), result ) )
throw FieldConvertError(value);
else
return result;
}
};
/// Converts checksum to/from a string
struct CheckSumConvertor
{
static std::string convert( int value )
throw( FieldConvertError )
{
if ( value > 255 || value < 0 ) throw FieldConvertError();
char result[4];
if( integer_to_string_padded(result, sizeof(result), value, 3) != result )
{
throw FieldConvertError();
}
return std::string( result, 3 );
}
static bool convert( const std::string& value, int& result )
{
return IntConvertor::convert( value, result );
}
static int convert( const std::string& value )
throw( FieldConvertError )
{
return IntConvertor::convert( value );
}
};
/// Converts double to/from a string
struct DoubleConvertor
{
private:
/*Simple and fast atof (ascii to float) function.
Executes about 5x faster than standard MSCRT library atof().
An attractive alternative if the number of calls is in the millions.
Assumes input is a proper integer, fraction, or scientific format.
Matches library atof() to 15 digits (except at extreme exponents).
Follows atof() precedent of essentially no error checking.
09-May-2009 Tom Van Baak (tvb) www.LeapSecond.com */
static double fast_atof (const char *p)
{
bool frac(false);
double sign(1.), value(0.), scale(1.);
while (IS_SPACE(*p))
++p;
// Get sign, if any.
if (*p == '-')
{
sign = -1.;
++p;
}
else if (*p == '+')
++p;
// Get digits before decimal point or exponent, if any.
while (IS_DIGIT(*p))
{
value = value * 10. + (*p - '0');
++p;
}
// Get digits after decimal point, if any.
if (*p == '.')
{
++p;
double pow10(10.);
while (IS_DIGIT(*p))
{
value += (*p - '0') / pow10;
pow10 *= 10.;
++p;
}
}
// Handle exponent, if any.
if (toupper(*p) == 'E')
{
unsigned int expon(0);
++p;
// Get sign of exponent, if any.
if (*p == '-')
{
frac = true;
++p;
}
else if (*p == '+')
++p;
// Get digits of exponent, if any.
while (IS_DIGIT(*p))
{
expon = expon * 10 + (*p - '0');
++p;
}
if (expon > 308)
expon = 308;
// Calculate scaling factor.
while (expon >= 50)
{
scale *= 1E50;
expon -= 50;
}
while (expon >= 8)
{
scale *= 1E8;
expon -= 8;
}
while (expon > 0)
{
scale *= 10.0;
expon -= 1;
}
}
// Return signed and scaled floating point result.
return sign * (frac ? (value / scale) : (value * scale));
}
public:
static std::string convert( double value, int padding = 0 )
{
char result[32];
char *end = 0;
int size;
if( value == 0 || value > 0.0001 || value <= -0.0001 )
{
size = STRING_SPRINTF( result, "%.15g", value );
if( padding > 0 )
{
char* point = result;
end = result + size - 1;
while( *point != '.' && *point != 0 )
point++;
if( *point == 0 )
{
end = point;
*point = '.';
size++;
}
int needed = padding - (int)(end - point);
while( needed-- > 0 )
{
*(++end) = '0';
size++;
}
*(end+1) = 0;
}
}
else
{
size = STRING_SPRINTF( result, "%.15f", value );
// strip trailing 0's
end = result + size - 1;
if( padding > 0 )
{
int discard = 15 - padding;
while( (*end == '0') && (discard-- > 0) )
{
*(end--) = 0;
size--;
}
}
else
{
while( *end == '0' )
{
*(end--) = 0;
size--;
}
}
}
return std::string( result, size );
}
static bool convert( const std::string& value, double& result )
{
const char * i = value.c_str();
// Catch null strings
if( !*i ) return false;
// Eat leading '-' and recheck for null string
if( *i == '-' && !*++i ) return false;
bool haveDigit = false;
if( IS_DIGIT(*i) )
{
haveDigit = true;
while( IS_DIGIT (*++i) );
}
if( *i == '.' && IS_DIGIT(*++i) )
{
haveDigit = true;
while( IS_DIGIT (*++i) );
}
if( *i || !haveDigit ) return false;
result = fast_atof( value.c_str() );
return true;
}
static double convert( const std::string& value )
throw( FieldConvertError )
{
double result = 0.0;
if( !convert( value, result ) )
throw FieldConvertError(value);
else
return result;
}
};
/// Converts character to/from a string
struct CharConvertor
{
static std::string convert( char value )
{
if( value == '\0' ) return "";
return std::string( 1, value );
}
static bool convert( const std::string& value, char& result )
{
if( value.size() != 1 ) return false;
result = value[0];
return true;
}
static char convert( const std::string& value )
throw( FieldConvertError )
{
char result = '\0';
if( !convert( value, result ) )
throw FieldConvertError(value);
else
return result;
}
};
/// Converts boolean to/from a string
struct BoolConvertor
{
static std::string convert( bool value )
{
const char ch = value ? 'Y' : 'N';
return std::string( 1, ch );
}
static bool convert( const std::string& value, bool& result )
{
if( value.size() != 1 ) return false;
switch( value[0] )
{
case 'Y': result = true; break;
case 'N': result = false; break;
default: return false;
}
return true;
}
static bool convert( const std::string& value )
throw( FieldConvertError )
{
bool result = false;
if( !convert( value, result ) )
throw FieldConvertError(value);
else
return result;
}
};
/// Converts a UtcTimeStamp to/from a string
struct UtcTimeStampConvertor
{
static std::string convert( const UtcTimeStamp& value,
bool showMilliseconds = false )
throw( FieldConvertError )
{
char result[ 18+4 ];
int year, month, day, hour, minute, second, millis;
value.getYMD( year, month, day );
value.getHMS( hour, minute, second, millis );
integer_to_string_padded( result, 5, year, 4 );
integer_to_string_padded( result + 4, 3, month, 2 );
integer_to_string_padded( result + 6, 3, day, 2 );
result[8] = '-';
integer_to_string_padded( result + 9, 3, hour, 2 );
result[11] = ':';
integer_to_string_padded( result + 12, 3, minute, 2 );
result[14] = ':';
integer_to_string_padded( result + 15, 3, second, 2 );
if( showMilliseconds )
{
result[17] = '.';
if( integer_to_string_padded ( result + 18, 4, millis, 3 )
!= result + 18 )
{
throw FieldConvertError();
}
}
return result;
}
static UtcTimeStamp convert( const std::string& value,
bool calculateDays = false )
throw( FieldConvertError )
{
bool haveMilliseconds = false;
switch( value.size() )
{
case 21: haveMilliseconds = true;
case 17: break;
default: throw FieldConvertError(value);
}
int i = 0;
int c = 0;
for( c = 0; c < 8; ++c )
if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
if (value[i++] != '-') throw FieldConvertError(value);
for( c = 0; c < 2; ++c )
if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
if( value[i++] != ':' ) throw FieldConvertError(value);
for( c = 0; c < 2; ++c )
if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
if( value[i++] != ':' ) throw FieldConvertError(value);
for( c = 0; c < 2; ++c )
if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
if( haveMilliseconds )
{
if( value[i++] != '.' ) throw FieldConvertError(value);
for( c = 0; c < 3; ++c )
if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
}
int year, mon, mday, hour, min, sec, millis;
i = 0;
year = value[i++] - '0';
year = 10 * year + value[i++] - '0';
year = 10 * year + value[i++] - '0';
year = 10 * year + value[i++] - '0';
mon = value[i++] - '0';
mon = 10 * mon + value[i++] - '0';
if( mon < 1 || 12 < mon ) throw FieldConvertError(value);
mday = value[i++] - '0';
mday = 10 * mday + value[i++] - '0';
if( mday < 1 || 31 < mday ) throw FieldConvertError(value);
++i; // skip '-'
hour = value[i++] - '0';
hour = 10 * hour + value[i++] - '0';
// No check for >= 0 as no '-' are converted here
if( 23 < hour ) throw FieldConvertError(value);
++i; // skip ':'
min = value[i++] - '0';
min = 10 * min + value[i++] - '0';
// No check for >= 0 as no '-' are converted here
if( 59 < min ) throw FieldConvertError(value);
++i; // skip ':'
sec = value[i++] - '0';
sec = 10 * sec + value[i++] - '0';
// No check for >= 0 as no '-' are converted here
if( 60 < sec ) throw FieldConvertError(value);
if( haveMilliseconds )
{
millis = (100 * (value[i+1] - '0')
+ 10 * (value[i+2] - '0')
+ (value[i+3] - '0'));
}
else
millis = 0;
return UtcTimeStamp (hour, min, sec, millis,
mday, mon, year);
}
};
/// Converts a UtcTimeOnly to/from a string
struct UtcTimeOnlyConvertor
{
static std::string convert( const UtcTimeOnly& value,
bool showMilliseconds = false)
throw( FieldConvertError )
{
char result[ 9+4 ];
int hour, minute, second, millis;
value.getHMS( hour, minute, second, millis );
integer_to_string_padded ( result, 3, hour, 2 );
result[2] = ':';
integer_to_string_padded ( result + 3, 3, minute, 2 );
result[5] = ':';
integer_to_string_padded ( result + 6, 3, second, 2 );
if( showMilliseconds )
{
result[8] = '.';
if( integer_to_string_padded ( result + 9, 4, millis, 3 )
!= result + 9 )
throw FieldConvertError();
}
return result;
}
static UtcTimeOnly convert( const std::string& value )
throw( FieldConvertError )
{
bool haveMilliseconds = false;
switch( value.size() )
{
case 12: haveMilliseconds = true;
case 8: break;
default: throw FieldConvertError(value);
}
int i = 0;
int c = 0;
for( c = 0; c < 2; ++c )
if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
if( value[i++] != ':' ) throw FieldConvertError(value);
for( c = 0; c < 2; ++c )
if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
if( value[i++] != ':' ) throw FieldConvertError(value);
for( c = 0; c < 2; ++c )
if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
if( haveMilliseconds )
{
// ++i instead of i++ skips the '.' separator
for( c = 0; c < 3; ++c )
if( !IS_DIGIT(value[++i]) ) throw FieldConvertError(value);
}
int hour, min, sec, millis;
i = 0;
hour = value[i++] - '0';
hour = 10 * hour + value[i++] - '0';
// No check for >= 0 as no '-' are converted here
if( 23 < hour ) throw FieldConvertError(value);
++i; // skip ':'
min = value[i++] - '0';
min = 10 * min + value[i++] - '0';
// No check for >= 0 as no '-' are converted here
if( 59 < min ) throw FieldConvertError(value);
++i; // skip ':'
sec = value[i++] - '0';
sec = 10 * sec + value[i++] - '0';
// No check for >= 0 as no '-' are converted here
if( 60 < sec ) throw FieldConvertError(value);
if( haveMilliseconds )
{
millis = (100 * (value[i+1] - '0')
+ 10 * (value[i+2] - '0')
+ (value[i+3] - '0'));
}
else
millis = 0;
return UtcTimeOnly( hour, min, sec, millis );
}
};
/// Converts a UtcDate to/from a string
struct UtcDateConvertor
{
static std::string convert( const UtcDate& value )
throw( FieldConvertError )
{
char result[ 9 ];
int year, month, day;
value.getYMD( year, month, day );
integer_to_string_padded( result, 5, year, 4 );
integer_to_string_padded( result + 4, 3, month, 2 );
integer_to_string_padded( result + 6, 3, day, 2 );
return result;
}
static UtcDate convert( const std::string& value )
throw( FieldConvertError )
{
if( value.size() != 8 ) throw FieldConvertError(value);
int i = 0;
for( int c=0; c<8; ++c )
if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
int year, mon, mday;
i = 0;
year = value[i++] - '0';
year = 10 * year + value[i++] - '0';
year = 10 * year + value[i++] - '0';
year = 10 * year + value[i++] - '0';
mon = value[i++] - '0';
mon = 10 * mon + value[i++] - '0';
if( mon < 1 || 12 < mon )
throw FieldConvertError(value);
mday = value[i++] - '0';
mday = 10 * mday + value[i++] - '0';
if( mday < 1 || 31 < mday )
throw FieldConvertError(value);
return UtcDateOnly( mday, mon, year );
}
};
typedef UtcDateConvertor UtcDateOnlyConvertor;
typedef StringConvertor STRING_CONVERTOR;
typedef CharConvertor CHAR_CONVERTOR;
typedef DoubleConvertor PRICE_CONVERTOR;
typedef IntConvertor INT_CONVERTOR;
typedef DoubleConvertor AMT_CONVERTOR;
typedef DoubleConvertor QTY_CONVERTOR;
typedef StringConvertor CURRENCY_CONVERTOR;
typedef StringConvertor MULTIPLEVALUESTRING_CONVERTOR;
typedef StringConvertor MULTIPLESTRINGVALUE_CONVERTOR;
typedef StringConvertor MULTIPLECHARVALUE_CONVERTOR;
typedef StringConvertor EXCHANGE_CONVERTOR;
typedef UtcTimeStampConvertor UTCTIMESTAMP_CONVERTOR;
typedef BoolConvertor BOOLEAN_CONVERTOR;
typedef StringConvertor LOCALMKTDATE_CONVERTOR;
typedef StringConvertor DATA_CONVERTOR;
typedef DoubleConvertor FLOAT_CONVERTOR;
typedef DoubleConvertor PRICEOFFSET_CONVERTOR;
typedef StringConvertor MONTHYEAR_CONVERTOR;
typedef StringConvertor DAYOFMONTH_CONVERTOR;
typedef UtcDateConvertor UTCDATE_CONVERTOR;
typedef UtcTimeOnlyConvertor UTCTIMEONLY_CONVERTOR;
typedef IntConvertor NUMINGROUP_CONVERTOR;
typedef DoubleConvertor PERCENTAGE_CONVERTOR;
typedef IntConvertor SEQNUM_CONVERTOR;
typedef IntConvertor LENGTH_CONVERTOR;
typedef StringConvertor COUNTRY_CONVERTOR;
typedef StringConvertor TZTIMEONLY_CONVERTOR;
typedef StringConvertor TZTIMESTAMP_CONVERTOR;
typedef StringConvertor XMLDATA_CONVERTOR;
typedef StringConvertor LANGUAGE_CONVERTOR;
typedef CheckSumConvertor CHECKSUM_CONVERTOR;
}
#endif //FIX_FIELDCONVERTORS_H
+244
View File
@@ -0,0 +1,244 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_FIELDMAP
#define FIX_FIELDMAP
#ifdef _MSC_VER
#pragma warning( disable: 4786 )
#endif
#include "Field.h"
#include "MessageSorters.h"
#include "Exceptions.h"
#include "Utility.h"
#include <map>
#include <vector>
#include <sstream>
#include <algorithm>
namespace FIX
{
/**
* Stores and organizes a collection of Fields.
*
* This is the basis for a message, header, and trailer. This collection
* class uses a sorter to keep the fields in a particular order.
*/
class FieldMap
{
public:
#if defined(_MSC_VER) && _MSC_VER < 1300
typedef std::multimap < int, FieldBase, message_order > Fields;
typedef std::map < int, std::vector < FieldMap* >, std::less<int> > Groups;
#else
typedef std::multimap < int, FieldBase, message_order,
ALLOCATOR<std::pair<const int,FieldBase> > > Fields;
typedef std::map < int, std::vector < FieldMap* >, std::less<int>,
ALLOCATOR<std::pair<const int, std::vector< FieldMap* > > > > Groups;
#endif
typedef Fields::const_iterator iterator;
typedef iterator const_iterator;
typedef Groups::const_iterator g_iterator;
typedef Groups::const_iterator g_const_iterator;
FieldMap( const message_order& order =
message_order( message_order::normal ) )
: m_fields( order ) {}
FieldMap( const int order[] )
: m_fields( message_order(order) ) {}
FieldMap( const FieldMap& copy )
{ *this = copy; }
virtual ~FieldMap();
FieldMap& operator=( const FieldMap& rhs );
/// Set a field without type checking
void setField( const FieldBase& field, bool overwrite = true )
throw( RepeatedTag )
{
if(!overwrite)
m_fields.insert( Fields::value_type( field.getField(), field ) );
else
{
Fields::iterator i = m_fields.find( field.getField() );
if( i == m_fields.end() )
m_fields.insert( Fields::value_type( field.getField(), field ) );
else
i->second = field;
}
}
/// Set a field without a field class
void setField( int field, const std::string& value )
throw( RepeatedTag, NoTagValue )
{
FieldBase fieldBase( field, value );
setField( fieldBase );
}
/// Get a field if set
bool getFieldIfSet( FieldBase& field ) const
{
Fields::const_iterator iter = m_fields.find( field.getField() );
if ( iter == m_fields.end() )
return false;
field = iter->second;
return true;
}
/// Get a field without type checking
FieldBase& getField( FieldBase& field )
const throw( FieldNotFound )
{
field = getFieldRef( field.getField() );
return field;
}
/// Get a field without a field class
const std::string& getField( int field )
const throw( FieldNotFound )
{
return getFieldRef( field ).getString();
}
/// Get direct access to a field through a reference
const FieldBase& getFieldRef( int field )
const throw( FieldNotFound )
{
Fields::const_iterator iter = m_fields.find( field );
if ( iter == m_fields.end() )
throw FieldNotFound( field );
return iter->second;
}
/// Get direct access to a field through a pointer
const FieldBase* const getFieldPtr( int field )
const throw( FieldNotFound )
{
return &getFieldRef( field );
}
/// Check to see if a field is set
bool isSetField( const FieldBase& field ) const
{ return isSetField( field.getField() ); }
/// Check to see if a field is set by referencing its number
bool isSetField( int field ) const
{ return m_fields.find( field ) != m_fields.end(); }
/// Remove a field. If field is not present, this is a no-op.
void removeField( int field );
/// Add a group.
void addGroup( int field, const FieldMap& group, bool setCount = true );
/// Acquire ownership of Group object
void addGroupPtr( int field, FieldMap * group, bool setCount = true );
/// Replace a specific instance of a group.
void replaceGroup( int num, int field, const FieldMap& group );
/// Get a specific instance of a group.
FieldMap& getGroup( int num, int field, FieldMap& group ) const
throw( FieldNotFound )
{
return group = getGroupRef( num, field );
}
/// Get direct access to a field through a reference
FieldMap& getGroupRef( int num, int field ) const
throw( FieldNotFound )
{
Groups::const_iterator i = m_groups.find( field );
if( i == m_groups.end() ) throw FieldNotFound( field );
if( num <= 0 ) throw FieldNotFound( field );
if( i->second.size() < (unsigned)num ) throw FieldNotFound( field );
return *( *(i->second.begin() + (num-1) ) );
}
/// Get direct access to a field through a pointer
FieldMap* getGroupPtr( int num, int field ) const
throw( FieldNotFound )
{
return &getGroupRef( num, field );
}
/// Remove a specific instance of a group.
void removeGroup( int num, int field );
/// Remove all instances of a group.
void removeGroup( int field );
/// Check to see any instance of a group exists
bool hasGroup( int field ) const;
/// Check to see if a specific instance of a group exists
bool hasGroup( int num, int field ) const;
/// Count the number of instance of a group
size_t groupCount( int field ) const;
/// Clear all fields from the map
void clear();
/// Check if map contains any fields
bool isEmpty();
size_t totalFields() const;
std::string& calculateString( std::string& ) const;
int calculateLength( int beginStringField = FIELD::BeginString,
int bodyLengthField = FIELD::BodyLength,
int checkSumField = FIELD::CheckSum ) const;
int calculateTotal( int checkSumField = FIELD::CheckSum ) const;
iterator begin() const { return m_fields.begin(); }
iterator end() const { return m_fields.end(); }
g_iterator g_begin() const { return m_groups.begin(); }
g_iterator g_end() const { return m_groups.end(); }
private:
Fields m_fields;
Groups m_groups;
};
/*! @} */
}
#define FIELD_SET( MAP, FIELD ) \
bool isSet( const FIELD& field ) const \
{ return (MAP).isSetField(field); } \
void set( const FIELD& field ) \
{ (MAP).setField(field); } \
FIELD& get( FIELD& field ) const \
{ return (FIELD&)(MAP).getField(field); } \
bool getIfSet( FIELD& field ) const \
{ return (MAP).getFieldIfSet(field); }
#define FIELD_GET_PTR( MAP, FLD ) \
(const FIX::FLD*)MAP.getFieldPtr( FIX::FIELD::FLD )
#define FIELD_GET_REF( MAP, FLD ) \
(const FIX::FLD&)MAP.getFieldRef( FIX::FIELD::FLD )
#define FIELD_THROW_IF_NOT_FOUND( MAP, FLD ) \
if( !(MAP).isSetField( FIX::FIELD::FLD) ) \
throw FieldNotFound( FIX::FIELD::FLD )
#endif //FIX_FIELDMAP
+46
View File
@@ -0,0 +1,46 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_FIELDNUMBERS_BASE_H
#define FIX_FIELDNUMBERS_BASE_H
#include <iostream>
#include "FixFieldNumbers.h"
namespace FIX
{
namespace FIELD
{
const int FIX40_LastField = PrevClosePx;
const int FIX41_LastField = PegDifference;
const int FIX42_LastField = EncodedListStatusText;
const int FIX43_LastField = SideComplianceID;
const int FIX44_LastField = LegInterestAccrualDate;
const int FIX50_LastField = ExchangeSpecialInstructions;
const int NormalMin = 1;
const int NormalMax = 4999;
const int UserMin = 5000;
const int UserMax = 9999;
const int InternalMin = 10000;
}
}
#endif //FIX_FIELDNUMBERS_BASE_H
+698
View File
@@ -0,0 +1,698 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_FIELDTYPES_H
#define FIX_FIELDTYPES_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Utility.h"
#include <string>
#include <time.h>
namespace FIX
{
/*! \addtogroup user
* @{
*/
/// Date and Time stored as a Julian day number and number of
/// milliseconds since midnight. Does not perform any timezone
/// calculations. All magic numbers and related calculations
/// have been taken from:
///
/// \sa http://www.faqs.org/faqs/calendars.faq
/// \sa http://scienceworld.wolfram.com/astronomy/JulianDate.html
/// \sa http://scienceworld.wolfram.com/astronomy/GregorianCalendar.html
/// \sa http://scienceworld.wolfram.com/astronomy/Weekday.html
///
/// \author Caleb Epstein <caleb.epstein at gmail dot com>
struct DateTime
{
int m_date;
int m_time;
/// Magic numbers
enum
{
SECONDS_PER_DAY = 86400,
SECONDS_PER_HOUR = 3600,
SECONDS_PER_MIN = 60,
MINUTES_PER_HOUR = 60,
MILLIS_PER_DAY = 86400000,
MILLIS_PER_HOUR = 3600000,
MILLIS_PER_MIN = 60000,
MILLIS_PER_SEC = 1000,
// time_t epoch (1970-01-01) as a Julian date
JULIAN_19700101 = 2440588
};
/// Default constructor - initializes to zero
DateTime () : m_date (0), m_time (0) {}
/// Construct from a Julian day number and time in millis
DateTime (int date, int time) : m_date (date), m_time (time) {}
/// Construct from the specified components
DateTime( int year, int month, int day,
int hour, int minute, int second, int millis )
{
m_date = julianDate( year, month, day );
m_time = makeHMS( hour, minute, second, millis );
}
virtual ~DateTime() {}
/// Return the year portion of the date
inline int getYear() const
{
int y, m, d;
getYMD( y, m, d );
return y;
}
/// Return the month (1-12) portion of the date
inline int getMonth() const
{
int y, m, d;
getYMD( y, m, d );
return m;
}
/// Return the day of the month portion of the date
inline int getDay() const
{
int y, m, d;
getYMD( y, m, d );
return d;
}
/// Another name for the day of the month. Bad name, but used
/// because of the legacy UtcTimeStamp interface
inline int getDate() const { return getDay(); }
/// Return the internal julian date
inline int getJulianDate() const { return m_date; }
/// Return the hour portion of the time (0-23)
inline int getHour() const
{
return m_time / MILLIS_PER_HOUR;
}
/// Return the minute portion of the time (0-59)
inline int getMinute() const
{
return (m_time / MILLIS_PER_MIN) % MINUTES_PER_HOUR;
}
/// Return the second portion of the time (0-59)
inline int getSecond() const
{
return (m_time / MILLIS_PER_SEC) % SECONDS_PER_MIN;
}
/// Return the millisecond portion of the time
inline int getMillisecond() const
{
return m_time % MILLIS_PER_SEC;
}
/// Load the referenced values with the year, month and day
/// portions of the date in a single operation
inline void getYMD (int& year, int& month, int& day) const
{
getYMD( m_date, year, month, day );
}
/// Load the referenced values with the hour, minute, second and
/// millisecond portions of the time in a single operation
inline void getHMS( int& hour, int& minute, int& second, int& millis ) const
{
int ticks = m_time / MILLIS_PER_SEC;
hour = ticks / SECONDS_PER_HOUR;
minute = (ticks / SECONDS_PER_MIN) % MINUTES_PER_HOUR;
second = ticks % SECONDS_PER_MIN;
millis = m_time % MILLIS_PER_SEC;
}
/// Calculate the weekday of the date (Sunday is 1, Saturday is 7)
inline int getWeekDay() const
{
int Y, M, D;
getYMD (Y, M, D);
int m = M >= 3 ? M - 2 : M + 10;
int Yprime = M >= 3 ? Y : Y - 1;
int y = Yprime % 100;
int c = Yprime / 100;
int wd = (D + int (2.6 * m - 0.2) + y + int (y / 4) + int (c / 4) -
(2 * c)) % 7;
return 1 + (wd < 0 ? 7 + wd : wd);
}
/// Convert the DateTime to a time_t. Note that this operation
/// can overflow on 32-bit platforms when we go beyond year 2038.
inline time_t getTimeT() const
{
return (SECONDS_PER_DAY * (m_date - JULIAN_19700101) +
m_time / MILLIS_PER_SEC);
}
/// Convert the DateTime to a struct tm which is in UTC
tm getTmUtc() const
{
int year, month, day;
int hour, minute, second, millis;
tm result = { 0 };
getYMD( year, month, day );
getHMS( hour, minute, second, millis );
result.tm_year = year - 1900;
result.tm_mon = month - 1;
result.tm_mday = day;
result.tm_hour = hour;
result.tm_min = minute;
result.tm_sec = second;
result.tm_isdst = -1;
return result;
}
/// Set the date portion of the DateTime
void setYMD( int year, int month, int day )
{
m_date = julianDate( year, month, day );
}
/// Set the time portion of the DateTime
void setHMS( int hour, int minute, int second, int millis )
{
m_time = makeHMS( hour, minute, second, millis );
}
/// Set the hour portion of the time
void setHour( int hour )
{
int old_hour, min, sec, millis;
getHMS( old_hour, min, sec, millis );
setHMS( hour, min, sec, millis );
}
/// Set the minute portion of the time
void setMinute( int min )
{
int hour, old_min, sec, millis;
getHMS( hour, old_min, sec, millis );
setHMS( hour, min, sec, millis );
}
/// Set the seconds portion of the time
void setSecond( int sec )
{
int hour, min, old_sec, millis;
getHMS( hour, min, old_sec, millis );
setHMS( hour, min, sec, millis );
}
/// Set the millisecond portion of the time
void setMillisecond( int millis )
{
int hour, min, sec, old_millis;
getHMS( hour, min, sec, old_millis );
setHMS( hour, min, sec, millis );
}
/// Clear the date portion of the DateTime
void clearDate()
{
m_date = 0;
}
/// Clear the time portion of the DateTime
void clearTime()
{
m_time = 0;
}
/// Set the internal date and time members
void set( int date, int time ) { m_date = date; m_time = time; }
/// Initialize from another DateTime
void set( const DateTime& other )
{
m_date = other.m_date;
m_time = other.m_time;
}
/// Add a number of seconds to this
void operator+=( int seconds )
{
int d = seconds / SECONDS_PER_DAY;
int s = seconds % SECONDS_PER_DAY;
m_date += d;
m_time += s * MILLIS_PER_SEC;
if( m_time > MILLIS_PER_DAY )
{
m_date++;
m_time %= MILLIS_PER_DAY;
}
else if( m_time < 0 )
{
m_date--;
m_time += MILLIS_PER_DAY;
}
}
/// Helper method to convert a broken down time to a number of
/// milliseconds since midnight
static int makeHMS( int hour, int minute, int second, int millis )
{
return MILLIS_PER_SEC * (SECONDS_PER_HOUR * hour +
SECONDS_PER_MIN * minute +
second) + millis;
}
/// Return the current wall-clock time as a utc DateTime
static DateTime nowUtc();
/// Return the current wall-clock time as a local DateTime
static DateTime nowLocal();
/// Convert a time_t and optional milliseconds to a DateTime
static DateTime fromUtcTimeT( time_t t, int millis = 0 )
{
struct tm tm = time_gmtime( &t );
return fromTm( tm, millis );
}
static DateTime fromLocalTimeT( time_t t, int millis = 0 )
{
struct tm tm = time_localtime( &t );
return fromTm( tm, millis );
}
/// Convert a tm and optional milliseconds to a DateTime. \note
/// the tm structure is assumed to contain a date specified in UTC
static DateTime fromTm( const tm& tm, int millis = 0 )
{
return DateTime ( julianDate(tm.tm_year + 1900, tm.tm_mon + 1,
tm.tm_mday),
makeHMS(tm.tm_hour, tm.tm_min, tm.tm_sec, millis) );
}
/// Helper method to calculate a Julian day number.
static int julianDate( int year, int month, int day )
{
int a = (14 - month) / 12;
int y = year + 4800 - a;
int m = month + 12 * a - 3;
return (day + int ((153 * m + 2) / 5) + y * 365 +
int (y / 4) - int (y / 100) + int (y / 400) - 32045);
}
/// Convert a Julian day number to a year, month and day
static void getYMD( int jday, int& year, int& month, int& day )
{
int a = jday + 32044;
int b = (4 * a + 3) / 146097;
int c = a - int ((b * 146097) / 4);
int d = (4 * c + 3) / 1461;
int e = c - int ((1461 * d) / 4);
int m = (5 * e + 2) / 153;
day = e - int ((153 * m + 2) / 5) + 1;
month = m + 3 - 12 * int (m / 10);
year = b * 100 + d - 4800 + int (m / 10);
}
};
inline bool operator==( const DateTime& lhs, const DateTime& rhs )
{
return lhs.m_date == rhs.m_date && lhs.m_time == rhs.m_time;
}
inline bool operator!=( const DateTime& lhs, const DateTime& rhs )
{
return !(lhs == rhs);
}
inline bool operator<( const DateTime& lhs, const DateTime& rhs )
{
if( lhs.m_date < rhs.m_date )
return true;
else if( lhs.m_date > rhs.m_date )
return false;
else if( lhs.m_time < rhs.m_time )
return true;
return false;
}
inline bool operator>( const DateTime& lhs, const DateTime& rhs )
{
return !(lhs == rhs || lhs < rhs);
}
inline bool operator<=( const DateTime& lhs, const DateTime& rhs )
{
return lhs == rhs || lhs < rhs;
}
inline bool operator>=( const DateTime& lhs, const DateTime& rhs )
{
return lhs == rhs || lhs > rhs;
}
/// Calculate the difference between two DateTime values and return
/// the result as a number of seconds
inline int operator-( const DateTime& lhs, const DateTime& rhs )
{
return (DateTime::SECONDS_PER_DAY * (lhs.m_date - rhs.m_date) +
// Truncate the millis before subtracting
lhs.m_time / 1000 - rhs.m_time / 1000);
}
/// Date and Time represented in UTC.
class UtcTimeStamp : public DateTime
{
public:
/// Defaults to the current date and time
UtcTimeStamp()
: DateTime( DateTime::nowUtc() ) {}
/// Defaults to the current date
UtcTimeStamp( int hour, int minute, int second, int millisecond = 0 )
: DateTime( DateTime::nowUtc() )
{
setHMS( hour, minute, second, millisecond );
}
UtcTimeStamp( int hour, int minute, int second,
int date, int month, int year )
: DateTime( year, month, date, hour, minute, second, 0 ) {}
UtcTimeStamp( int hour, int minute, int second, int millisecond,
int date, int month, int year )
: DateTime( year, month, date, hour, minute, second, millisecond ) {}
explicit UtcTimeStamp( time_t time, int millisecond = 0 )
: DateTime( fromUtcTimeT (time, millisecond) ) {}
UtcTimeStamp( const tm* time, int millisecond = 0 )
: DateTime( fromTm (*time, millisecond) ) {}
void setCurrent()
{
set( DateTime::nowUtc() );
}
};
/// Date and Time represented in local time.
class LocalTimeStamp : public DateTime
{
public:
/// Defaults to the current date and time
LocalTimeStamp()
: DateTime( DateTime::nowLocal() ) {}
/// Defaults to the current date
LocalTimeStamp( int hour, int minute, int second, int millisecond = 0 )
: DateTime( DateTime::nowLocal() )
{
setHMS( hour, minute, second, millisecond );
}
LocalTimeStamp( int hour, int minute, int second,
int date, int month, int year )
: DateTime( year, month, date, hour, minute, second, 0 ) {}
LocalTimeStamp( int hour, int minute, int second, int millisecond,
int date, int month, int year )
: DateTime( year, month, date, hour, minute, second, millisecond ) {}
explicit LocalTimeStamp( time_t time, int millisecond = 0 )
: DateTime( fromLocalTimeT (time, millisecond) ) {}
LocalTimeStamp( const tm* time, int millisecond = 0 )
: DateTime( fromTm (*time, millisecond) ) {}
void setCurrent()
{
set( DateTime::nowLocal() );
}
};
/// Time only represented in UTC.
class UtcTimeOnly : public DateTime
{
public:
/// Defaults to the current time
UtcTimeOnly()
{
setCurrent();
}
UtcTimeOnly( const DateTime& val )
: DateTime(val)
{
clearDate();
}
UtcTimeOnly( int hour, int minute, int second, int millisecond = 0 )
{
setHMS( hour, minute, second, millisecond );
}
explicit UtcTimeOnly( time_t time, int millisecond = 0 )
: DateTime( fromUtcTimeT (time, millisecond) )
{
clearDate();
}
UtcTimeOnly( const tm* time, int millisecond = 0 )
: DateTime( fromTm (*time, millisecond) )
{
clearDate();
}
/// Set to the current time.
void setCurrent()
{
DateTime d = nowUtc();
m_time = d.m_time;
}
};
/// Time only represented in local time.
class LocalTimeOnly : public DateTime
{
public:
/// Defaults to the current time
LocalTimeOnly()
{
setCurrent();
}
LocalTimeOnly( const DateTime& val )
: DateTime(val)
{
clearDate();
}
LocalTimeOnly( int hour, int minute, int second, int millisecond = 0 )
{
setHMS( hour, minute, second, millisecond );
}
explicit LocalTimeOnly( time_t time, int millisecond = 0 )
: DateTime( fromLocalTimeT (time, millisecond) )
{
clearDate();
}
LocalTimeOnly( const tm* time, int millisecond = 0 )
: DateTime( fromTm (*time, millisecond) )
{
clearDate();
}
/// Set to the current time.
void setCurrent()
{
DateTime d = nowLocal();
m_time = d.m_time;
}
};
/// Date only represented in UTC.
class UtcDate : public DateTime
{
public:
/// Defaults to the current date
UtcDate()
{
setCurrent();
}
UtcDate( const DateTime& val )
: DateTime( val )
{
clearTime();
}
UtcDate( int date, int month, int year )
: DateTime(year, month, date, 0, 0, 0, 0) {}
UtcDate( int sec )
: DateTime( sec / DateTime::SECONDS_PER_DAY, 0 ) {}
UtcDate( const tm* time )
: DateTime( fromTm (*time) )
{
clearTime();
}
/// Set to the current time.
void setCurrent()
{
DateTime d = nowUtc();
m_date = d.m_date;
}
};
/// Date only represented in local time.
class LocalDate : public DateTime
{
public:
/// Defaults to the current date
LocalDate()
{
setCurrent();
}
LocalDate( const DateTime& val )
: DateTime( val )
{
clearTime();
}
LocalDate( int date, int month, int year )
: DateTime(year, month, date, 0, 0, 0, 0) {}
LocalDate( int sec )
: DateTime( sec / DateTime::SECONDS_PER_DAY, 0 ) {}
LocalDate( const tm* time )
: DateTime( fromTm (*time) )
{
clearTime();
}
/// Set to the current time.
void setCurrent()
{
DateTime d = nowLocal();
m_date = d.m_date;
}
};
/*! @} */
typedef UtcDate UtcDateOnly;
typedef std::string STRING;
typedef char CHAR;
typedef double PRICE;
typedef int INT;
typedef double AMT;
typedef double QTY;
typedef std::string CURRENCY;
typedef std::string MULTIPLEVALUESTRING;
typedef std::string MULTIPLESTRINGVALUE;
typedef std::string MULTIPLECHARVALUE;
typedef std::string EXCHANGE;
typedef UtcTimeStamp UTCTIMESTAMP;
typedef bool BOOLEAN;
typedef std::string LOCALMKTDATE;
typedef std::string DATA;
typedef double FLOAT;
typedef double PRICEOFFSET;
typedef std::string MONTHYEAR;
typedef std::string DAYOFMONTH;
typedef UtcDate UTCDATE;
typedef UtcDateOnly UTCDATEONLY;
typedef UtcTimeOnly UTCTIMEONLY;
typedef int NUMINGROUP;
typedef double PERCENTAGE;
typedef int SEQNUM;
typedef int LENGTH;
typedef std::string COUNTRY;
typedef std::string TZTIMEONLY;
typedef std::string TZTIMESTAMP;
typedef std::string XMLDATA;
typedef std::string LANGUAGE;
namespace TYPE
{
enum Type
{
Unknown,
String,
Char,
Price,
Int,
Amt,
Qty,
Currency,
MultipleValueString,
MultipleStringValue,
MultipleCharValue,
Exchange,
UtcTimeStamp,
Boolean,
LocalMktDate,
Data,
Float,
PriceOffset,
MonthYear,
DayOfMonth,
UtcDate,
UtcDateOnly = UtcDate,
UtcTimeOnly,
NumInGroup,
Percentage,
SeqNum,
Length,
Country,
TzTimeOnly,
TzTimeStamp,
XmlData,
Language
};
}
}
#endif //FIX_FIELDTYPES_H
+31
View File
@@ -0,0 +1,31 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_FIELDS_BASE_H
#define FIX_FIELDS_BASE_H
#include "FixFields.h"
#include "Field.h"
#undef Yield
#endif //FIX_FIELDS_BASE_H
+112
View File
@@ -0,0 +1,112 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_FILELOG_H
#define FIX_FILELOG_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Log.h"
#include "SessionSettings.h"
#include <fstream>
namespace FIX
{
/**
* Creates a file based implementation of Log
*
* This stores all log events into flat files
*/
class FileLogFactory : public LogFactory
{
public:
FileLogFactory( const SessionSettings& settings )
: m_settings( settings ), m_globalLog(0), m_globalLogCount(0) {};
FileLogFactory( const std::string& path )
: m_path( path ), m_backupPath( path ), m_globalLog(0), m_globalLogCount(0) {};
FileLogFactory( const std::string& path, const std::string& backupPath )
: m_path( path ), m_backupPath( backupPath ), m_globalLog(0), m_globalLogCount(0) {};
public:
Log* create();
Log* create( const SessionID& );
void destroy( Log* log );
private:
std::string m_path;
std::string m_backupPath;
SessionSettings m_settings;
Log* m_globalLog;
int m_globalLogCount;
};
/**
* File based implementation of Log
*
* Two files are created by this implementation. One for messages,
* and one for events.
*
*/
class FileLog : public Log
{
public:
FileLog( const std::string& path );
FileLog( const std::string& path, const std::string& backupPath );
FileLog( const std::string& path, const SessionID& sessionID );
FileLog( const std::string& path, const std::string& backupPath, const SessionID& sessionID );
virtual ~FileLog();
void clear();
void backup();
void onIncoming( const std::string& value )
{ m_messages << UtcTimeStampConvertor::convert(UtcTimeStamp(), m_millisecondsInTimeStamp) << " : " << value << std::endl; }
void onOutgoing( const std::string& value )
{ m_messages << UtcTimeStampConvertor::convert(UtcTimeStamp(), m_millisecondsInTimeStamp) << " : " << value << std::endl; }
void onEvent( const std::string& value )
{
UtcTimeStamp now;
m_event << UtcTimeStampConvertor::convert( now, m_millisecondsInTimeStamp )
<< " : " << value << std::endl;
}
bool getMillisecondsInTimeStamp() const
{ return m_millisecondsInTimeStamp; }
void setMillisecondsInTimeStamp ( bool value )
{ m_millisecondsInTimeStamp = value; }
private:
std::string generatePrefix( const SessionID& sessionID );
void init( std::string path, std::string backupPath, const std::string& prefix );
std::ofstream m_messages;
std::ofstream m_event;
std::string m_messagesFileName;
std::string m_eventFileName;
std::string m_fullPrefix;
std::string m_fullBackupPrefix;
bool m_millisecondsInTimeStamp;
};
}
#endif //FIX_LOG_H
+129
View File
@@ -0,0 +1,129 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_FILESTORE_H
#define FIX_FILESTORE_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "MessageStore.h"
#include "SessionSettings.h"
#include <fstream>
#include <string>
namespace FIX
{
class Session;
/// Creates a file based implementation of MessageStore.
class FileStoreFactory : public MessageStoreFactory
{
public:
FileStoreFactory( const SessionSettings& settings )
: m_settings( settings ) {};
FileStoreFactory( const std::string& path )
: m_path( path ) {};
MessageStore* create( const SessionID& );
void destroy( MessageStore* );
private:
std::string m_path;
SessionSettings m_settings;
};
/*! @} */
/**
* File based implementation of MessageStore.
*
* Four files are created by this implementation. One for storing outgoing
* messages, one for indexing message locations, one for storing sequence numbers,
* and one for storing the session creation time.
*
* The formats of the files are:<br>
* &nbsp;&nbsp;
* [path]+[BeginString]-[SenderCompID]-[TargetCompID].body<br>
* &nbsp;&nbsp;
* [path]+[BeginString]-[SenderCompID]-[TargetCompID].header<br>
* &nbsp;&nbsp;
* [path]+[BeginString]-[SenderCompID]-[TargetCompID].seqnums<br>
* &nbsp;&nbsp;
* [path]+[BeginString]-[SenderCompID]-[TargetCompID].session<br>
*
*
* The messages file is a pure stream of %FIX messages.<br><br>
* The sequence number file is in the format of<br>
* &nbsp;&nbsp;
* [SenderMsgSeqNum] : [TargetMsgSeqNum]<br><br>
* The session file is a UTC timestamp in the format of<br>
* &nbsp;&nbsp;
* YYYYMMDD-HH:MM:SS
*/
class FileStore : public MessageStore
{
public:
FileStore( std::string, const SessionID& s );
virtual ~FileStore();
bool set( int, const std::string& ) throw ( IOException );
void get( int, int, std::vector < std::string > & ) const throw ( IOException );
int getNextSenderMsgSeqNum() const throw ( IOException );
int getNextTargetMsgSeqNum() const throw ( IOException );
void setNextSenderMsgSeqNum( int value ) throw ( IOException );
void setNextTargetMsgSeqNum( int value ) throw ( IOException );
void incrNextSenderMsgSeqNum() throw ( IOException );
void incrNextTargetMsgSeqNum() throw ( IOException );
UtcTimeStamp getCreationTime() const throw ( IOException );
void reset() throw ( IOException );
void refresh() throw ( IOException );
private:
typedef std::pair < int, int > OffsetSize;
typedef std::map < int, OffsetSize > NumToOffset;
void open( bool deleteFile );
void populateCache();
bool readFromFile( int offset, int size, std::string& msg );
void setSeqNum();
void setSession();
bool get( int, std::string& ) const throw ( IOException );
MemoryStore m_cache;
NumToOffset m_offsets;
std::string m_msgFileName;
std::string m_headerFileName;
std::string m_seqNumsFileName;
std::string m_sessionFileName;
FILE* m_msgFile;
FILE* m_headerFile;
FILE* m_seqNumsFile;
FILE* m_sessionFile;
};
}
#endif //FIX_FILESTORE_H
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+188
View File
@@ -0,0 +1,188 @@
// FlexLexer.h -- define interfaces for lexical analyzer classes generated
// by flex
// Copyright (c) 1993 The Regents of the University of California.
// All rights reserved.
//
// This code is derived from software contributed to Berkeley by
// Kent Williams and Tom Epperly.
//
// Redistribution and use in source and binary forms with or without
// modification are permitted provided that: (1) source distributions retain
// this entire copyright notice and comment, and (2) distributions including
// binaries display the following acknowledgement: ``This product includes
// software developed by the University of California, Berkeley and its
// contributors'' in the documentation or other materials provided with the
// distribution and in all advertising materials mentioning features or use
// of this software. Neither the name of the University nor the names of
// its contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
// This file defines FlexLexer, an abstract class which specifies the
// external interface provided to flex C++ lexer objects, and yyFlexLexer,
// which defines a particular lexer class.
//
// If you want to create multiple lexer classes, you use the -P flag
// to rename each yyFlexLexer to some other xxFlexLexer. You then
// include <FlexLexer.h> in your other sources once per lexer class:
//
//#undef yyFlexLexer
//#define yyFlexLexer xxFlexLexer
//#include <FlexLexer.h>
//
//#undef yyFlexLexer
//#define yyFlexLexer zzFlexLexer
//#include <FlexLexer.h>
//...
#ifndef __FLEX_LEXER_H
// Never included before - need to define base class.
#define __FLEX_LEXER_H
#include <iostream>
extern "C++"
{
struct yy_buffer_state;
typedef int yy_state_type;
class FlexLexer
{
public:
virtual ~FlexLexer() { }
const char* YYText() { return yytext; }
int YYLeng() { return yyleng; }
virtual void
yy_switch_to_buffer( struct yy_buffer_state* new_buffer ) = 0;
virtual struct yy_buffer_state*
yy_create_buffer( std::istream* s, int size ) = 0;
virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0;
virtual void yyrestart( std::istream* s ) = 0;
virtual int yylex() = 0;
// Call yylex with new input/output sources.
int yylex( std::istream* new_in, std::ostream* new_out = 0 )
{
switch_streams( new_in, new_out );
return yylex();
}
// Switch to new input/output streams. A nil stream pointer
// indicates "keep the current one".
virtual void switch_streams( std::istream* new_in = 0,
std::ostream* new_out = 0 ) = 0;
int lineno() const{ return yylineno; }
int debug() const{ return yy_flex_debug; }
void set_debug( int flag ) { yy_flex_debug = flag; }
protected:
char* yytext;
int yyleng;
int yylineno; // only maintained if you use %option yylineno
int yy_flex_debug; // only has effect with -d or "%option debug"
}
;
}
#endif
#if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce)
// Either this is the first time through (yyFlexLexerOnce not defined),
// or this is a repeated include to define a different flavor of
// yyFlexLexer, as discussed in the flex man page.
#define yyFlexLexerOnce
class yyFlexLexer : public FlexLexer
{
public:
// arg_yyin and arg_yyout default to the cin and cout, but we
// only make that assignment when initializing in yylex().
yyFlexLexer( std::istream* arg_yyin = 0, std::ostream* arg_yyout = 0 );
virtual ~yyFlexLexer();
void yy_switch_to_buffer( struct yy_buffer_state* new_buffer );
struct yy_buffer_state* yy_create_buffer( std::istream* s, int size );
void yy_delete_buffer( struct yy_buffer_state* b );
void yyrestart( std::istream* s );
virtual int yylex();
virtual void switch_streams( std::istream* new_in, std::ostream* new_out );
protected:
virtual int LexerInput( char* buf, int max_size );
virtual void LexerOutput( const char* buf, int size );
virtual void LexerError( const char* msg );
void yyunput( int c, char* buf_ptr );
int yyinput();
void yy_load_buffer_state();
void yy_init_buffer( struct yy_buffer_state* b, std::istream* s );
void yy_flush_buffer( struct yy_buffer_state* b );
int yy_start_stack_ptr;
int yy_start_stack_depth;
int* yy_start_stack;
void yy_push_state( int new_state );
void yy_pop_state();
int yy_top_state();
yy_state_type yy_get_previous_state();
yy_state_type yy_try_NUL_trans( yy_state_type current_state );
int yy_get_next_buffer();
std::istream* yyin; // input source for default LexerInput
std::ostream* yyout; // output sink for default LexerOutput
struct yy_buffer_state* yy_current_buffer;
// yy_hold_char holds the character lost when yytext is formed.
char yy_hold_char;
// Number of characters read into yy_ch_buf.
int yy_n_chars;
// Points to current character in buffer.
char* yy_c_buf_p;
int yy_init; // whether we need to initialize
int yy_start; // start state number
// Flag which is used to allow yywrap()'s to do buffer switches
// instead of setting up a fresh yyin. A bit of a hack ...
int yy_did_buffer_switch_on_eof;
// The following are not always needed, but may be depending
// on use of certain flex features (like REJECT or yymore()).
yy_state_type yy_last_accepting_state;
char* yy_last_accepting_cpos;
yy_state_type* yy_state_buf;
yy_state_type* yy_state_ptr;
char* yy_full_match;
int* yy_full_state;
int yy_full_lp;
int yy_lp;
int yy_looking_for_trail_begin;
int yy_more_flag;
int yy_more_len;
int yy_more_offset;
int yy_prev_more_offset;
};
#endif
+73
View File
@@ -0,0 +1,73 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_GROUP
#define FIX_GROUP
#ifdef _MSC_VER
#pragma warning( disable: 4786 )
#endif
#include "FieldMap.h"
#include "Fields.h"
#include <vector>
namespace FIX
{
/**
* Base class for all %FIX repeating groups.
*
* A group consists of a count field, deliminator, and a sorting order.
*/
class Group : public FieldMap
{
public:
Group( int field, int delim )
: FieldMap( message_order( delim, 0 ) ),
m_field( field ), m_delim( delim ) {}
Group( int field, int delim, const int order[] )
: FieldMap( order ), m_field( field ), m_delim( delim ) {}
Group( int field, int delim, const message_order& order )
: FieldMap( order ), m_field( field ), m_delim( delim ) {}
Group( const Group& copy )
: FieldMap( copy ), m_field( copy.m_field ), m_delim( copy.m_delim ) {}
int field() const { return m_field; }
int delim() const { return m_delim; }
void addGroup( const Group& group );
void replaceGroup( unsigned num, const Group& group );
Group& getGroup( unsigned num, Group& group ) const throw( FieldNotFound );
void removeGroup( unsigned num, const Group& group );
void removeGroup( const Group& group );
bool hasGroup( const Group& group );
bool hasGroup( unsigned num, const Group& group );
private:
int m_field;
int m_delim;
};
}
#endif //FIX_GROUP
+186
View File
@@ -0,0 +1,186 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef HTML_BUILDER_H
#define HTML_BUILDER_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include <sstream>
namespace HTML
{
class TAG
{
public:
TAG( const std::string& tag, std::ostream& stream )
: m_tag( tag ), m_stream( stream )
{
m_stream << "<" << m_tag;
}
virtual ~TAG()
{
m_stream << m_value.str();
m_stream << "</" << m_tag << ">";
}
TAG& text()
{ m_stream << ">"; return *this; }
TAG& text( const std::string& value )
{ m_value << value; text(); return *this; }
TAG& text( int value )
{ m_value << value; text(); return *this; }
private:
std::string m_tag;
std::stringstream m_value;
protected:
std::ostream& m_stream;
};
class SPECIAL
{
public:
SPECIAL( const std::string& value, std::ostream& stream )
{
stream << "&" << value << ";";
}
};
class A : public TAG
{
public:
A( std::ostream& stream )
: TAG( "A", stream ) {}
A& href( const std::string& value )
{ m_stream << " href='" << value << "'"; return *this; }
};
class BODY : public TAG
{
public:
BODY( std::ostream& stream )
: TAG( "BODY", stream ) {}
};
class BR : public TAG
{
public:
BR( std::ostream& stream )
: TAG( "BR", stream ) {}
};
class CAPTION : public TAG
{
public:
CAPTION( std::ostream& stream )
: TAG( "CAPTION", stream ) {}
};
class CENTER : public TAG
{
public:
CENTER( std::ostream& stream )
: TAG( "CENTER", stream ) {}
};
class EM : public TAG
{
public:
EM( std::ostream& stream )
: TAG( "EM", stream ) {}
};
class H1 : public TAG
{
public:
H1( std::ostream& stream )
: TAG( "H1", stream ) {}
};
class H2 : public TAG
{
public:
H2( std::ostream& stream )
: TAG( "H2", stream ) {}
};
class HEAD : public TAG
{
public:
HEAD( std::ostream& stream )
: TAG( "HEAD", stream ) {}
};
class HR : public TAG
{
public:
HR( std::ostream& stream )
: TAG( "HR", stream ) {}
};
const char* NBSP = "&nbsp;";
class TABLE : public TAG
{
public:
TABLE( std::ostream& stream )
: TAG( "TABLE", stream ) {}
TABLE& border( int value )
{ m_stream << " border='" << value << "'"; return *this; }
TABLE& cellspacing( int value )
{ m_stream << " cellspacing='" << value << "'"; return *this; }
TABLE& width( int value )
{ m_stream << " width='" << value << "%'"; return *this; }
};
class TD : public TAG
{
public:
TD( std::ostream& stream )
: TAG( "TD", stream ) {}
TD& align( const std::string& value )
{ m_stream << " align='" << value << "'"; return *this; }
};
class TITLE : public TAG
{
public:
TITLE( std::ostream& stream )
: TAG( "TITLE", stream ) {}
};
class TR : public TAG
{
public:
TR( std::ostream& stream )
: TAG( "TR", stream ) {}
};
}
#endif
+78
View File
@@ -0,0 +1,78 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_HTTPCONNECTION_H
#define FIX_HTTPCONNECTION_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "HttpParser.h"
#include <stdio.h>
namespace FIX
{
class HttpMessage;
/// Encapsulates a HTTP socket file descriptor
class HttpConnection
{
public:
HttpConnection( int s );
int getSocket() const { return m_socket; }
bool read();
private:
bool readMessage( std::string& msg ) throw( SocketRecvFailed );
void processStream();
void processRequest( const HttpMessage& );
void processRoot( const HttpMessage&, std::stringstream& h, std::stringstream& b );
void processResetSessions( const HttpMessage&, std::stringstream& h, std::stringstream& b );
void processRefreshSessions( const HttpMessage&, std::stringstream& h, std::stringstream& b );
void processEnableSessions( const HttpMessage&, std::stringstream& h, std::stringstream& b );
void processDisableSessions( const HttpMessage&, std::stringstream& h, std::stringstream& b );
void processSession( const HttpMessage&, std::stringstream& h, std::stringstream& b );
void processResetSession( const HttpMessage&, std::stringstream& h, std::stringstream& b );
void processRefreshSession( const HttpMessage&, std::stringstream& h, std::stringstream& b );
void showToggle
( std::stringstream& s, const std::string& name, bool value, const std::string& url );
void showRow
( std::stringstream& s, const std::string& name, bool value, const std::string& url = "" );
void showRow
( std::stringstream& s, const std::string& name, const std::string& value, const std::string& url = "" );
void showRow
( std::stringstream& s, const std::string& name, int value, const std::string& url = "" );
bool send( const std::string& );
void disconnect( int error = 0 );
int m_socket;
char m_buffer[BUFSIZ];
HttpParser m_parser;
fd_set m_fds;
};
}
#endif
+133
View File
@@ -0,0 +1,133 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_HTTPMESSAGE
#define FIX_HTTPMESSAGE
#ifdef _MSC_VER
#pragma warning( disable: 4786 )
#endif
#include "Exceptions.h"
#include <map>
namespace FIX
{
/**
* HTTP Message that implemented GET functionality
*/
class HttpMessage
{
public:
typedef std::map<std::string, std::string> Parameters;
HttpMessage();
/// Construct a message from a string
HttpMessage( const std::string& string )
throw( InvalidMessage );
HttpMessage( const HttpMessage& copy )
{
m_root = copy.m_root;
m_parameters = copy.m_parameters;
}
public:
/// Get a string representation of the message
std::string toString() const;
/// Get a string representation without making a copy
std::string& toString( std::string& ) const;
void setString( const std::string& string )
throw( InvalidMessage );
void clear()
{
#if defined(_MSC_VER) && _MSC_VER < 1300
m_root = "";
#else
m_root.clear();
#endif
m_parameters.clear();
}
const std::string& getRootString() const
{ return m_root; }
const std::string getParameterString() const
{
std::string result;
Parameters::const_iterator i;
for( i = m_parameters.begin(); i != m_parameters.end(); ++i )
{
result += (i == m_parameters.begin()) ? "?" : "&";
result += i->first + "=" + i->second;
}
return result;
}
const Parameters& getParameters() const
{ return m_parameters; }
bool hasParameter( const std::string& key ) const
{
Parameters::const_iterator find = m_parameters.find( key );
return find != m_parameters.end();
}
const std::string& getParameter( const std::string& key ) const
throw( std::logic_error )
{
Parameters::const_iterator find = m_parameters.find( key );
if( find == m_parameters.end() )
throw std::logic_error( "Parameter " + key + " not found" );
return find->second;
}
void addParameter( const std::string& key, const std::string& value )
{
m_parameters[key] = value;
}
void removeParameter( const std::string& key )
{
m_parameters.erase( key );
}
static std::string createResponse( int error = 0, const std::string& text = "" );
private:
std::string m_root;
Parameters m_parameters;
};
/*! @} */
inline std::ostream& operator <<
( std::ostream& stream, const HttpMessage& message )
{
std::string str;
stream << message.toString( str );
return stream;
}
}
#endif //FIX_HTTPMESSAGE
+54
View File
@@ -0,0 +1,54 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_HTTPPARSER_H
#define FIX_HTTPPARSER_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Exceptions.h"
#include <iostream>
#include <string>
namespace FIX
{
/// Parses HTTP messages off an input stream.
class HttpParser
{
public:
HttpParser() {}
~HttpParser() {}
bool readHttpMessage( std::string& str )
throw ( MessageParseError );
void addToStream( const char* str, size_t len )
{ m_buffer.append( str, len ); }
void addToStream( const std::string& str )
{ m_buffer.append( str ); }
private:
std::string m_buffer;
};
}
#endif //FIX_HTTPPARSER_H
+78
View File
@@ -0,0 +1,78 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_HTTPSERVER_H
#define FIX_HTTPSERVER_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "SocketServer.h"
#include "SessionSettings.h"
#include "Exceptions.h"
#include "Mutex.h"
namespace FIX
{
/// Basic HTTP Server
class HttpServer : public SocketServer::Strategy
{
public:
HttpServer( const SessionSettings& ) throw( ConfigError );
static void startGlobal( const SessionSettings& ) throw ( ConfigError, RuntimeError );
static void stopGlobal();
void start() throw ( ConfigError, RuntimeError );
void stop();
private:
void onConfigure( const SessionSettings& ) throw ( ConfigError );
void onInitialize( const SessionSettings& ) throw ( RuntimeError );
void onStart();
bool onPoll();
void onStop();
void onConnect( SocketServer&, int, int );
void onWrite( SocketServer&, int );
bool onData( SocketServer&, int );
void onDisconnect( SocketServer&, int );
void onError( SocketServer& );
void onTimeout( SocketServer& );
static THREAD_PROC startThread( void* p );
SocketServer* m_pServer;
SessionSettings m_settings;
thread_id m_threadid;
int m_port;
bool m_stop;
static Mutex s_mutex;
static int s_count;
static HttpServer* s_pServer;
};
/*! @} */
}
#endif //FIX_HTTPSERVER_H
+149
View File
@@ -0,0 +1,149 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_INITIATOR_H
#define FIX_INITIATOR_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Application.h"
#include "MessageStore.h"
#include "Log.h"
#include "Responder.h"
#include "SessionSettings.h"
#include "Exceptions.h"
#include "Mutex.h"
#include "Session.h"
#include <set>
#include <map>
#include <string>
namespace FIX
{
class Client;
/**
* Base for classes which act as an initiator for establishing connections.
*
* Most users will not need to implement one of these. The default
* SocketInitiator implementation will be used in most cases.
*/
class Initiator
{
public:
Initiator( Application&, MessageStoreFactory&,
const SessionSettings& ) throw( ConfigError );
Initiator( Application&, MessageStoreFactory&,
const SessionSettings&, LogFactory& ) throw( ConfigError );
virtual ~Initiator();
/// Start initiator.
void start() throw ( ConfigError, RuntimeError );
/// Block on the initiator
void block() throw ( ConfigError, RuntimeError );
/// Poll the initiator
bool poll( double timeout = 0.0 ) throw ( ConfigError, RuntimeError );
/// Stop initiator.
void stop( bool force = false );
/// Check to see if any sessions are currently logged on
bool isLoggedOn();
Session* getSession( const SessionID& sessionID, Responder& );
const std::set<SessionID>& getSessions() const { return m_sessionIDs; }
Session* getSession( const SessionID& sessionID ) const;
const Dictionary* const getSessionSettings( const SessionID& sessionID ) const;
bool has( const SessionID& id )
{ return m_sessions.find( id ) != m_sessions.end(); }
bool isStopped() { return m_stop; }
public:
Application& getApplication() { return m_application; }
MessageStoreFactory& getMessageStoreFactory()
{ return m_messageStoreFactory; }
Log* getLog()
{
if( m_pLog ) return m_pLog;
return &m_nullLog;
}
protected:
void setPending( const SessionID& );
void setConnected( const SessionID& );
void setDisconnected( const SessionID& );
bool isPending( const SessionID& );
bool isConnected( const SessionID& );
bool isDisconnected( const SessionID& );
void connect();
private:
void initialize() throw ( ConfigError );
/// Implemented to configure acceptor
virtual void onConfigure( const SessionSettings& ) throw ( ConfigError ) {};
/// Implemented to initialize initiator
virtual void onInitialize( const SessionSettings& ) throw ( RuntimeError ) {};
/// Implemented to start connecting to targets.
virtual void onStart() = 0;
/// Implemented to connect and poll for events.
virtual bool onPoll( double timeout ) = 0;
/// Implemented to stop a running initiator.
virtual void onStop() = 0;
/// Implemented to connect a session to its target.
virtual void doConnect( const SessionID&, const Dictionary& ) = 0;
static THREAD_PROC startThread( void* p );
typedef std::set < SessionID > SessionIDs;
typedef std::map < SessionID, int > SessionState;
typedef std::map < SessionID, Session* > Sessions;
Sessions m_sessions;
SessionIDs m_sessionIDs;
SessionIDs m_pending;
SessionIDs m_connected;
SessionIDs m_disconnected;
SessionState m_sessionState;
thread_id m_threadid;
Application& m_application;
MessageStoreFactory& m_messageStoreFactory;
SessionSettings m_settings;
LogFactory* m_pLogFactory;
Log* m_pLog;
NullLog m_nullLog;
bool m_firstPoll;
bool m_stop;
Mutex m_mutex;
};
/*! @} */
}
#endif // FIX_INITIATOR_H
+179
View File
@@ -0,0 +1,179 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_LOG_H
#define FIX_LOG_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Message.h"
#include "Mutex.h"
#include "SessionSettings.h"
#include <map>
#include <vector>
namespace FIX
{
class Log;
/**
* This interface must be implemented to create a Log.
*/
class LogFactory
{
public:
virtual ~LogFactory() {}
virtual Log* create() = 0;
virtual Log* create( const SessionID& ) = 0;
virtual void destroy( Log* ) = 0;
};
/**
* Creates a screen based implementation of Log.
*
* This displays all log events onto the standard output
*/
class ScreenLogFactory : public LogFactory
{
public:
ScreenLogFactory( const SessionSettings& settings )
: m_useSettings( true ), m_settings( settings ) {};
ScreenLogFactory( bool incoming, bool outgoing, bool event )
: m_incoming( incoming ), m_outgoing( outgoing ), m_event( event ), m_useSettings( false ) {}
Log* create();
Log* create( const SessionID& );
void destroy( Log* log );
private:
void init( const Dictionary& settings, bool& incoming, bool& outgoing, bool& event );
bool m_incoming;
bool m_outgoing;
bool m_event;
bool m_useSettings;
SessionSettings m_settings;
};
/**
* This interface must be implemented to log messages and events
*/
class Log
{
public:
virtual ~Log() {}
virtual void clear() = 0;
virtual void backup() = 0;
virtual void onIncoming( const std::string& ) = 0;
virtual void onOutgoing( const std::string& ) = 0;
virtual void onEvent( const std::string& ) = 0;
};
/*! @} */
/**
* Null implementation of Log
*
* This is only for internal use. Used when no log factory is
* passed to the initiator or acceptor.
*/
class NullLog : public Log
{
public:
void clear() {}
void backup() {}
void onIncoming( const std::string& ) {}
void onOutgoing( const std::string& ) {}
void onEvent( const std::string& ) {}
};
/**
* Screen based implementation of Log.
*
* This will display all log information onto the standard output
*/
class ScreenLog : public Log
{
public:
ScreenLog( bool incoming, bool outgoing, bool event )
: m_prefix( "GLOBAL" ),
m_incoming( incoming ), m_outgoing( outgoing ), m_event( event ), m_millisecondsInTimeStamp( true ) {}
ScreenLog( const SessionID& sessionID,
bool incoming, bool outgoing, bool event )
: m_prefix( sessionID.toString() ),
m_incoming( incoming ), m_outgoing( outgoing ), m_event( event ), m_millisecondsInTimeStamp( true ) {}
void clear() {}
void backup() {}
void onIncoming( const std::string& value )
{
if ( !m_incoming ) return ;
Locker l( s_mutex );
m_time.setCurrent();
std::cout << "<" << UtcTimeStampConvertor::convert(m_time, m_millisecondsInTimeStamp)
<< ", " << m_prefix
<< ", " << "incoming>" << std::endl
<< " (" << value << ")" << std::endl;
}
void onOutgoing( const std::string& value )
{
if ( !m_outgoing ) return ;
Locker l( s_mutex );
m_time.setCurrent();
std::cout << "<" << UtcTimeStampConvertor::convert(m_time, m_millisecondsInTimeStamp)
<< ", " << m_prefix
<< ", " << "outgoing>" << std::endl
<< " (" << value << ")" << std::endl;
}
void onEvent( const std::string& value )
{
if ( !m_event ) return ;
Locker l( s_mutex );
m_time.setCurrent();
std::cout << "<" << UtcTimeStampConvertor::convert(m_time, m_millisecondsInTimeStamp)
<< ", " << m_prefix
<< ", " << "event>" << std::endl
<< " (" << value << ")" << std::endl;
}
bool getMillisecondsInTimeStamp() const
{ return m_millisecondsInTimeStamp; }
void setMillisecondsInTimeStamp ( bool value )
{ m_millisecondsInTimeStamp = value; }
private:
std::string m_prefix;
UtcTimeStamp m_time;
bool m_incoming;
bool m_outgoing;
bool m_event;
static Mutex s_mutex;
bool m_millisecondsInTimeStamp;
};
}
#endif //FIX_LOG_H
+370
View File
@@ -0,0 +1,370 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_MESSAGE
#define FIX_MESSAGE
#ifdef _MSC_VER
#pragma warning( disable: 4786 )
#endif
#include "FieldMap.h"
#include "Fields.h"
#include "Group.h"
#include "SessionID.h"
#include "DataDictionary.h"
#include "Values.h"
#include <vector>
#include <memory>
namespace FIX
{
static int const headerOrder[] =
{
FIELD::BeginString,
FIELD::BodyLength,
FIELD::MsgType
};
class Header : public FieldMap
{
public:
Header() : FieldMap(message_order( message_order::header ) )
{}
};
class Trailer : public FieldMap
{
public:
Trailer() : FieldMap(message_order( message_order::trailer ) )
{}
};
/**
* Base class for all %FIX messages.
*
* A message consists of three field maps. One for the header, the body,
* and the trailer.
*/
class Message : public FieldMap
{
friend class DataDictionary;
friend class Session;
enum field_type { header, body, trailer };
public:
Message();
/// Construct a message from a string
Message( const std::string& string, bool validate = true )
throw( InvalidMessage );
/// Construct a message from a string using a data dictionary
Message( const std::string& string, const FIX::DataDictionary& dataDictionary,
bool validate = true )
throw( InvalidMessage );
/// Construct a message from a string using a session and application data dictionary
Message( const std::string& string, const FIX::DataDictionary& sessionDataDictionary,
const FIX::DataDictionary& applicationDataDictionary, bool validate = true )
throw( InvalidMessage );
Message( const Message& copy )
: FieldMap( copy )
{
m_header = copy.m_header;
m_trailer = copy.m_trailer;
m_validStructure = copy.m_validStructure;
m_field = copy.m_field;
}
/// Set global data dictionary for encoding messages into XML
static bool InitializeXML( const std::string& string );
void addGroup( const FIX::Group& group )
{ FieldMap::addGroup( group.field(), group ); }
void replaceGroup( unsigned num, const FIX::Group& group )
{ FieldMap::replaceGroup( num, group.field(), group ); }
Group& getGroup( unsigned num, FIX::Group& group ) const throw( FieldNotFound )
{ group.clear();
return static_cast < Group& >
( FieldMap::getGroup( num, group.field(), group ) );
}
void removeGroup( unsigned num, const FIX::Group& group )
{ FieldMap::removeGroup( num, group.field() ); }
void removeGroup( const FIX::Group& group )
{ FieldMap::removeGroup( group.field() ); }
bool hasGroup( const FIX::Group& group ) const
{ return FieldMap::hasGroup( group.field() ); }
bool hasGroup( unsigned num, const FIX::Group& group ) const
{ return FieldMap::hasGroup( num, group.field() ); }
protected:
// Constructor for derived classes
Message( const BeginString& beginString, const MsgType& msgType )
: m_validStructure( true )
{
m_header.setField( beginString );
m_header.setField( msgType );
}
public:
/// Get a string representation of the message
std::string toString( int beginStringField = FIELD::BeginString,
int bodyLengthField = FIELD::BodyLength,
int checkSumField = FIELD::CheckSum ) const;
/// Get a string representation without making a copy
std::string& toString( std::string&,
int beginStringField = FIELD::BeginString,
int bodyLengthField = FIELD::BodyLength,
int checkSumField = FIELD::CheckSum ) const;
/// Get a XML representation of the message
std::string toXML() const;
/// Get a XML representation without making a copy
std::string& toXML( std::string& ) const;
/**
* Add header informations depending on a source message.
* This can be used to add routing informations like OnBehalfOfCompID
* and DeliverToCompID to a message.
*/
void reverseRoute( const Header& );
/**
* Set a message based on a string representation
* This will fill in the fields on the message by parsing out the string
* that is passed in. It will return true on success and false
* on failure.
*/
void setString( const std::string& string )
throw( InvalidMessage )
{ setString(string, true); }
void setString( const std::string& string, bool validate )
throw( InvalidMessage )
{ setString(string, validate, 0); }
void setString( const std::string& string,
bool validate,
const FIX::DataDictionary* pDataDictionary )
throw( InvalidMessage )
{ setString(string, validate, pDataDictionary, pDataDictionary); }
void setString( const std::string& string,
bool validate,
const FIX::DataDictionary* pSessionDataDictionary,
const FIX::DataDictionary* pApplicationDataDictionary )
throw( InvalidMessage );
void setGroup( const std::string& msg, const FieldBase& field,
const std::string& string, std::string::size_type& pos,
FieldMap& map, const DataDictionary& dataDictionary );
/**
* Set a messages header from a string
* This is an optimization that can be used to get useful information
* from the header of a FIX string without parsing the whole thing.
*/
bool setStringHeader( const std::string& string );
/// Getter for the message header
const Header& getHeader() const { return m_header; }
/// Mutable getter for the message header
Header& getHeader() { return m_header; }
/// Getter for the message trailer
const Trailer& getTrailer() const { return m_trailer; }
/// Mutable getter for the message trailer
Trailer& getTrailer() { return m_trailer; }
bool hasValidStructure(int& field) const
{ field = m_field;
return m_validStructure;
}
int bodyLength( int beginStringField = FIELD::BeginString,
int bodyLengthField = FIELD::BodyLength,
int checkSumField = FIELD::CheckSum ) const
{ return m_header.calculateLength(beginStringField, bodyLengthField, checkSumField)
+ calculateLength(beginStringField, bodyLengthField, checkSumField)
+ m_trailer.calculateLength(beginStringField, bodyLengthField, checkSumField);
}
int checkSum( int checkSumField = FIELD::CheckSum ) const
{ return ( m_header.calculateTotal(checkSumField)
+ calculateTotal(checkSumField)
+ m_trailer.calculateTotal(checkSumField) ) % 256;
}
bool isAdmin() const
{
if( m_header.isSetField(FIELD::MsgType) )
{
const MsgType& msgType = FIELD_GET_REF( m_header, MsgType );
return isAdminMsgType( msgType );
}
return false;
}
bool isApp() const
{
if( m_header.isSetField(FIELD::MsgType) )
{
const MsgType& msgType = FIELD_GET_REF( m_header, MsgType );
return !isAdminMsgType( msgType );
}
return false;
}
bool isEmpty()
{ return m_header.isEmpty() && FieldMap::isEmpty() && m_trailer.isEmpty(); }
void clear()
{
m_field = 0;
m_header.clear();
FieldMap::clear();
m_trailer.clear();
}
static bool isAdminMsgType( const MsgType& msgType )
{ if ( msgType.getValue().length() != 1 ) return false;
return strchr
( "0A12345",
msgType.getValue().c_str() [ 0 ] ) != 0;
}
static ApplVerID toApplVerID(const BeginString& value)
{
if( value == BeginString_FIX40 )
return ApplVerID(ApplVerID_FIX40);
if( value == BeginString_FIX41 )
return ApplVerID(ApplVerID_FIX41);
if( value == BeginString_FIX42 )
return ApplVerID(ApplVerID_FIX42);
if( value == BeginString_FIX43 )
return ApplVerID(ApplVerID_FIX43);
if( value == BeginString_FIX44 )
return ApplVerID(ApplVerID_FIX44);
if( value == BeginString_FIX50 )
return ApplVerID(ApplVerID_FIX50);
if( value == "FIX.5.0SP1" )
return ApplVerID(ApplVerID_FIX50SP1);
if( value == "FIX.5.0SP2" )
return ApplVerID(ApplVerID_FIX50SP2);
return ApplVerID(ApplVerID(value));
}
static BeginString toBeginString( const ApplVerID& applVerID )
{
if( applVerID == ApplVerID_FIX40 )
return BeginString(BeginString_FIX40);
else if( applVerID == ApplVerID_FIX41 )
return BeginString(BeginString_FIX41);
else if( applVerID == ApplVerID_FIX42 )
return BeginString(BeginString_FIX42);
else if( applVerID == ApplVerID_FIX43 )
return BeginString(BeginString_FIX43);
else if( applVerID == ApplVerID_FIX44 )
return BeginString(BeginString_FIX44);
else if( applVerID == ApplVerID_FIX50 )
return BeginString(BeginString_FIX50);
else if( applVerID == ApplVerID_FIX50SP1 )
return BeginString(BeginString_FIX50);
else if( applVerID == ApplVerID_FIX50SP2 )
return BeginString(BeginString_FIX50);
else
return BeginString("");
}
static bool isHeaderField( int field );
static bool isHeaderField( const FieldBase& field,
const DataDictionary* pD = 0 );
static bool isTrailerField( int field );
static bool isTrailerField( const FieldBase& field,
const DataDictionary* pD = 0 );
/// Returns the session ID of the intended recipient
SessionID getSessionID( const std::string& qualifier = "" ) const
throw( FieldNotFound );
/// Sets the session ID of the intended recipient
void setSessionID( const SessionID& sessionID );
private:
FieldBase extractField(
const std::string& string, std::string::size_type& pos,
const DataDictionary* pSessionDD = 0, const DataDictionary* pAppDD = 0,
const Group* pGroup = 0);
static bool IsDataField(
int field,
const DataDictionary* pSessionDD,
const DataDictionary* pAppDD )
{
if( (pSessionDD && pSessionDD->isDataField( field )) ||
(pAppDD && pAppDD != pSessionDD && pAppDD->isDataField( field )) )
{
return true;
}
return false;
}
void validate();
std::string toXMLFields(const FieldMap& fields, int space) const;
protected:
mutable Header m_header;
mutable Trailer m_trailer;
bool m_validStructure;
int m_field;
static std::auto_ptr<DataDictionary> s_dataDictionary;
};
/*! @} */
inline std::ostream& operator <<
( std::ostream& stream, const Message& message )
{
std::string str;
stream << message.toString( str );
return stream;
}
/// Parse the type of a message from a string.
inline MsgType identifyType( const std::string& message )
throw( MessageParseError )
{
std::string::size_type pos = message.find( "\001" "35=" );
if ( pos == std::string::npos ) throw MessageParseError();
std::string::size_type startValue = pos + 4;
std::string::size_type soh = message.find_first_of( '\001', startValue );
if ( soh == std::string::npos ) throw MessageParseError();
std::string value = message.substr( startValue, soh - startValue );
return MsgType( value );
}
}
#endif //FIX_MESSAGE
+188
View File
@@ -0,0 +1,188 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_MESSAGECRACKER_H
#define FIX_MESSAGECRACKER_H
#include "fix40/MessageCracker.h"
#include "fix41/MessageCracker.h"
#include "fix42/MessageCracker.h"
#include "fix43/MessageCracker.h"
#include "fix44/MessageCracker.h"
#include "fix50/MessageCracker.h"
#include "fix50sp1/MessageCracker.h"
#include "fix50sp2/MessageCracker.h"
#include "fixt11/MessageCracker.h"
#include "Values.h"
#include "Session.h"
namespace FIX
{
/** Takes in a generic Message and produces an object that represents
* its specific version and message type.
*/
class MessageCracker
:
public FIX40::MessageCracker,
public FIX41::MessageCracker,
public FIX42::MessageCracker,
public FIX43::MessageCracker,
public FIX44::MessageCracker,
public FIX50::MessageCracker,
public FIX50SP1::MessageCracker,
public FIX50SP2::MessageCracker,
public FIXT11::MessageCracker
{
public:
void crack( const Message& message,
const SessionID& sessionID )
{
const FIX::BeginString& beginString =
FIELD_GET_REF( message.getHeader(), BeginString );
crack( message, sessionID, beginString );
}
void crack( const Message& message,
const SessionID& sessionID,
const BeginString& beginString )
{
if ( beginString == BeginString_FIX40 )
((FIX40::MessageCracker&)(*this)).crack((const FIX40::Message&) message, sessionID);
else if ( beginString == BeginString_FIX41 )
((FIX41::MessageCracker&)(*this)).crack((const FIX41::Message&) message, sessionID);
else if ( beginString == BeginString_FIX42 )
((FIX42::MessageCracker&)(*this)).crack((const FIX42::Message&) message, sessionID);
else if ( beginString == BeginString_FIX43 )
((FIX43::MessageCracker&)(*this)).crack((const FIX43::Message&) message, sessionID);
else if ( beginString == BeginString_FIX44 )
((FIX44::MessageCracker&)(*this)).crack((const FIX44::Message&) message, sessionID);
else if ( beginString == BeginString_FIXT11 )
{
if( message.isAdmin() )
{
((FIXT11::MessageCracker&)(*this)).crack((const FIXT11::Message&) message, sessionID);
}
else
{
ApplVerID applVerID;
if(!message.getHeader().getFieldIfSet(applVerID))
{
Session* pSession = Session::lookupSession( sessionID );
applVerID = pSession->getSenderDefaultApplVerID();
}
crack( message, sessionID, applVerID );
}
}
}
void crack( const Message& message,
const SessionID& sessionID,
const ApplVerID& applVerID )
{
if ( applVerID == ApplVerID_FIX40 )
((FIX40::MessageCracker&)(*this)).crack((const FIX40::Message&) message, sessionID);
if ( applVerID == ApplVerID_FIX41 )
((FIX41::MessageCracker&)(*this)).crack((const FIX41::Message&) message, sessionID);
if ( applVerID == ApplVerID_FIX42 )
((FIX42::MessageCracker&)(*this)).crack((const FIX42::Message&) message, sessionID);
if ( applVerID == ApplVerID_FIX43 )
((FIX43::MessageCracker&)(*this)).crack((const FIX43::Message&) message, sessionID);
if ( applVerID == ApplVerID_FIX44 )
((FIX44::MessageCracker&)(*this)).crack((const FIX44::Message&) message, sessionID);
if ( applVerID == ApplVerID_FIX50 )
((FIX50::MessageCracker&)(*this)).crack((const FIX50::Message&) message, sessionID);
if ( applVerID == ApplVerID_FIX50SP1 )
((FIX50SP1::MessageCracker&)(*this)).crack((const FIX50SP1::Message&) message, sessionID);
if ( applVerID == ApplVerID_FIX50SP2 )
((FIX50SP2::MessageCracker&)(*this)).crack((const FIX50SP2::Message&) message, sessionID);
}
void crack( Message& message,
const SessionID& sessionID )
{
const FIX::BeginString& beginString =
FIELD_GET_REF( message.getHeader(), BeginString );
crack( message, sessionID, beginString );
}
void crack( Message& message,
const SessionID& sessionID,
const BeginString& beginString )
{
if ( beginString == BeginString_FIX40 )
((FIX40::MessageCracker&)(*this)).crack((FIX40::Message&) message, sessionID);
else if ( beginString == BeginString_FIX41 )
((FIX41::MessageCracker&)(*this)).crack((FIX41::Message&) message, sessionID);
else if ( beginString == BeginString_FIX42 )
((FIX42::MessageCracker&)(*this)).crack((FIX42::Message&) message, sessionID);
else if ( beginString == BeginString_FIX43 )
((FIX43::MessageCracker&)(*this)).crack((FIX43::Message&) message, sessionID);
else if ( beginString == BeginString_FIX44 )
((FIX44::MessageCracker&)(*this)).crack((FIX44::Message&) message, sessionID);
else if ( beginString == BeginString_FIXT11 )
{
if( message.isAdmin() )
{
((FIXT11::MessageCracker&)(*this)).crack((FIXT11::Message&) message, sessionID);
}
else
{
ApplVerID applVerID;
if(!message.getHeader().getFieldIfSet(applVerID))
{
Session* pSession = Session::lookupSession( sessionID );
applVerID = pSession->getSenderDefaultApplVerID();
}
crack( message, sessionID, applVerID );
}
}
}
void crack( Message& message,
const SessionID& sessionID,
const ApplVerID& applVerID )
{
if ( applVerID == ApplVerID_FIX40 )
((FIX40::MessageCracker&)(*this)).crack((FIX40::Message&) message, sessionID);
if ( applVerID == ApplVerID_FIX41 )
((FIX41::MessageCracker&)(*this)).crack((FIX41::Message&) message, sessionID);
if ( applVerID == ApplVerID_FIX42 )
((FIX42::MessageCracker&)(*this)).crack((FIX42::Message&) message, sessionID);
if ( applVerID == ApplVerID_FIX43 )
((FIX43::MessageCracker&)(*this)).crack((FIX43::Message&) message, sessionID);
if ( applVerID == ApplVerID_FIX44 )
((FIX44::MessageCracker&)(*this)).crack((FIX44::Message&) message, sessionID);
if ( applVerID == ApplVerID_FIX50 )
((FIX50::MessageCracker&)(*this)).crack((FIX50::Message&) message, sessionID);
if ( applVerID == ApplVerID_FIX50SP1 )
((FIX50SP1::MessageCracker&)(*this)).crack((FIX50SP1::Message&) message, sessionID);
if ( applVerID == ApplVerID_FIX50SP2 )
((FIX50SP2::MessageCracker&)(*this)).crack((FIX50SP2::Message&) message, sessionID);
}
};
}
#endif //FIX_MESSAGECRACKER_H
+156
View File
@@ -0,0 +1,156 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_MESSAGESORTERS_H
#define FIX_MESSAGESORTERS_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "FieldNumbers.h"
#include "SharedArray.h"
#include <stdarg.h>
#include <functional>
#include <map>
namespace FIX
{
/// Sorts fields in correct header order.
struct header_order
{
static bool compare( const int x, const int y )
{
int orderedX = getOrderedPosition( x );
int orderedY = getOrderedPosition( y );
if ( orderedX && orderedY )
return orderedX < orderedY;
else
if ( orderedX )
return true;
else
if ( orderedY )
return false;
else
return x < y;
}
static int getOrderedPosition( const int field )
{
switch ( field )
{
case FIELD::BeginString: return 1;
case FIELD::BodyLength: return 2;
case FIELD::MsgType: return 3;
default: return 0;
};
}
};
/// Sorts fields in correct trailer order.
struct trailer_order
{
static bool compare( const int x, const int y )
{
if ( x == FIELD::CheckSum ) return false;
else
if ( y == FIELD::CheckSum ) return true;
else return x < y;
}
};
/// Sorts fields in correct group order
struct group_order
{
static bool compare( const int x, const int y, int* order, int largest )
{
if ( x <= largest && y <= largest )
{
int iX = order[ x ];
int iY = order[ y ];
if ( iX == 0 && iY == 0 )
return x < y;
else if ( iX == 0 )
return false;
else if ( iY == 0 )
return true;
else
return iX < iY;
}
else if ( x <= largest ) return true;
else if ( y <= largest ) return false;
else return x < y;
}
};
typedef std::less < int > normal_order;
/**
* Sorts fields in header, normal, or trailer order.
*
* Used as a dynamic sorter to create Header, Trailer, and Message
* FieldMaps while maintaining the same base type.
*/
struct message_order
{
public:
enum cmp_mode { header, trailer, normal, group };
message_order( cmp_mode mode = normal )
: m_mode( mode ), m_delim( 0 ), m_largest( 0 ) {}
message_order( int first, ... );
message_order( const int order[] );
message_order( const message_order& copy )
{ *this = copy; }
bool operator() ( const int x, const int y ) const
{
switch ( m_mode )
{
case header:
return header_order::compare( x, y );
case trailer:
return trailer_order::compare( x, y );
case group:
return group_order::compare( x, y, m_groupOrder, m_largest );
case normal: default:
return x < y;
}
}
message_order& operator=( const message_order& rhs );
operator bool() const
{ return !m_groupOrder.empty(); }
private:
void setOrder( int size, const int order[] );
cmp_mode m_mode;
int m_delim;
shared_array<int> m_groupOrder;
int m_largest;
};
}
#endif //FIX_MESSAGESORTERS_H
+174
View File
@@ -0,0 +1,174 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_MESSAGESTORE_H
#define FIX_MESSAGESTORE_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Message.h"
#include <map>
#include <vector>
#include <string>
namespace FIX
{
class MessageStore;
/**
* This interface must be implemented to create a MessageStore.
*/
class MessageStoreFactory
{
public:
virtual ~MessageStoreFactory() {}
virtual MessageStore* create( const SessionID& ) = 0;
virtual void destroy( MessageStore* ) = 0;
};
/**
* Creates a memory based implementation of MessageStore.
*
* This will lose all data on process termination. This class should only
* be used for test applications, never in production.
*/
class MemoryStoreFactory : public MessageStoreFactory
{
public:
MessageStore* create( const SessionID& );
void destroy( MessageStore* );
};
/**
* This interface must be implemented to store and retrieve messages and
* sequence numbers.
*/
class MessageStore
{
public:
virtual ~MessageStore() {}
virtual bool set( int, const std::string& )
throw ( IOException ) = 0;
virtual void get( int, int, std::vector < std::string > & ) const
throw ( IOException ) = 0;
virtual int getNextSenderMsgSeqNum() const throw ( IOException ) = 0;
virtual int getNextTargetMsgSeqNum() const throw ( IOException ) = 0;
virtual void setNextSenderMsgSeqNum( int ) throw ( IOException ) = 0;
virtual void setNextTargetMsgSeqNum( int ) throw ( IOException ) = 0;
virtual void incrNextSenderMsgSeqNum() throw ( IOException ) = 0;
virtual void incrNextTargetMsgSeqNum() throw ( IOException ) = 0;
virtual UtcTimeStamp getCreationTime() const throw ( IOException ) = 0;
virtual void reset() throw ( IOException ) = 0;
virtual void refresh() throw ( IOException ) = 0;
};
/*! @} */
/**
* Memory based implementation of MessageStore.
*
* This will lose all data on process terminition. This class should only
* be used for test applications, never in production.
*/
class MemoryStore : public MessageStore
{
public:
MemoryStore() : m_nextSenderMsgSeqNum( 1 ), m_nextTargetMsgSeqNum( 1 ) {}
bool set( int, const std::string& ) throw ( IOException );
void get( int, int, std::vector < std::string > & ) const throw ( IOException );
int getNextSenderMsgSeqNum() const throw ( IOException )
{ return m_nextSenderMsgSeqNum; }
int getNextTargetMsgSeqNum() const throw ( IOException )
{ return m_nextTargetMsgSeqNum; }
void setNextSenderMsgSeqNum( int value ) throw ( IOException )
{ m_nextSenderMsgSeqNum = value; }
void setNextTargetMsgSeqNum( int value ) throw ( IOException )
{ m_nextTargetMsgSeqNum = value; }
void incrNextSenderMsgSeqNum() throw ( IOException )
{ ++m_nextSenderMsgSeqNum; }
void incrNextTargetMsgSeqNum() throw ( IOException )
{ ++m_nextTargetMsgSeqNum; }
void setCreationTime( const UtcTimeStamp& creationTime ) throw ( IOException )
{ m_creationTime = creationTime; }
UtcTimeStamp getCreationTime() const throw ( IOException )
{ return m_creationTime; }
void reset() throw ( IOException )
{
m_nextSenderMsgSeqNum = 1; m_nextTargetMsgSeqNum = 1;
m_messages.clear(); m_creationTime.setCurrent();
}
void refresh() throw ( IOException ) {}
private:
typedef std::map < int, std::string > Messages;
Messages m_messages;
int m_nextSenderMsgSeqNum;
int m_nextTargetMsgSeqNum;
UtcTimeStamp m_creationTime;
};
class MessageStoreFactoryExceptionWrapper
{
private:
MessageStoreFactory* m_pFactory;
public:
MessageStoreFactoryExceptionWrapper( MessageStoreFactory* pFactory )
: m_pFactory( pFactory ) {}
MessageStore* create( const SessionID&, bool&, ConfigError& );
void destroy( MessageStore* );
};
class MessageStoreExceptionWrapper
{
private:
MessageStore* m_pStore;
public:
MessageStoreExceptionWrapper( MessageStore* pStore ) : m_pStore( pStore ) {}
~MessageStoreExceptionWrapper() { delete m_pStore; }
bool set( int, const std::string&, bool&, IOException& );
void get( int, int, std::vector < std::string > &, bool&, IOException& ) const;
int getNextSenderMsgSeqNum( bool&, IOException& ) const;
int getNextTargetMsgSeqNum( bool&, IOException& ) const;
void setNextSenderMsgSeqNum( int, bool&, IOException& );
void setNextTargetMsgSeqNum( int, bool&, IOException& );
void incrNextSenderMsgSeqNum( bool&, IOException& );
void incrNextTargetMsgSeqNum( bool&, IOException& );
UtcTimeStamp getCreationTime( bool&, IOException& );
void reset( bool&, IOException& );
void refresh( bool&, IOException& );
};
}
#endif //FIX_MESSAGESTORE_H
+131
View File
@@ -0,0 +1,131 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_MUTEX_H
#define FIX_MUTEX_H
#include "Utility.h"
namespace FIX
{
/// Portable implementation of a mutex.
class Mutex
{
public:
Mutex()
{
#ifdef _MSC_VER
InitializeCriticalSection( &m_mutex );
#else
m_count = 0;
m_threadID = 0;
//pthread_mutexattr_t attr;
//pthread_mutexattr_init(&attr);
//pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
//pthread_mutex_init(&m_mutex, &attr);
pthread_mutex_init( &m_mutex, 0 );
#endif
}
~Mutex()
{
#ifdef _MSC_VER
DeleteCriticalSection( &m_mutex );
#else
pthread_mutex_destroy( &m_mutex );
#endif
}
void lock()
{
#ifdef _MSC_VER
EnterCriticalSection( &m_mutex );
#else
if ( m_count && m_threadID == pthread_self() )
{ ++m_count; return ; }
pthread_mutex_lock( &m_mutex );
++m_count;
m_threadID = pthread_self();
#endif
}
void unlock()
{
#ifdef _MSC_VER
LeaveCriticalSection( &m_mutex );
#else
if ( m_count > 1 )
{ m_count--; return ; }
--m_count;
m_threadID = 0;
pthread_mutex_unlock( &m_mutex );
#endif
}
private:
#ifdef _MSC_VER
CRITICAL_SECTION m_mutex;
#else
pthread_mutex_t m_mutex;
pthread_t m_threadID;
int m_count;
#endif
};
/// Locks/Unlocks a mutex using RAII.
class Locker
{
public:
Locker( Mutex& mutex )
: m_mutex( mutex )
{
m_mutex.lock();
}
~Locker()
{
m_mutex.unlock();
}
private:
Mutex& m_mutex;
};
/// Does the opposite of the Locker to ensure mutex ends up in a locked state.
class ReverseLocker
{
public:
ReverseLocker( Mutex& mutex )
: m_mutex( mutex )
{
m_mutex.unlock();
}
~ReverseLocker()
{
m_mutex.lock();
}
private:
Mutex& m_mutex;
};
}
#endif
+194
View File
@@ -0,0 +1,194 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef HAVE_MYSQL
#error MySQLConnection.h included, but HAVE_MYSQL not defined
#endif
#ifdef HAVE_MYSQL
#ifndef FIX_MYSQLCONNECTION_H
#define FIX_MYSQLCONNECTION_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#pragma comment( lib, "libMySQL" )
#endif
#include <mysql.h>
#include <errmsg.h>
#include "DatabaseConnectionID.h"
#include "DatabaseConnectionPool.h"
#include "Mutex.h"
#undef MYSQL_PORT
namespace FIX
{
class MySQLQuery
{
public:
MySQLQuery( const std::string& query )
: m_result( 0 ), m_query( query )
{}
~MySQLQuery()
{
if( m_result )
mysql_free_result( m_result );
}
bool execute( MYSQL* pConnection )
{
int retry = 0;
do
{
if( m_result ) mysql_free_result( m_result );
int errcode = mysql_query( pConnection, m_query.c_str() );
m_result = mysql_store_result( pConnection );
if( errcode == 0 )
return true;
m_status = mysql_errno( pConnection );
m_reason = mysql_error( pConnection );
mysql_ping( pConnection );
retry++;
} while( retry <= 1 );
return success();
}
bool success()
{
return m_status == 0;
}
int rows()
{
return (int)mysql_num_rows( m_result );
}
const std::string& reason()
{
return m_reason;
}
char* getValue( int row, int column )
{
if( m_rows.empty() )
{
MYSQL_ROW row = 0;
while( (row = mysql_fetch_row( m_result )) )
m_rows.push_back(row);
}
return m_rows[row][column];
}
void throwException() throw( IOException )
{
if( !success() )
throw IOException( "Query failed [" + m_query + "] " + reason() );
}
private:
MYSQL_RES* m_result;
int m_status;
std::string m_query;
std::string m_reason;
std::vector<MYSQL_ROW> m_rows;
};
class MySQLConnection
{
public:
MySQLConnection
( const DatabaseConnectionID& id )
: m_connectionID( id )
{
connect();
}
MySQLConnection
( const std::string& database, const std::string& user,
const std::string& password, const std::string& host, short port )
: m_connectionID( database, user, password, host, port )
{
connect();
}
~MySQLConnection()
{
if( m_pConnection )
mysql_close( m_pConnection );
}
const DatabaseConnectionID& connectionID()
{
return m_connectionID;
}
bool connected()
{
Locker locker( m_mutex );
return mysql_ping( m_pConnection ) == 0;
}
bool reconnect()
{
Locker locker( m_mutex );
return mysql_ping( m_pConnection ) == 0;
}
bool execute( MySQLQuery& pQuery )
{
Locker locker( m_mutex );
return pQuery.execute( m_pConnection );
}
private:
void connect()
{
short port = m_connectionID.getPort();
m_pConnection = mysql_init( NULL );
if( !mysql_real_connect
( m_pConnection, m_connectionID.getHost().c_str(), m_connectionID.getUser().c_str(),
m_connectionID.getPassword().c_str(), m_connectionID.getDatabase().c_str(), port, 0, 0 ) )
{
if( !connected() )
throw ConfigError( std::string("Unable to connect to database [") + mysql_error(m_pConnection) + "]" );
}
#if( MYSQL_VERSION_ID > 50000 )
my_bool reconnect = 1;
mysql_options( m_pConnection, MYSQL_OPT_RECONNECT, static_cast<char*>(&reconnect) );
#endif
}
MYSQL* m_pConnection;
DatabaseConnectionID m_connectionID;
Mutex m_mutex;
};
typedef DatabaseConnectionPool<MySQLConnection>
MySQLConnectionPool;
typedef std::auto_ptr< MySQLConnectionPool >
MySQLConnectionPoolPtr;
}
#endif //FIX_MYSQLCONNECTION_H
#endif //HAVE_MYSQL
+145
View File
@@ -0,0 +1,145 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef HAVE_MYSQL
#error MySQLLog.h included, but HAVE_MYSQL not defined
#endif
#ifdef HAVE_MYSQL
#ifndef FIX_MYSQLLOG_H
#define FIX_MYSQLLOG_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#pragma comment( lib, "libMySQL" )
#endif
#include "Log.h"
#include "SessionSettings.h"
#include "MySQLConnection.h"
#include <fstream>
#include <string>
namespace FIX
{
/// MySQL based implementation of Log.
class MySQLLog : public Log
{
public:
MySQLLog( const SessionID& s, const DatabaseConnectionID& d, MySQLConnectionPool* p );
MySQLLog( const DatabaseConnectionID& d, MySQLConnectionPool* p );
MySQLLog( const SessionID& s, const std::string& database, const std::string& user,
const std::string& password, const std::string& host, short port );
MySQLLog( const std::string& database, const std::string& user,
const std::string& password, const std::string& host, short port );
~MySQLLog();
void clear();
void backup();
void setIncomingTable( const std::string& incomingTable )
{ m_incomingTable = incomingTable; }
void setOutgoingTable( const std::string& outgoingTable )
{ m_outgoingTable = outgoingTable; }
void setEventTable( const std::string& eventTable )
{ m_eventTable = eventTable; }
void onIncoming( const std::string& value )
{ insert( m_incomingTable, value ); }
void onOutgoing( const std::string& value )
{ insert( m_outgoingTable, value ); }
void onEvent( const std::string& value )
{ insert( m_eventTable, value ); }
private:
void init();
void insert( const std::string& table, const std::string value );
std::string m_incomingTable;
std::string m_outgoingTable;
std::string m_eventTable;
MySQLConnection* m_pConnection;
MySQLConnectionPool* m_pConnectionPool;
SessionID* m_pSessionID;
};
/// Creates a MySQL based implementation of Log.
class MySQLLogFactory : public LogFactory
{
public:
static const std::string DEFAULT_DATABASE;
static const std::string DEFAULT_USER;
static const std::string DEFAULT_PASSWORD;
static const std::string DEFAULT_HOST;
static const short DEFAULT_PORT;
MySQLLogFactory( const SessionSettings& settings )
: m_settings( settings ), m_useSettings( true )
{
bool poolConnections = false;
try { poolConnections = settings.get().getBool(MYSQL_LOG_USECONNECTIONPOOL); }
catch( ConfigError& ) {}
m_connectionPoolPtr = MySQLConnectionPoolPtr
( new MySQLConnectionPool(poolConnections) );
}
MySQLLogFactory( const std::string& database, const std::string& user,
const std::string& password, const std::string& host,
short port )
: m_database( database ), m_user( user ), m_password( password ), m_host( host ), m_port( port ),
m_useSettings( false )
{
m_connectionPoolPtr = MySQLConnectionPoolPtr
( new MySQLConnectionPool(false) );
}
MySQLLogFactory()
: m_database( DEFAULT_DATABASE ), m_user( DEFAULT_USER ), m_password( DEFAULT_PASSWORD ),
m_host( DEFAULT_HOST ), m_port( DEFAULT_PORT ), m_useSettings( false )
{
m_connectionPoolPtr = MySQLConnectionPoolPtr
( new MySQLConnectionPool(false) );
}
Log* create();
Log* create( const SessionID& );
void destroy( Log* );
private:
void init( const Dictionary& settings, std::string& database,
std::string& user, std::string& password,
std::string& host, short& port );
void initLog( const Dictionary& settings, MySQLLog& log );
MySQLConnectionPoolPtr m_connectionPoolPtr;
SessionSettings m_settings;
std::string m_database;
std::string m_user;
std::string m_password;
std::string m_host;
short m_port;
bool m_useSettings;
};
}
#endif //FIX_MYSQLLOG_H
#endif //HAVE_MYSQL
+142
View File
@@ -0,0 +1,142 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef HAVE_MYSQL
#error MySQLStore.h included, but HAVE_MYSQL not defined
#endif
#ifdef HAVE_MYSQL
#ifndef FIX_MYSQLSTORE_H
#define FIX_MYSQLSTORE_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#pragma comment( lib, "libMySQL" )
#endif
#include "MessageStore.h"
#include "SessionSettings.h"
#include "MySQLConnection.h"
#include <fstream>
#include <string>
namespace FIX
{
/// Creates a MySQL based implementation of MessageStore.
class MySQLStoreFactory : public MessageStoreFactory
{
public:
static const std::string DEFAULT_DATABASE;
static const std::string DEFAULT_USER;
static const std::string DEFAULT_PASSWORD;
static const std::string DEFAULT_HOST;
static const short DEFAULT_PORT;
MySQLStoreFactory( const SessionSettings& settings )
: m_settings( settings ), m_useSettings( true ), m_useDictionary( false )
{
bool poolConnections = false;
try { poolConnections = settings.get().getBool(MYSQL_STORE_USECONNECTIONPOOL); }
catch( ConfigError& ) {}
m_connectionPoolPtr = MySQLConnectionPoolPtr
( new MySQLConnectionPool(poolConnections) );
}
MySQLStoreFactory( const Dictionary& dictionary )
: m_dictionary( dictionary ), m_useSettings( false ), m_useDictionary( true )
{
m_connectionPoolPtr = MySQLConnectionPoolPtr
( new MySQLConnectionPool(false) );
}
MySQLStoreFactory( const std::string& database, const std::string& user,
const std::string& password, const std::string& host,
short port )
: m_database( database ), m_user( user ), m_password( password ), m_host( host ), m_port( port ),
m_useSettings( false ), m_useDictionary( false )
{
m_connectionPoolPtr = MySQLConnectionPoolPtr
( new MySQLConnectionPool(false) );
}
MySQLStoreFactory()
: m_database( DEFAULT_DATABASE ), m_user( DEFAULT_USER ), m_password( DEFAULT_PASSWORD ),
m_host( DEFAULT_HOST ), m_port( DEFAULT_PORT ), m_useSettings( false ), m_useDictionary( false )
{
m_connectionPoolPtr = MySQLConnectionPoolPtr
( new MySQLConnectionPool(false) );
}
MessageStore* create( const SessionID& );
void destroy( MessageStore* );
private:
MessageStore* create( const SessionID& s, const Dictionary& );
MySQLConnectionPoolPtr m_connectionPoolPtr;
SessionSettings m_settings;
Dictionary m_dictionary;
std::string m_database;
std::string m_user;
std::string m_password;
std::string m_host;
short m_port;
bool m_useSettings;
bool m_useDictionary;
};
/*! @} */
/// MySQL based implementation of MessageStore.
class MySQLStore : public MessageStore
{
public:
MySQLStore( const SessionID& s, const DatabaseConnectionID& d, MySQLConnectionPool* p );
MySQLStore( const SessionID& s, const std::string& database, const std::string& user,
const std::string& password, const std::string& host, short port );
~MySQLStore();
bool set( int, const std::string& ) throw ( IOException );
void get( int, int, std::vector < std::string > & ) const throw ( IOException );
int getNextSenderMsgSeqNum() const throw ( IOException );
int getNextTargetMsgSeqNum() const throw ( IOException );
void setNextSenderMsgSeqNum( int value ) throw ( IOException );
void setNextTargetMsgSeqNum( int value ) throw ( IOException );
void incrNextSenderMsgSeqNum() throw ( IOException );
void incrNextTargetMsgSeqNum() throw ( IOException );
UtcTimeStamp getCreationTime() const throw ( IOException );
void reset() throw ( IOException );
void refresh() throw ( IOException );
private:
void populateCache();
MemoryStore m_cache;
MySQLConnection* m_pConnection;
MySQLConnectionPool* m_pConnectionPool;
SessionID m_sessionID;
};
}
#endif //FIX_MYSQLSTORE_H
#endif //HAVE_MYSQL
+99
View File
@@ -0,0 +1,99 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_NULLSTORE_H
#define FIX_NULLSTORE_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "MessageStore.h"
#include "SessionSettings.h"
#include <string>
namespace FIX
{
class Session;
/**
* Null implementation of MessageStore.
*
* Will not actually store messages. Useful for admin-only or market
* data-only applications.
*/
class NullStoreFactory : public MessageStoreFactory
{
public:
MessageStore* create( const SessionID& );
void destroy( MessageStore* );
};
/*! @} */
/**
* Null implementation of MessageStore.
*
* Will not actually store messages. Useful for admin-only or market
* data-only applications.
*/
class NullStore : public MessageStore
{
public:
NullStore() : m_nextSenderMsgSeqNum( 1 ), m_nextTargetMsgSeqNum( 1 ) {}
bool set( int, const std::string& ) throw ( IOException );
void get( int, int, std::vector < std::string > & ) const throw ( IOException );
int getNextSenderMsgSeqNum() const throw ( IOException )
{ return m_nextSenderMsgSeqNum; }
int getNextTargetMsgSeqNum() const throw ( IOException )
{ return m_nextTargetMsgSeqNum; }
void setNextSenderMsgSeqNum( int value ) throw ( IOException )
{ m_nextSenderMsgSeqNum = value; }
void setNextTargetMsgSeqNum( int value ) throw ( IOException )
{ m_nextTargetMsgSeqNum = value; }
void incrNextSenderMsgSeqNum() throw ( IOException )
{ ++m_nextSenderMsgSeqNum; }
void incrNextTargetMsgSeqNum() throw ( IOException )
{ ++m_nextTargetMsgSeqNum; }
void setCreationTime( const UtcTimeStamp& creationTime ) throw ( IOException )
{ m_creationTime = creationTime; }
UtcTimeStamp getCreationTime() const throw ( IOException )
{ return m_creationTime; }
void reset() throw ( IOException )
{
m_nextSenderMsgSeqNum = 1; m_nextTargetMsgSeqNum = 1;
m_creationTime.setCurrent();
}
void refresh() throw ( IOException ) {}
private:
int m_nextSenderMsgSeqNum;
int m_nextTargetMsgSeqNum;
UtcTimeStamp m_creationTime;
};
}
#endif // FIX_NULLSTORE_H
+266
View File
@@ -0,0 +1,266 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef HAVE_ODBC
#error OdbcConnection.h included, but HAVE_ODBC not defined
#endif
#ifdef HAVE_ODBC
#ifndef FIX_ODBCCONNECTION_H
#define FIX_ODBCCONNECTION_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#pragma comment( lib, "Odbc32" )
#endif
#include "Utility.h"
#include <sql.h>
#include <sqlext.h>
#include <sqltypes.h>
#include <sstream>
#include "DatabaseConnectionID.h"
#include "DatabaseConnectionPool.h"
#include "Exceptions.h"
#include "Mutex.h"
namespace FIX
{
inline std::string odbcError( SQLSMALLINT statementType, SQLHANDLE handle )
{
SQLCHAR state[6];
SQLINTEGER error;
SQLCHAR text[SQL_MAX_MESSAGE_LENGTH];
SQLSMALLINT textLength;
RETCODE result = SQLGetDiagRec
( statementType, handle, 1, state, &error, text, sizeof(text), &textLength );
if( result == SQL_SUCCESS || result == SQL_SUCCESS_WITH_INFO )
return std::string( (char*)text );
return "";
}
inline bool odbcSuccess( RETCODE result )
{
return result == SQL_SUCCESS || result == SQL_SUCCESS_WITH_INFO;
}
class OdbcQuery
{
public:
OdbcQuery( const std::string& query )
: m_statement( 0 ), m_result( 0 ), m_query( query )
{}
~OdbcQuery()
{
close();
}
void close()
{
if( m_statement )
{
SQLFreeHandle( SQL_HANDLE_STMT, m_statement );
m_statement = 0;
m_result = 0;
}
}
bool execute( HDBC connection )
{
if( m_statement ) SQLFreeHandle( SQL_HANDLE_STMT, m_statement );
SQLAllocHandle( SQL_HANDLE_STMT, connection, &m_statement );
m_result = SQLExecDirect( m_statement, (SQLCHAR*)m_query.c_str(), m_query.size() );
if( success() || m_result == SQL_NO_DATA )
return true;
m_reason = odbcError( SQL_HANDLE_STMT, m_statement );
SQLFreeHandle( SQL_HANDLE_STMT, m_statement );
m_statement = 0;
return success();
}
bool success()
{
return odbcSuccess( m_result );
}
/*int rows()
{
return (int)mysql_num_rows( m_result );
}*/
const std::string& reason()
{
return m_reason;
}
bool fetch()
{
return odbcSuccess( SQLFetch(m_statement) );
}
/*char* getValue( int row, int column )
{
if( m_rows.empty() )
{
MYSQL_ROW row = 0;
while( row = mysql_fetch_row( m_result ) )
m_rows.push_back(row);
}
return m_rows[row][column];
}*/
HSTMT statement()
{
return m_statement;
}
void throwException() throw( IOException )
{
if( !success() )
throw IOException( "Query failed [" + m_query + "] " + reason() );
}
private:
HSTMT m_statement;
RETCODE m_result;
std::string m_query;
std::string m_reason;
};
class OdbcConnection
{
public:
OdbcConnection
( const DatabaseConnectionID& id )
: m_connection( 0 ), m_environment( 0 ), m_connectionID( id )
{
connect();
}
OdbcConnection
( const std::string& user, const std::string& password,
const std::string& connectionString )
: m_connection( 0 ), m_environment( 0 ), m_connectionID( "", user, password, connectionString, 0 )
{
connect();
}
~OdbcConnection()
{
if( m_connection )
{
SQLDisconnect( m_connection );
SQLFreeHandle( SQL_HANDLE_DBC, m_connection );
SQLFreeHandle( SQL_HANDLE_ENV, m_environment );
}
}
const DatabaseConnectionID& connectionID()
{
return m_connectionID;
}
bool connected()
{
Locker locker( m_mutex );
return m_connected;
}
bool reconnect()
{
Locker locker( m_mutex );
SQLDisconnect( m_connection );
SQLFreeHandle( SQL_HANDLE_DBC, m_connection );
m_connection = 0;
connect();
return true;
}
bool execute( OdbcQuery& pQuery )
{
Locker locker( m_mutex );
if( !pQuery.execute( m_connection ) )
{
reconnect();
return pQuery.execute( m_connection );
}
return true;
}
private:
void connect()
{
m_connected = false;
RETCODE result;
if(!m_environment)
{
result = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &m_environment );
if( !odbcSuccess(result) )
throw ConfigError( "Unable to allocate ODBC environment" );
result = SQLSetEnvAttr(m_environment, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
if( !odbcSuccess(result) )
throw ConfigError( "Unable to find ODBC version 3.0" );
}
result = SQLAllocHandle( SQL_HANDLE_DBC, m_environment, &m_connection );
if( !odbcSuccess(result) )
throw ConfigError( "Unable to allocate ODBC connection" );
std::stringstream connectionStream;
std::string connectionString = m_connectionID.getHost();
if( m_connectionID.getHost().find("UID=") == std::string::npos )
connectionStream << "UID=" << m_connectionID.getUser() << ";";
if( m_connectionID.getHost().find("PWD=") == std::string::npos )
connectionStream << "PWD=" << m_connectionID.getPassword() << ";";
connectionStream << m_connectionID.getHost();
connectionString = connectionStream.str();
SQLCHAR connectionStringOut[255];
result = SQLDriverConnect(
m_connection, NULL,
(SQLCHAR*)connectionString.c_str(), SQL_NTS,
connectionStringOut, 255,
0, SQL_DRIVER_NOPROMPT );
if( !odbcSuccess(result) )
{
std::string error = odbcError( SQL_HANDLE_DBC, m_connection );
throw ConfigError( error );
}
m_connected = true;
}
HENV m_environment;
HDBC m_connection;
bool m_connected;
DatabaseConnectionID m_connectionID;
Mutex m_mutex;
};
}
#endif
#endif
+117
View File
@@ -0,0 +1,117 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef HAVE_ODBC
#error OdbcLog.h included, but HAVE_ODBC not defined
#endif
#ifdef HAVE_ODBC
#ifndef FIX_ODBCLOG_H
#define FIX_ODBCLOG_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "OdbcConnection.h"
#include "Log.h"
#include "SessionSettings.h"
#include <fstream>
#include <string>
namespace FIX
{
/// ODBC based implementation of Log.
class OdbcLog : public Log
{
public:
OdbcLog( const SessionID& s, const std::string& user, const std::string& password,
const std::string& connectionString );
OdbcLog( const std::string& user, const std::string& password,
const std::string& connectionString );
~OdbcLog();
void clear();
void backup();
void setIncomingTable( const std::string& incomingTable )
{ m_incomingTable = incomingTable; }
void setOutgoingTable( const std::string& outgoingTable )
{ m_outgoingTable = outgoingTable; }
void setEventTable( const std::string& eventTable )
{ m_eventTable = eventTable; }
void onIncoming( const std::string& value )
{ insert( m_incomingTable, value ); }
void onOutgoing( const std::string& value )
{ insert( m_outgoingTable, value ); }
void onEvent( const std::string& value )
{ insert( m_eventTable, value ); }
private:
void init();
void insert( const std::string& table, const std::string value );
std::string m_incomingTable;
std::string m_outgoingTable;
std::string m_eventTable;
OdbcConnection* m_pConnection;
SessionID* m_pSessionID;
};
/// Creates a ODBC based implementation of Log.
class OdbcLogFactory : public LogFactory
{
public:
static const std::string DEFAULT_USER;
static const std::string DEFAULT_PASSWORD;
static const std::string DEFAULT_CONNECTION_STRING;
OdbcLogFactory( const SessionSettings& settings )
: m_settings( settings ), m_useSettings( true ) {}
OdbcLogFactory( const std::string& user, const std::string& password,
const std::string& connectionString );
OdbcLogFactory();
~OdbcLogFactory();
Log* create();
Log* create( const SessionID& );
void destroy( Log* );
private:
void init( const Dictionary& settings,
std::string& user, std::string& password,
std::string& connectionString );
void initLog( const Dictionary& settings, OdbcLog& log );
SessionSettings m_settings;
std::string m_user;
std::string m_password;
std::string m_connectionString;
bool m_useSettings;
};
}
#endif
#endif
+113
View File
@@ -0,0 +1,113 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef HAVE_ODBC
#error OdbcStore.h included, but HAVE_ODBC not defined
#endif
#ifdef HAVE_ODBC
#ifndef FIX_ODBCSTORE_H
#define FIX_ODBCSTORE_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "OdbcConnection.h"
#include "MessageStore.h"
#include "SessionSettings.h"
#include <fstream>
#include <string>
namespace FIX
{
/// Creates a Odbc based implementation of MessageStore.
class OdbcStoreFactory : public MessageStoreFactory
{
public:
static const std::string DEFAULT_USER;
static const std::string DEFAULT_PASSWORD;
static const std::string DEFAULT_CONNECTION_STRING;
OdbcStoreFactory( const SessionSettings& settings )
: m_settings( settings ), m_useSettings( true ), m_useDictionary( false ) {}
OdbcStoreFactory( const Dictionary& dictionary )
: m_dictionary( dictionary ), m_useSettings( false ), m_useDictionary( true ) {}
OdbcStoreFactory( const std::string& user, const std::string& password,
const std::string& connectionString )
: m_user( user ), m_password( password ), m_connectionString( connectionString ),
m_useSettings( false ), m_useDictionary( false ) {}
OdbcStoreFactory()
: m_user( DEFAULT_USER ), m_password( DEFAULT_PASSWORD ),
m_connectionString( DEFAULT_CONNECTION_STRING ), m_useSettings( false ), m_useDictionary( false ) {}
MessageStore* create( const SessionID& );
void destroy( MessageStore* );
private:
MessageStore* create( const SessionID& s, const Dictionary& );
Dictionary m_dictionary;
SessionSettings m_settings;
std::string m_user;
std::string m_password;
std::string m_connectionString;
bool m_useSettings;
bool m_useDictionary;
};
/*! @} */
/// Odbc based implementation of MessageStore.
class OdbcStore : public MessageStore
{
public:
OdbcStore( const SessionID& s, const std::string& user, const std::string& password,
const std::string& connectionString );
~OdbcStore();
bool set( int, const std::string& ) throw ( IOException );
void get( int, int, std::vector < std::string > & ) const throw ( IOException );
int getNextSenderMsgSeqNum() const throw ( IOException );
int getNextTargetMsgSeqNum() const throw ( IOException );
void setNextSenderMsgSeqNum( int value ) throw ( IOException );
void setNextTargetMsgSeqNum( int value ) throw ( IOException );
void incrNextSenderMsgSeqNum() throw ( IOException );
void incrNextTargetMsgSeqNum() throw ( IOException );
UtcTimeStamp getCreationTime() const throw ( IOException );
void reset() throw ( IOException );
void refresh() throw ( IOException );
private:
void populateCache();
OdbcConnection* m_pConnection;
MemoryStore m_cache;
SessionID m_sessionID;
};
}
#endif
#endif
@@ -0,0 +1,81 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_PUGIXMLDOMDOCUMENT_H
#define FIX_PUGIXMLDOMDOCUMENT_H
#include "DOMDocument.h"
#include "Exceptions.h"
#include "pugixml.hpp"
namespace FIX
{
/// XML attribute as represented by pugixml.
class PUGIXML_DOMAttributes : public DOMAttributes
{
public:
PUGIXML_DOMAttributes( pugi::xml_node pNode )
: m_pNode(pNode) {}
bool get( const std::string&, std::string& );
DOMAttributes::map toMap();
private:
pugi::xml_node m_pNode;
};
/// XML node as represented by pugixml.
class PUGIXML_DOMNode : public DOMNode
{
public:
PUGIXML_DOMNode( pugi::xml_node pNode )
: m_pNode(pNode) {}
~PUGIXML_DOMNode() {}
DOMNodePtr getFirstChildNode();
DOMNodePtr getNextSiblingNode();
DOMAttributesPtr getAttributes();
std::string getName();
std::string getText();
private:
pugi::xml_node m_pNode;
};
/// XML document as represented by pugixml.
class PUGIXML_DOMDocument : public DOMDocument
{
public:
PUGIXML_DOMDocument() throw( ConfigError );
~PUGIXML_DOMDocument();
bool load( std::istream& );
bool load( const std::string& );
bool xml( std::ostream& );
DOMNodePtr getNode( const std::string& );
private:
pugi::xml_document m_pDoc;
};
}
#endif
+57
View File
@@ -0,0 +1,57 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_PARSER_H
#define FIX_PARSER_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Exceptions.h"
#include <iostream>
#include <string>
namespace FIX
{
/// Parses %FIX messages off an input stream.
class Parser
{
public:
Parser() {}
~Parser() {}
bool extractLength( int& length, std::string::size_type& pos,
const std::string& buffer )
throw ( MessageParseError );
bool readFixMessage( std::string& str )
throw ( MessageParseError );
void addToStream( const char* str, size_t len )
{ m_buffer.append( str, len ); }
void addToStream( const std::string& str )
{ m_buffer.append( str ); }
private:
std::string m_buffer;
};
}
#endif //FIX_PARSER_H
@@ -0,0 +1,176 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef HAVE_POSTGRESQL
#error PostgreSQLConnection.h included, but HAVE_POSTGRESQL not defined
#endif
#ifdef HAVE_POSTGRESQL
#ifndef FIX_POSTGRESQLCONNECTION_H
#define FIX_POSTGRESQLCONNECTION_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#pragma comment( lib, "libpq" )
#endif
#include <libpq-fe.h>
#include "DatabaseConnectionID.h"
#include "DatabaseConnectionPool.h"
#include "Mutex.h"
namespace FIX
{
class PostgreSQLQuery
{
public:
PostgreSQLQuery( const std::string& query )
: m_result( 0 ), m_query( query )
{}
~PostgreSQLQuery()
{
if( m_result )
PQclear( m_result );
}
bool execute( PGconn* pConnection )
{
int retry = 0;
do
{
if( m_result ) PQclear( m_result );
m_result = PQexec( pConnection, m_query.c_str() );
m_status = PQresultStatus( m_result );
if( success() ) return true;
PQreset( pConnection );
retry++;
} while( retry <= 1 );
return success();
}
bool success()
{
return m_status == PGRES_TUPLES_OK
|| m_status == PGRES_COMMAND_OK;
}
int rows()
{
return PQntuples( m_result );
}
char* reason()
{
return PQresultErrorMessage( m_result );
}
char* getValue( int row, int column )
{
return PQgetvalue( m_result, row, column );
}
void throwException() throw( IOException )
{
if( !success() )
throw IOException( "Query failed [" + m_query + "] " );
}
private:
PGresult* m_result;
ExecStatusType m_status;
std::string m_query;
};
class PostgreSQLConnection
{
public:
PostgreSQLConnection
( const DatabaseConnectionID& id )
: m_connectionID( id )
{
connect();
}
PostgreSQLConnection
( const std::string& database, const std::string& user,
const std::string& password, const std::string& host, short port )
: m_connectionID( database, user, password, host, port )
{
connect();
}
~PostgreSQLConnection()
{
if( m_pConnection )
PQfinish( m_pConnection );
}
const DatabaseConnectionID& connectionID()
{
return m_connectionID;
}
bool connected()
{
Locker locker( m_mutex );
return PQstatus( m_pConnection ) == CONNECTION_OK;
}
bool reconnect()
{
Locker locker( m_mutex );
PQreset( m_pConnection );
return connected();
}
bool execute( PostgreSQLQuery& pQuery )
{
Locker locker( m_mutex );
return pQuery.execute( m_pConnection );
}
private:
void connect()
{
short port = m_connectionID.getPort();
m_pConnection = PQsetdbLogin
( m_connectionID.getHost().c_str(), port == 0 ? "" : IntConvertor::convert( port ).c_str(),
"", "", m_connectionID.getDatabase().c_str(), m_connectionID.getUser().c_str(), m_connectionID.getPassword().c_str() );
if( !connected() )
throw ConfigError( "Unable to connect to database" );
}
PGconn* m_pConnection;
DatabaseConnectionID m_connectionID;
Mutex m_mutex;
};
typedef DatabaseConnectionPool<PostgreSQLConnection>
PostgreSQLConnectionPool;
typedef std::auto_ptr< PostgreSQLConnectionPool >
PostgreSQLConnectionPoolPtr;
}
#endif //FIX_POSTGRESQLCONNECTION_H
#endif //HAVE_POSTGRESQL
+144
View File
@@ -0,0 +1,144 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef HAVE_POSTGRESQL
#error PostgreSQLLog.h included, but HAVE_POSTGRESQL not defined
#endif
#ifdef HAVE_POSTGRESQL
#ifndef FIX_POSTGRESQLLOG_H
#define FIX_POSTGRESQLLOG_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Log.h"
#include "SessionSettings.h"
#include "PostgreSQLConnection.h"
#include <fstream>
#include <string>
namespace FIX
{
/// PostgreSQL based implementation of Log.
class PostgreSQLLog : public Log
{
public:
PostgreSQLLog( const SessionID& s, const DatabaseConnectionID& d, PostgreSQLConnectionPool* p );
PostgreSQLLog( const DatabaseConnectionID& d, PostgreSQLConnectionPool* p );
PostgreSQLLog( const SessionID& s, const std::string& database, const std::string& user,
const std::string& password, const std::string& host, short port );
PostgreSQLLog( const std::string& database, const std::string& user,
const std::string& password, const std::string& host, short port );
~PostgreSQLLog();
void clear();
void backup();
void setIncomingTable( const std::string& incomingTable )
{ m_incomingTable = incomingTable; }
void setOutgoingTable( const std::string& outgoingTable )
{ m_outgoingTable = outgoingTable; }
void setEventTable( const std::string& eventTable )
{ m_eventTable = eventTable; }
void onIncoming( const std::string& value )
{ insert( m_incomingTable, value ); }
void onOutgoing( const std::string& value )
{ insert( m_outgoingTable, value ); }
void onEvent( const std::string& value )
{ insert( m_eventTable, value ); }
private:
void init();
void insert( const std::string& table, const std::string value );
std::string m_incomingTable;
std::string m_outgoingTable;
std::string m_eventTable;
PostgreSQLConnection* m_pConnection;
PostgreSQLConnectionPool* m_pConnectionPool;
SessionID* m_pSessionID;
};
/// Creates a MySQL based implementation of Log.
class PostgreSQLLogFactory : public LogFactory
{
public:
static const std::string DEFAULT_DATABASE;
static const std::string DEFAULT_USER;
static const std::string DEFAULT_PASSWORD;
static const std::string DEFAULT_HOST;
static const short DEFAULT_PORT;
PostgreSQLLogFactory( const SessionSettings& settings )
: m_settings( settings ), m_useSettings( true )
{
bool poolConnections = false;
try { poolConnections = settings.get().getBool(POSTGRESQL_LOG_USECONNECTIONPOOL); }
catch( ConfigError& ) {}
m_connectionPoolPtr = PostgreSQLConnectionPoolPtr
( new PostgreSQLConnectionPool(poolConnections) );
}
PostgreSQLLogFactory( const std::string& database, const std::string& user,
const std::string& password, const std::string& host,
short port )
: m_database( database ), m_user( user ), m_password( password ), m_host( host ), m_port( port ),
m_useSettings( false )
{
m_connectionPoolPtr = PostgreSQLConnectionPoolPtr
( new PostgreSQLConnectionPool(false) );
}
PostgreSQLLogFactory()
: m_database( DEFAULT_DATABASE ), m_user( DEFAULT_USER ), m_password( DEFAULT_PASSWORD ),
m_host( DEFAULT_HOST ), m_port( DEFAULT_PORT ), m_useSettings( false )
{
m_connectionPoolPtr = PostgreSQLConnectionPoolPtr
( new PostgreSQLConnectionPool(false) );
}
Log* create();
Log* create( const SessionID& );
void destroy( Log* );
private:
void init( const Dictionary& settings, std::string& database,
std::string& user, std::string& password,
std::string& host, short& port );
void initLog( const Dictionary& settings, PostgreSQLLog& log );
PostgreSQLConnectionPoolPtr m_connectionPoolPtr;
SessionSettings m_settings;
std::string m_database;
std::string m_user;
std::string m_password;
std::string m_host;
short m_port;
bool m_useSettings;
};
}
#endif //FIX_POSTGRESQLLOG_H
#endif //HAVE_POSTGRESQL
+141
View File
@@ -0,0 +1,141 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef HAVE_POSTGRESQL
#error PostgreSQLStore.h included, but HAVE_POSTGRESQL not defined
#endif
#ifdef HAVE_POSTGRESQL
#ifndef FIX_POSTGRESQLSTORE_H
#define FIX_POSTGRESQLSTORE_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "MessageStore.h"
#include "SessionSettings.h"
#include "PostgreSQLConnection.h"
#include <fstream>
#include <string>
namespace FIX
{
/// Creates a PostgreSQL based implementation of MessageStore.
class PostgreSQLStoreFactory : public MessageStoreFactory
{
public:
static const std::string DEFAULT_DATABASE;
static const std::string DEFAULT_USER;
static const std::string DEFAULT_PASSWORD;
static const std::string DEFAULT_HOST;
static const short DEFAULT_PORT;
PostgreSQLStoreFactory( const SessionSettings& settings )
: m_settings( settings ), m_useSettings( true ), m_useDictionary( false )
{
bool poolConnections = false;
try { poolConnections = settings.get().getBool(POSTGRESQL_STORE_USECONNECTIONPOOL); }
catch( ConfigError& ) {}
m_connectionPoolPtr = PostgreSQLConnectionPoolPtr
( new PostgreSQLConnectionPool(poolConnections) );
}
PostgreSQLStoreFactory( const Dictionary& dictionary )
: m_dictionary( dictionary ), m_useSettings( false ), m_useDictionary( true )
{
m_connectionPoolPtr = PostgreSQLConnectionPoolPtr
( new PostgreSQLConnectionPool(false) );
}
PostgreSQLStoreFactory( const std::string& database, const std::string& user,
const std::string& password, const std::string& host,
short port )
: m_database( database ), m_user( user ), m_password( password ), m_host( host ), m_port( port ),
m_useSettings( false ), m_useDictionary( false )
{
m_connectionPoolPtr = PostgreSQLConnectionPoolPtr
( new PostgreSQLConnectionPool(false) );
}
PostgreSQLStoreFactory()
: m_database( DEFAULT_DATABASE ), m_user( DEFAULT_USER ), m_password( DEFAULT_PASSWORD ),
m_host( DEFAULT_HOST ), m_port( DEFAULT_PORT ), m_useSettings( false ), m_useDictionary( false )
{
m_connectionPoolPtr = PostgreSQLConnectionPoolPtr
( new PostgreSQLConnectionPool(false) );
}
MessageStore* create( const SessionID& );
void destroy( MessageStore* );
private:
MessageStore* create( const SessionID& s, const Dictionary& );
PostgreSQLConnectionPoolPtr m_connectionPoolPtr;
SessionSettings m_settings;
Dictionary m_dictionary;
std::string m_database;
std::string m_user;
std::string m_password;
std::string m_host;
short m_port;
bool m_useSettings;
bool m_useDictionary;
};
/*! @} */
/// PostgreSQL based implementation of MessageStore.
class PostgreSQLStore : public MessageStore
{
public:
PostgreSQLStore( const SessionID& s, const DatabaseConnectionID& d, PostgreSQLConnectionPool* p );
PostgreSQLStore( const SessionID& s, const std::string& database, const std::string& user,
const std::string& password, const std::string& host, short port );
~PostgreSQLStore();
bool set( int, const std::string& ) throw ( IOException );
void get( int, int, std::vector < std::string > & ) const throw ( IOException );
int getNextSenderMsgSeqNum() const throw ( IOException );
int getNextTargetMsgSeqNum() const throw ( IOException );
void setNextSenderMsgSeqNum( int value ) throw ( IOException );
void setNextTargetMsgSeqNum( int value ) throw ( IOException );
void incrNextSenderMsgSeqNum() throw ( IOException );
void incrNextTargetMsgSeqNum() throw ( IOException );
UtcTimeStamp getCreationTime() const throw ( IOException );
void reset() throw ( IOException );
void refresh() throw ( IOException );
private:
void populateCache();
MemoryStore m_cache;
PostgreSQLConnection* m_pConnection;
PostgreSQLConnectionPool* m_pConnectionPool;
SessionID m_sessionID;
};
}
#endif //FIX_POSTGRESQLSTORE_H
#endif //HAVE_POSTGRESQL
+75
View File
@@ -0,0 +1,75 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_QUEUE_H
#define FIX_QUEUE_H
#include "Utility.h"
#include "Event.h"
#include "Mutex.h"
#include <queue>
namespace FIX
{
/// A thread safe monitored queue
template < typename T > class Queue
{
public:
void push( const T& value )
{
Locker locker( m_mutex );
m_queue.push( value );
signal();
}
bool pop( T& value )
{
Locker locker( m_mutex );
if ( !m_queue.size() ) return false;
value = m_queue.front();
m_queue.pop();
return true;
}
int size()
{
Locker locker( m_mutex );
return m_queue.size();
}
void wait( double s )
{
m_event.wait( s );
}
void signal()
{
m_event.signal();
}
private:
Event m_event;
Mutex m_mutex;
std::queue < T > m_queue;
};
}
#endif
+43
View File
@@ -0,0 +1,43 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_RESPONDER_H
#define FIX_RESPONDER_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include <string>
namespace FIX
{
/// Interface implements sending on and disconnecting a transport.
class Responder
{
public:
virtual ~Responder() {}
virtual bool send( const std::string& ) = 0;
virtual void disconnect() = 0;
};
}
#endif
+335
View File
@@ -0,0 +1,335 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_SESSION_H
#define FIX_SESSION_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "SessionState.h"
#include "TimeRange.h"
#include "SessionID.h"
#include "Responder.h"
#include "Fields.h"
#include "DataDictionaryProvider.h"
#include "Application.h"
#include "Mutex.h"
#include "Log.h"
#include <utility>
#include <map>
#include <queue>
namespace FIX
{
/// Maintains the state and implements the logic of a %FIX %session.
class Session
{
public:
Session( Application&, MessageStoreFactory&,
const SessionID&,
const DataDictionaryProvider&,
const TimeRange&,
int heartBtInt, LogFactory* pLogFactory );
virtual ~Session();
void logon()
{ m_state.enabled( true ); m_state.logoutReason( "" ); }
void logout( const std::string& reason = "" )
{ m_state.enabled( false ); m_state.logoutReason( reason ); }
bool isEnabled()
{ return m_state.enabled(); }
bool sentLogon() { return m_state.sentLogon(); }
bool sentLogout() { return m_state.sentLogout(); }
bool receivedLogon() { return m_state.receivedLogon(); }
bool isLoggedOn() { return receivedLogon() && sentLogon(); }
void reset() throw( IOException )
{ generateLogout(); disconnect(); m_state.reset(); }
void refresh() throw( IOException )
{ m_state.refresh(); }
void setNextSenderMsgSeqNum( int num ) throw( IOException )
{ m_state.setNextSenderMsgSeqNum( num ); }
void setNextTargetMsgSeqNum( int num ) throw( IOException )
{ m_state.setNextTargetMsgSeqNum( num ); }
const SessionID& getSessionID() const
{ return m_sessionID; }
void setDataDictionaryProvider( const DataDictionaryProvider& dataDictionaryProvider )
{ m_dataDictionaryProvider = dataDictionaryProvider; }
const DataDictionaryProvider& getDataDictionaryProvider() const
{ return m_dataDictionaryProvider; }
static bool sendToTarget( Message& message,
const std::string& qualifier = "" )
throw( SessionNotFound );
static bool sendToTarget( Message& message, const SessionID& sessionID )
throw( SessionNotFound );
static bool sendToTarget( Message&,
const SenderCompID& senderCompID,
const TargetCompID& targetCompID,
const std::string& qualifier = "" )
throw( SessionNotFound );
static bool sendToTarget( Message& message,
const std::string& senderCompID,
const std::string& targetCompID,
const std::string& qualifier = "" )
throw( SessionNotFound );
static std::set<SessionID> getSessions();
static bool doesSessionExist( const SessionID& );
static Session* lookupSession( const SessionID& );
static Session* lookupSession( const std::string&, bool reverse = false );
static bool isSessionRegistered( const SessionID& );
static Session* registerSession( const SessionID& );
static void unregisterSession( const SessionID& );
static size_t numSessions();
bool isSessionTime(const UtcTimeStamp& time)
{ return m_sessionTime.isInRange(time); }
bool isLogonTime(const UtcTimeStamp& time)
{ return m_logonTime.isInRange(time); }
bool isInitiator()
{ return m_state.initiate(); }
bool isAcceptor()
{ return !m_state.initiate(); }
const TimeRange& getLogonTime()
{ return m_logonTime; }
void setLogonTime( const TimeRange& value )
{ m_logonTime = value; }
const std::string& getSenderDefaultApplVerID()
{ return m_senderDefaultApplVerID; }
void setSenderDefaultApplVerID( const std::string& senderDefaultApplVerID )
{ m_senderDefaultApplVerID = senderDefaultApplVerID; }
const std::string& getTargetDefaultApplVerID()
{ return m_targetDefaultApplVerID; }
void setTargetDefaultApplVerID( const std::string& targetDefaultApplVerID )
{ m_targetDefaultApplVerID = targetDefaultApplVerID; }
bool getSendRedundantResendRequests()
{ return m_sendRedundantResendRequests; }
void setSendRedundantResendRequests ( bool value )
{ m_sendRedundantResendRequests = value; }
bool getCheckCompId()
{ return m_checkCompId; }
void setCheckCompId ( bool value )
{ m_checkCompId = value; }
bool getCheckLatency()
{ return m_checkLatency; }
void setCheckLatency ( bool value )
{ m_checkLatency = value; }
int getMaxLatency()
{ return m_maxLatency; }
void setMaxLatency ( int value )
{ m_maxLatency = value; }
int getLogonTimeout()
{ return m_state.logonTimeout(); }
void setLogonTimeout ( int value )
{ m_state.logonTimeout( value ); }
int getLogoutTimeout()
{ return m_state.logoutTimeout(); }
void setLogoutTimeout ( int value )
{ m_state.logoutTimeout( value ); }
bool getResetOnLogon()
{ return m_resetOnLogon; }
void setResetOnLogon ( bool value )
{ m_resetOnLogon = value; }
bool getResetOnLogout()
{ return m_resetOnLogout; }
void setResetOnLogout ( bool value )
{ m_resetOnLogout = value; }
bool getResetOnDisconnect()
{ return m_resetOnDisconnect; }
void setResetOnDisconnect( bool value )
{ m_resetOnDisconnect = value; }
bool getRefreshOnLogon()
{ return m_refreshOnLogon; }
void setRefreshOnLogon( bool value )
{ m_refreshOnLogon = value; }
bool getMillisecondsInTimeStamp()
{ return m_millisecondsInTimeStamp; }
void setMillisecondsInTimeStamp ( bool value )
{ m_millisecondsInTimeStamp = value; }
bool getPersistMessages()
{ return m_persistMessages; }
void setPersistMessages ( bool value )
{ m_persistMessages = value; }
bool getValidateLengthAndChecksum()
{ return m_validateLengthAndChecksum; }
void setValidateLengthAndChecksum ( bool value )
{ m_validateLengthAndChecksum = value; }
void setResponder( Responder* pR )
{
if( !checkSessionTime(UtcTimeStamp()) )
reset();
m_pResponder = pR;
}
bool send( Message& );
void next();
void next( const UtcTimeStamp& timeStamp );
void next( const std::string&, const UtcTimeStamp& timeStamp, bool queued = false );
void next( const Message&, const UtcTimeStamp& timeStamp, bool queued = false );
void disconnect();
int getExpectedSenderNum() { return m_state.getNextSenderMsgSeqNum(); }
int getExpectedTargetNum() { return m_state.getNextTargetMsgSeqNum(); }
Log* getLog() { return &m_state; }
const MessageStore* getStore() { return &m_state; }
private:
typedef std::map < SessionID, Session* > Sessions;
typedef std::set < SessionID > SessionIDs;
static bool addSession( Session& );
static void removeSession( Session& );
bool send( const std::string& );
bool sendRaw( Message&, int msgSeqNum = 0 );
bool resend( Message& message );
void persist( const Message&, const std::string& ) throw ( IOException );
void insertSendingTime( Header& );
void insertOrigSendingTime( Header&,
const UtcTimeStamp& when = UtcTimeStamp () );
void fill( Header& );
bool isGoodTime( const SendingTime& sendingTime )
{
if ( !m_checkLatency ) return true;
UtcTimeStamp now;
return labs( now - sendingTime ) <= m_maxLatency;
}
bool checkSessionTime( const UtcTimeStamp& timeStamp )
{
UtcTimeStamp creationTime = m_state.getCreationTime();
return m_sessionTime.isInSameRange( timeStamp, creationTime );
}
bool isTargetTooHigh( const MsgSeqNum& msgSeqNum )
{ return msgSeqNum > ( m_state.getNextTargetMsgSeqNum() ); }
bool isTargetTooLow( const MsgSeqNum& msgSeqNum )
{ return msgSeqNum < ( m_state.getNextTargetMsgSeqNum() ); }
bool isCorrectCompID( const SenderCompID& senderCompID,
const TargetCompID& targetCompID )
{
if( !m_checkCompId ) return true;
return
m_sessionID.getSenderCompID().getValue() == targetCompID.getValue()
&& m_sessionID.getTargetCompID().getValue() == senderCompID.getValue();
}
bool shouldSendReset();
bool validLogonState( const MsgType& msgType );
void fromCallback( const MsgType& msgType, const Message& msg,
const SessionID& sessionID );
void doBadTime( const Message& msg );
void doBadCompID( const Message& msg );
bool doPossDup( const Message& msg );
bool doTargetTooLow( const Message& msg );
void doTargetTooHigh( const Message& msg );
void nextQueued( const UtcTimeStamp& timeStamp );
bool nextQueued( int num, const UtcTimeStamp& timeStamp );
void nextLogon( const Message&, const UtcTimeStamp& timeStamp );
void nextHeartbeat( const Message&, const UtcTimeStamp& timeStamp );
void nextTestRequest( const Message&, const UtcTimeStamp& timeStamp );
void nextLogout( const Message&, const UtcTimeStamp& timeStamp );
void nextReject( const Message&, const UtcTimeStamp& timeStamp );
void nextSequenceReset( const Message&, const UtcTimeStamp& timeStamp );
void nextResendRequest( const Message&, const UtcTimeStamp& timeStamp );
void generateLogon();
void generateLogon( const Message& );
void generateResendRequest( const BeginString&, const MsgSeqNum& );
void generateSequenceReset( int, int );
void generateHeartbeat();
void generateHeartbeat( const Message& );
void generateTestRequest( const std::string& );
void generateReject( const Message&, int err, int field = 0 );
void generateReject( const Message&, const std::string& );
void generateBusinessReject( const Message&, int err, int field = 0 );
void generateLogout( const std::string& text = "" );
void populateRejectReason( Message&, int field, const std::string& );
void populateRejectReason( Message&, const std::string& );
bool verify( const Message& msg,
bool checkTooHigh = true, bool checkTooLow = true );
bool set( int s, const Message& m );
bool get( int s, Message& m ) const;
Application& m_application;
SessionID m_sessionID;
TimeRange m_sessionTime;
TimeRange m_logonTime;
std::string m_senderDefaultApplVerID;
std::string m_targetDefaultApplVerID;
bool m_sendRedundantResendRequests;
bool m_checkCompId;
bool m_checkLatency;
int m_maxLatency;
bool m_resetOnLogon;
bool m_resetOnLogout;
bool m_resetOnDisconnect;
bool m_refreshOnLogon;
bool m_millisecondsInTimeStamp;
bool m_persistMessages;
bool m_validateLengthAndChecksum;
SessionState m_state;
DataDictionaryProvider m_dataDictionaryProvider;
MessageStoreFactory& m_messageStoreFactory;
LogFactory* m_pLogFactory;
Responder* m_pResponder;
Mutex m_mutex;
static Sessions s_sessions;
static SessionIDs s_sessionIDs;
static Sessions s_registered;
static Mutex s_mutex;
};
}
#endif //FIX_SESSION_H
+86
View File
@@ -0,0 +1,86 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_SESSIONFACTORY_H
#define FIX_SESSIONFACTORY_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Log.h"
#include "Exceptions.h"
#include "Dictionary.h"
namespace FIX
{
class SessionID;
class Session;
class Application;
class MessageStoreFactory;
class DataDictionaryProvider;
/** Responsible for creating Session objects. This factory will use
* QuickFIX SessionID, Dictionary settings, MessageStoreFactory, and
* optional LogFactory to create all the required sessions for an
* Application.
*/
class SessionFactory
{
public:
SessionFactory( Application& application,
MessageStoreFactory& messageStoreFactory,
LogFactory* pLogFactory )
: m_application( application ),
m_messageStoreFactory( messageStoreFactory ),
m_pLogFactory( pLogFactory ) {}
~SessionFactory();
Session* create( const SessionID& sessionID,
const Dictionary& settings ) throw( ConfigError );
void destroy( Session* pSession );
private:
typedef std::map < std::string, ptr::shared_ptr<DataDictionary> > Dictionaries;
ptr::shared_ptr<DataDictionary> createDataDictionary(const SessionID& sessionID,
const Dictionary& settings,
const std::string& settingsKey) throw(ConfigError);
void processFixtDataDictionaries(const SessionID& sessionID,
const Dictionary& settings,
DataDictionaryProvider& provider) throw(ConfigError);
void processFixDataDictionary(const SessionID& sessionID,
const Dictionary& settings,
DataDictionaryProvider& provider) throw(ConfigError);
std::string toApplVerID(const std::string& value);
Application& m_application;
MessageStoreFactory& m_messageStoreFactory;
LogFactory* m_pLogFactory;
Dictionaries m_dictionaries;
};
}
#endif
+170
View File
@@ -0,0 +1,170 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_SESSIONID_H
#define FIX_SESSIONID_H
#include "Fields.h"
namespace FIX
{
/// Unique session id consists of BeginString, SenderCompID and TargetCompID.
class SessionID
{
public:
SessionID()
{
toString(m_frozenString);
}
SessionID( const std::string& beginString,
const std::string& senderCompID,
const std::string& targetCompID,
const std::string& sessionQualifier = "" )
: m_beginString( BeginString(beginString) ),
m_senderCompID( SenderCompID(senderCompID) ),
m_targetCompID( TargetCompID(targetCompID) ),
m_sessionQualifier( sessionQualifier ),
m_isFIXT(false)
{
toString(m_frozenString);
if( beginString.substr(0, 4) == "FIXT" )
m_isFIXT = true;
}
const BeginString& getBeginString() const
{ return m_beginString; }
const SenderCompID& getSenderCompID() const
{ return m_senderCompID; }
const TargetCompID& getTargetCompID() const
{ return m_targetCompID; }
const std::string& getSessionQualifier() const
{ return m_sessionQualifier; }
const bool isFIXT() const
{ return m_isFIXT; }
/// Get a string representation of the SessionID
std::string toString() const
{
return m_frozenString;
}
// Return a reference for a high-performance scenario
const std::string& toStringFrozen() const
{
return m_frozenString;
}
/// Build from string representation of SessionID
void fromString( const std::string& str )
{
std::string::size_type first =
str.find_first_of(':');
std::string::size_type second =
str.find("->");
std::string::size_type third =
str.find_last_of(':');
if( first == std::string::npos )
return;
if( second == std::string::npos )
return;
m_beginString = str.substr(0, first);
m_senderCompID = str.substr(first+1, second - first - 1);
if( first == third )
{
m_targetCompID = str.substr(second+2);
m_sessionQualifier = "";
}
else
{
m_targetCompID = str.substr(second+2, third - second - 2);
m_sessionQualifier = str.substr(third+1);
}
toString(m_frozenString);
}
/// Get a string representation without making a copy
std::string& toString( std::string& str ) const
{
str = getBeginString().getValue() + ":" +
getSenderCompID().getValue() + "->" +
getTargetCompID().getValue();
if( m_sessionQualifier.size() )
str += ":" + m_sessionQualifier;
return str;
}
friend bool operator<( const SessionID&, const SessionID& );
friend bool operator==( const SessionID&, const SessionID& );
friend bool operator!=( const SessionID&, const SessionID& );
friend std::ostream& operator<<( std::ostream&, const SessionID& );
friend std::ostream& operator>>( std::ostream&, const SessionID& );
SessionID operator~() const
{
return SessionID( m_beginString, SenderCompID( m_targetCompID ),
TargetCompID( m_senderCompID ), m_sessionQualifier );
}
private:
BeginString m_beginString;
SenderCompID m_senderCompID;
TargetCompID m_targetCompID;
std::string m_sessionQualifier;
bool m_isFIXT;
std::string m_frozenString;
};
/*! @} */
inline bool operator<( const SessionID& lhs, const SessionID& rhs )
{
return lhs.toStringFrozen() < rhs.toStringFrozen();
}
inline bool operator==( const SessionID& lhs, const SessionID& rhs )
{
return lhs.toStringFrozen() == rhs.toStringFrozen();
}
inline bool operator!=( const SessionID& lhs, const SessionID& rhs )
{
return !( lhs == rhs );
}
inline std::ostream& operator<<
( std::ostream& stream, const SessionID& sessionID )
{
stream << sessionID.toStringFrozen();
return stream;
}
inline std::istream& operator>>
( std::istream& stream, SessionID& sessionID )
{
std::string str;
stream >> str;
sessionID.fromString( str );
return stream;
}
}
#endif //FIX_SESSIONID_H
+171
View File
@@ -0,0 +1,171 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_SESSIONSETTINGS_H
#define FIX_SESSIONSETTINGS_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Dictionary.h"
#include "SessionID.h"
#include "Exceptions.h"
#include <map>
#include <set>
namespace FIX
{
const char BEGINSTRING[] = "BeginString";
const char SENDERCOMPID[] = "SenderCompID";
const char TARGETCOMPID[] = "TargetCompID";
const char SESSION_QUALIFIER[] = "SessionQualifier";
const char DEFAULT_APPLVERID[] = "DefaultApplVerID";
const char CONNECTION_TYPE[] = "ConnectionType";
const char USE_DATA_DICTIONARY[] = "UseDataDictionary";
const char SEND_RESETSEQNUMFLAG[] = "SendResetSeqNumFlag";
const char SEND_REDUNDANT_RESENDREQUESTS[] = "SendRedundantResendRequests";
const char DATA_DICTIONARY[] = "DataDictionary";
const char TRANSPORT_DATA_DICTIONARY[] = "TransportDataDictionary";
const char APP_DATA_DICTIONARY[] = "AppDataDictionary";
const char USE_LOCAL_TIME[] = "UseLocalTime";
const char START_TIME[] = "StartTime";
const char END_TIME[] = "EndTime";
const char START_DAY[] = "StartDay";
const char END_DAY[] = "EndDay";
const char LOGON_TIME[] = "LogonTime";
const char LOGOUT_TIME[] = "LogoutTime";
const char LOGON_DAY[] = "LogonDay";
const char LOGOUT_DAY[] = "LogoutDay";
const char CHECK_COMPID[] = "CheckCompID";
const char CHECK_LATENCY[] = "CheckLatency";
const char MAX_LATENCY[] = "MaxLatency";
const char HEARTBTINT[] = "HeartBtInt";
const char SOCKET_ACCEPT_PORT[] = "SocketAcceptPort";
const char SOCKET_REUSE_ADDRESS[] = "SocketReuseAddress";
const char SOCKET_CONNECT_HOST[] = "SocketConnectHost";
const char SOCKET_CONNECT_PORT[] = "SocketConnectPort";
const char SOCKET_NODELAY[] = "SocketNodelay";
const char SOCKET_SEND_BUFFER_SIZE[] = "SendBufferSize";
const char SOCKET_RECEIVE_BUFFER_SIZE[] = "ReceiveBufferSize";
const char RECONNECT_INTERVAL[] = "ReconnectInterval";
const char VALIDATE_LENGTH_AND_CHECKSUM[] = "ValidateLengthAndChecksum";
const char VALIDATE_FIELDS_OUT_OF_ORDER[] = "ValidateFieldsOutOfOrder";
const char VALIDATE_FIELDS_HAVE_VALUES[] = "ValidateFieldsHaveValues";
const char VALIDATE_USER_DEFINED_FIELDS[] = "ValidateUserDefinedFields";
const char LOGON_TIMEOUT[] = "LogonTimeout";
const char LOGOUT_TIMEOUT[] = "LogoutTimeout";
const char FILE_STORE_PATH[] = "FileStorePath";
const char MYSQL_STORE_USECONNECTIONPOOL[] = "MySQLStoreUseConnectionPool";
const char MYSQL_STORE_DATABASE[] = "MySQLStoreDatabase";
const char MYSQL_STORE_USER[] = "MySQLStoreUser";
const char MYSQL_STORE_PASSWORD[] = "MySQLStorePassword";
const char MYSQL_STORE_HOST[] = "MySQLStoreHost";
const char MYSQL_STORE_PORT[] = "MySQLStorePort";
const char POSTGRESQL_STORE_USECONNECTIONPOOL[] = "PostgreSQLStoreUseConnectionPool";
const char POSTGRESQL_STORE_DATABASE[] = "PostgreSQLStoreDatabase";
const char POSTGRESQL_STORE_USER[] = "PostgreSQLStoreUser";
const char POSTGRESQL_STORE_PASSWORD[] = "PostgreSQLStorePassword";
const char POSTGRESQL_STORE_HOST[] = "PostgreSQLStoreHost";
const char POSTGRESQL_STORE_PORT[] = "PostgreSQLStorePort";
const char ODBC_STORE_USER[] = "OdbcStoreUser";
const char ODBC_STORE_PASSWORD[] = "OdbcStorePassword";
const char ODBC_STORE_CONNECTION_STRING[] = "OdbcStoreConnectionString";
const char FILE_LOG_PATH[] = "FileLogPath";
const char FILE_LOG_BACKUP_PATH[] = "FileLogBackupPath";
const char SCREEN_LOG_SHOW_INCOMING[] = "ScreenLogShowIncoming";
const char SCREEN_LOG_SHOW_OUTGOING[] = "ScreenLogShowOutgoing";
const char SCREEN_LOG_SHOW_EVENTS[] = "ScreenLogShowEvents";
const char MYSQL_LOG_USECONNECTIONPOOL[] = "MySQLLogUseConnectionPool";
const char MYSQL_LOG_DATABASE[] = "MySQLLogDatabase";
const char MYSQL_LOG_USER[] = "MySQLLogUser";
const char MYSQL_LOG_PASSWORD[] = "MySQLLogPassword";
const char MYSQL_LOG_HOST[] = "MySQLLogHost";
const char MYSQL_LOG_PORT[] = "MySQLLogPort";
const char MYSQL_LOG_INCOMING_TABLE[] = "MySQLLogIncomingTable";
const char MYSQL_LOG_OUTGOING_TABLE[] = "MySQLLogOutgoingTable";
const char MYSQL_LOG_EVENT_TABLE[] = "MySQLLogEventTable";
const char POSTGRESQL_LOG_USECONNECTIONPOOL[] = "PostgreSQLLogUseConnectionPool";
const char POSTGRESQL_LOG_DATABASE[] = "PostgreSQLLogDatabase";
const char POSTGRESQL_LOG_USER[] = "PostgreSQLLogUser";
const char POSTGRESQL_LOG_PASSWORD[] = "PostgreSQLLogPassword";
const char POSTGRESQL_LOG_HOST[] = "PostgreSQLLogHost";
const char POSTGRESQL_LOG_PORT[] = "PostgreSQLLogPort";
const char POSTGRESQL_LOG_INCOMING_TABLE[] = "PostgreSQLLogIncomingTable";
const char POSTGRESQL_LOG_OUTGOING_TABLE[] = "PostgreSQLLogOutgoingTable";
const char POSTGRESQL_LOG_EVENT_TABLE[] = "PostgreSQLLogEventTable";
const char ODBC_LOG_USER[] = "OdbcLogUser";
const char ODBC_LOG_PASSWORD[] = "OdbcLogPassword";
const char ODBC_LOG_CONNECTION_STRING[] = "OdbcLogConnectionString";
const char ODBC_LOG_INCOMING_TABLE[] = "OdbcLogIncomingTable";
const char ODBC_LOG_OUTGOING_TABLE[] = "OdbcLogOutgoingTable";
const char ODBC_LOG_EVENT_TABLE[] = "OdbcLogEventTable";
const char RESET_ON_LOGON[] = "ResetOnLogon";
const char RESET_ON_LOGOUT[] = "ResetOnLogout";
const char RESET_ON_DISCONNECT[] = "ResetOnDisconnect";
const char REFRESH_ON_LOGON[] = "RefreshOnLogon";
const char MILLISECONDS_IN_TIMESTAMP[] = "MillisecondsInTimeStamp";
const char HTTP_ACCEPT_PORT[] = "HttpAcceptPort";
const char PERSIST_MESSAGES[] = "PersistMessages";
/// Container for setting dictionaries mapped to sessions.
class SessionSettings
{
public:
SessionSettings() {}
SessionSettings( std::istream& stream ) throw( ConfigError );
SessionSettings( const std::string& file ) throw( ConfigError );
/// Check if session setings are present
const bool has( const SessionID& ) const;
/// Get a dictionary for a session.
const Dictionary& get( const SessionID& ) const throw( ConfigError );
/// Set a dictionary for a session
void set( const SessionID&, Dictionary ) throw( ConfigError );
/// Get global default settings
const Dictionary& get() const { return m_defaults; }
/// Set global default settings
void set( const Dictionary& defaults ) throw( ConfigError );
/// Number of session settings
size_t size() const { return m_settings.size(); }
typedef std::map < SessionID, Dictionary > Dictionaries;
std::set < SessionID > getSessions() const;
private:
void validate( const Dictionary& ) const throw( ConfigError );
Dictionaries m_settings;
Dictionary m_defaults;
friend std::ostream& operator<<( std::ostream&, const SessionSettings& );
};
/*! @} */
std::istream& operator>>( std::istream&, SessionSettings& )
throw( ConfigError );
std::ostream& operator<<( std::ostream&, const SessionSettings& );
}
#endif //FIX_SESSIONSETTINGS_H
+231
View File
@@ -0,0 +1,231 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_SESSIONSTATE_H
#define FIX_SESSIONSTATE_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "FieldTypes.h"
#include "MessageStore.h"
#include "Log.h"
#include "Mutex.h"
namespace FIX
{
/// Maintains all of state for the Session class.
class SessionState : public MessageStore, public Log
{
typedef std::map < int, Message > Messages;
public:
SessionState()
: m_enabled( true ), m_receivedLogon( false ),
m_sentLogout( false ), m_sentLogon( false ),
m_sentReset( false ), m_receivedReset( false ),
m_initiate( false ), m_logonTimeout( 10 ),
m_logoutTimeout( 2 ), m_testRequest( 0 ),
m_pStore( 0 ), m_pLog( 0 ) {}
bool enabled() const { return m_enabled; }
void enabled( bool value ) { m_enabled = value; }
bool receivedLogon() const { return m_receivedLogon; }
void receivedLogon( bool value ) { m_receivedLogon = value; }
bool sentLogout() const { return m_sentLogout; }
void sentLogout( bool value ) { m_sentLogout = value; }
bool sentLogon() const { return m_sentLogon; }
void sentLogon( bool value ) { m_sentLogon = value; }
bool receivedReset() const { return m_receivedReset; }
void receivedReset( bool value ) { m_receivedReset = value; }
bool sentReset() const { return m_sentReset; }
void sentReset( bool value ) { m_sentReset = value; }
bool initiate() const { return m_initiate; }
void initiate( bool value ) { m_initiate = value; }
int logonTimeout() const { return m_logonTimeout; }
void logonTimeout( int value ) { m_logonTimeout = value; }
int logoutTimeout() const { return m_logoutTimeout; }
void logoutTimeout( int value ) { m_logoutTimeout = value; }
int testRequest() const { return m_testRequest; }
void testRequest( int value ) { m_testRequest = value; }
bool resendRequested() const
{ return !(m_resendRange.first == 0 && m_resendRange.second == 0); }
typedef std::pair<int, int> ResendRange;
ResendRange resendRange () const { return m_resendRange; }
void resendRange (int begin, int end)
{ m_resendRange = std::make_pair( begin, end ); }
MessageStore* store() { return m_pStore; }
void store( MessageStore* pValue ) { m_pStore = pValue; }
Log* log() { return m_pLog ? m_pLog : &m_nullLog; }
void log( Log* pValue ) { m_pLog = pValue; }
void heartBtInt( const HeartBtInt& value )
{ m_heartBtInt = value; }
HeartBtInt& heartBtInt()
{ return m_heartBtInt; }
const HeartBtInt& heartBtInt() const
{ return m_heartBtInt; }
void lastSentTime( const UtcTimeStamp& value )
{ m_lastSentTime = value; }
UtcTimeStamp& lastSentTime()
{ return m_lastSentTime; }
const UtcTimeStamp& lastSentTime() const
{ return m_lastSentTime; }
void lastReceivedTime( const UtcTimeStamp& value )
{ m_lastReceivedTime = value; }
UtcTimeStamp& lastReceivedTime()
{ return m_lastReceivedTime; }
const UtcTimeStamp& lastReceivedTime() const
{ return m_lastReceivedTime; }
bool shouldSendLogon() const { return initiate() && !sentLogon(); }
bool alreadySentLogon() const { return initiate() && sentLogon(); }
bool logonTimedOut() const
{
UtcTimeStamp now;
return now - lastReceivedTime() >= logonTimeout();
}
bool logoutTimedOut() const
{
UtcTimeStamp now;
return sentLogout() && ( ( now - lastSentTime() ) >= logoutTimeout() );
}
bool withinHeartBeat() const
{
UtcTimeStamp now;
return ( ( now - lastSentTime() ) < heartBtInt() ) &&
( ( now - lastReceivedTime() ) < heartBtInt() );
}
bool timedOut() const
{
UtcTimeStamp now;
return ( now - lastReceivedTime() ) >= ( 2.4 * ( double ) heartBtInt() );
}
bool needHeartbeat() const
{
UtcTimeStamp now;
return ( ( now - lastSentTime() ) >= heartBtInt() ) && !testRequest();
}
bool needTestRequest() const
{
UtcTimeStamp now;
return ( now - lastReceivedTime() ) >=
( ( 1.2 * ( ( double ) testRequest() + 1 ) ) * ( double ) heartBtInt() );
}
std::string logoutReason() const
{ Locker l( m_mutex ); return m_logoutReason; }
void logoutReason( const std::string& value )
{ Locker l( m_mutex ); m_logoutReason = value; }
void queue( int msgSeqNum, const Message& message )
{ Locker l( m_mutex ); m_queue[ msgSeqNum ] = message; }
bool retrieve( int msgSeqNum, Message& message )
{
Locker l( m_mutex );
Messages::iterator i = m_queue.find( msgSeqNum );
if ( i != m_queue.end() )
{
message = i->second;
m_queue.erase( i );
return true;
}
return false;
}
void clearQueue()
{ Locker l( m_mutex ); m_queue.clear(); }
bool set( int s, const std::string& m ) throw ( IOException )
{ Locker l( m_mutex ); return m_pStore->set( s, m ); }
void get( int b, int e, std::vector < std::string > &m ) const
throw ( IOException )
{ Locker l( m_mutex ); m_pStore->get( b, e, m ); }
int getNextSenderMsgSeqNum() const throw ( IOException )
{ Locker l( m_mutex ); return m_pStore->getNextSenderMsgSeqNum(); }
int getNextTargetMsgSeqNum() const throw ( IOException )
{ Locker l( m_mutex ); return m_pStore->getNextTargetMsgSeqNum(); }
void setNextSenderMsgSeqNum( int n ) throw ( IOException )
{ Locker l( m_mutex ); m_pStore->setNextSenderMsgSeqNum( n ); }
void setNextTargetMsgSeqNum( int n ) throw ( IOException )
{ Locker l( m_mutex ); m_pStore->setNextTargetMsgSeqNum( n ); }
void incrNextSenderMsgSeqNum() throw ( IOException )
{ Locker l( m_mutex ); m_pStore->incrNextSenderMsgSeqNum(); }
void incrNextTargetMsgSeqNum() throw ( IOException )
{ Locker l( m_mutex ); m_pStore->incrNextTargetMsgSeqNum(); }
UtcTimeStamp getCreationTime() const throw ( IOException )
{ Locker l( m_mutex ); return m_pStore->getCreationTime(); }
void reset() throw ( IOException )
{ Locker l( m_mutex ); m_pStore->reset(); }
void refresh() throw ( IOException )
{ Locker l( m_mutex ); m_pStore->refresh(); }
void clear()
{ if ( !m_pLog ) return ; Locker l( m_mutex ); m_pLog->clear(); }
void backup()
{ if ( !m_pLog ) return ; Locker l( m_mutex ); m_pLog->backup(); }
void onIncoming( const std::string& string )
{ if ( !m_pLog ) return ; Locker l( m_mutex ); m_pLog->onIncoming( string ); }
void onOutgoing( const std::string& string )
{ if ( !m_pLog ) return ; Locker l( m_mutex ); m_pLog->onOutgoing( string ); }
void onEvent( const std::string& string )
{ if ( !m_pLog ) return ; Locker l( m_mutex ); m_pLog->onEvent( string ); }
private:
bool m_enabled;
bool m_receivedLogon;
bool m_sentLogout;
bool m_sentLogon;
bool m_sentReset;
bool m_receivedReset;
bool m_initiate;
int m_logonTimeout;
int m_logoutTimeout;
int m_testRequest;
ResendRange m_resendRange;
HeartBtInt m_heartBtInt;
UtcTimeStamp m_lastSentTime;
UtcTimeStamp m_lastReceivedTime;
std::string m_logoutReason;
Messages m_queue;
MessageStore* m_pStore;
Log* m_pLog;
NullLog m_nullLog;
mutable Mutex m_mutex;
};
}
#endif //FIX_SESSIONSTATE_H
+53
View File
@@ -0,0 +1,53 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_SETTINGS_H
#define FIX_SETTINGS_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Dictionary.h"
#include <string>
#include <vector>
#include <map>
#include <iostream>
namespace FIX
{
/// Internal representation of QuickFIX configuration settings.
class Settings
{
public:
typedef std::vector < Dictionary > Sections;
Sections get( const std::string& name ) const;
friend std::istream& operator>>( std::istream&, Settings& );
private:
Sections m_sections;
};
std::istream& operator>>( std::istream&, Settings& );
}
#endif //FIX_SETTINGS_H
+150
View File
@@ -0,0 +1,150 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef SHARED_ARRAY
#define SHARED_ARRAY
#include "AtomicCount.h"
namespace FIX
{
/// Shared array with atomic reference count
template<typename T>
class shared_array
{
public:
shared_array()
: m_size(0)
, m_buffer(0)
{}
shared_array(const shared_array& rhs)
: m_size(rhs.m_size)
, m_buffer(rhs.m_buffer)
{
rhs.attach();
}
~shared_array()
{ release(); }
shared_array& operator=(const shared_array& rhs)
{
if( &rhs == this )
return *this;
rhs.attach();
release();
m_size = rhs.m_size;
m_buffer = rhs.m_buffer;
return *this;
}
std::size_t size() const
{ return m_size; }
bool empty() const
{ return m_buffer == 0; }
operator T* () const
{ return m_buffer; }
//optimized function to allocate storage for buffer and counter object at once
static shared_array create(const std::size_t nSize)
{
if(nSize <= 0)
return shared_array();
//verify the needed buffer size to allocate counter object and nSize elements
const std::size_t sizeToAllocate = nSize + ( sizeof(atomic_count) / sizeof(T) + 1 );
//allocate and zero-fill the buffer
T* storage = new T[ sizeToAllocate ];
memset(storage, 0, sizeToAllocate * sizeof(T));
// create the counter object at the end of the storage
// with initial reference count set to 1
new (&storage[nSize]) atomic_count( 1 );
return shared_array(storage, nSize);
}
private:
shared_array( T * buff, std::size_t nSize )
: m_size(nSize)
, m_buffer(buff)
{
}
atomic_count* get_counter() const
{
return reinterpret_cast<atomic_count*>( &m_buffer[ size() ] );
}
void increment_reference_count() const
{
atomic_count* counter = get_counter();
++(*counter);
}
long decrement_reference_count()
{
atomic_count* counter = get_counter();
return --(*counter);
}
void attach() const
{
if( !empty() )
increment_reference_count();
}
void release()
{
if( empty() )
return;
//free object if reference count has decreased to zero
if( decrement_reference_count() == 0)
{
T * tmpBuff = m_buffer;
atomic_count* tmpCounter = get_counter();
m_buffer = 0;
m_size = 0;
//explicitly call destructor for the counter object
tmpCounter->~atomic_count();
delete [] tmpBuff;
}
}
std::size_t m_size;
T * m_buffer;
};
}
#endif
+75
View File
@@ -0,0 +1,75 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_SOCKETACCEPTOR_H
#define FIX_SOCKETACCEPTOR_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Acceptor.h"
#include "SocketServer.h"
#include "SocketConnection.h"
namespace FIX
{
/// Socket implementation of Acceptor.
class SocketAcceptor : public Acceptor, SocketServer::Strategy
{
friend class SocketConnection;
public:
SocketAcceptor( Application&, MessageStoreFactory&,
const SessionSettings& ) throw( ConfigError );
SocketAcceptor( Application&, MessageStoreFactory&,
const SessionSettings&, LogFactory& ) throw( ConfigError );
virtual ~SocketAcceptor();
private:
bool readSettings( const SessionSettings& );
typedef std::set < SessionID > Sessions;
typedef std::map < int, Sessions > PortToSessions;
typedef std::map < int, SocketConnection* > SocketConnections;
void onConfigure( const SessionSettings& ) throw ( ConfigError );
void onInitialize( const SessionSettings& ) throw ( RuntimeError );
void onStart();
bool onPoll( double timeout );
void onStop();
void onConnect( SocketServer&, int, int );
void onWrite( SocketServer&, int );
bool onData( SocketServer&, int );
void onDisconnect( SocketServer&, int );
void onError( SocketServer& );
void onTimeout( SocketServer& );
SocketServer* m_pServer;
PortToSessions m_portToSessions;
SocketConnections m_connections;
};
/*! @} */
}
#endif //FIX_SOCKETACCEPTOR_H
+103
View File
@@ -0,0 +1,103 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_SOCKETCONNECTION_H
#define FIX_SOCKETCONNECTION_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Parser.h"
#include "Responder.h"
#include "SessionID.h"
#include "SocketMonitor.h"
#include "Utility.h"
#include "Mutex.h"
#include <set>
namespace FIX
{
class SocketAcceptor;
class SocketServer;
class SocketConnector;
class SocketInitiator;
class Session;
/// Encapsulates a socket file descriptor (single-threaded).
class SocketConnection : Responder
{
public:
typedef std::set<SessionID> Sessions;
SocketConnection( int s, Sessions sessions, SocketMonitor* pMonitor );
SocketConnection( SocketInitiator&, const SessionID&, int, SocketMonitor* );
virtual ~SocketConnection();
int getSocket() const { return m_socket; }
Session* getSession() const { return m_pSession; }
bool read( SocketConnector& s );
bool read( SocketAcceptor&, SocketServer& );
bool processQueue();
void signal()
{
Locker l( m_mutex );
if( m_sendQueue.size() == 1 )
m_pMonitor->signal( m_socket );
}
void unsignal()
{
Locker l( m_mutex );
if( m_sendQueue.size() == 0 )
m_pMonitor->unsignal( m_socket );
}
void onTimeout();
private:
typedef std::deque<std::string, ALLOCATOR<std::string> >
Queue;
bool isValidSession();
void readFromSocket() throw( SocketRecvFailed );
bool readMessage( std::string& msg );
void readMessages( SocketMonitor& s );
bool send( const std::string& );
void disconnect();
int m_socket;
char m_buffer[BUFSIZ];
Parser m_parser;
Queue m_sendQueue;
unsigned m_sendLength;
Sessions m_sessions;
Session* m_pSession;
SocketMonitor* m_pMonitor;
Mutex m_mutex;
fd_set m_fds;
};
}
#endif //FIX_SOCKETCONNECTION_H
+67
View File
@@ -0,0 +1,67 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_SOCKETCONNECTOR_H
#define FIX_SOCKETCONNECTOR_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "SocketMonitor.h"
#include <string>
namespace FIX
{
/// Connects sockets to remote ports and addresses.
class SocketConnector
{
public:
class Strategy;
SocketConnector( int timeout = 0 );
int connect( const std::string& address, int port, bool noDelay,
int sendBufSize, int rcvBufSize );
int connect( const std::string& address, int port, bool noDelay,
int sendBufSize, int rcvBufSize, Strategy& );
void block( Strategy& strategy, bool poll = 0, double timeout = 0.0 );
SocketMonitor& getMonitor() { return m_monitor; }
private:
SocketMonitor m_monitor;
public:
class Strategy
{
public:
virtual ~Strategy() {}
virtual void onConnect( SocketConnector&, int socket ) = 0;
virtual void onWrite( SocketConnector&, int socket ) = 0;
virtual bool onData( SocketConnector&, int socket ) = 0;
virtual void onDisconnect( SocketConnector&, int socket ) = 0;
virtual void onError( SocketConnector& ) = 0;
virtual void onTimeout( SocketConnector& ) {};
};
};
}
#endif //FIX_SOCKETCONNECTOR_H
+81
View File
@@ -0,0 +1,81 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_SOCKETINITIATOR_H
#define FIX_SOCKETINITIATOR_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Initiator.h"
#include "SocketConnector.h"
#include "SocketConnection.h"
namespace FIX
{
/// Socket implementation of Initiator.
class SocketInitiator : public Initiator, SocketConnector::Strategy
{
public:
SocketInitiator( Application&, MessageStoreFactory&,
const SessionSettings& ) throw( ConfigError );
SocketInitiator( Application&, MessageStoreFactory&,
const SessionSettings&, LogFactory& ) throw( ConfigError );
virtual ~SocketInitiator();
private:
typedef std::map < int, SocketConnection* > SocketConnections;
typedef std::map < SessionID, int > SessionToHostNum;
void onConfigure( const SessionSettings& ) throw ( ConfigError );
void onInitialize( const SessionSettings& ) throw ( RuntimeError );
void onStart();
bool onPoll( double timeout );
void onStop();
void doConnect( const SessionID&, const Dictionary& d );
void onConnect( SocketConnector&, int );
void onWrite( SocketConnector&, int );
bool onData( SocketConnector&, int );
void onDisconnect( SocketConnector&, int );
void onError( SocketConnector& );
void onTimeout( SocketConnector& );
void getHost( const SessionID&, const Dictionary&, std::string&, short& );
SessionSettings m_settings;
SessionToHostNum m_sessionToHostNum;
SocketConnector m_connector;
SocketConnections m_pendingConnections;
SocketConnections m_connections;
time_t m_lastConnect;
int m_reconnectInterval;
bool m_noDelay;
int m_sendBufSize;
int m_rcvBufSize;
};
/*! @} */
}
#endif //FIX_SOCKETINITIATOR_H
+111
View File
@@ -0,0 +1,111 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_SOCKETMONITOR_H
#define FIX_SOCKETMONITOR_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#ifdef _MSC_VER
#include <Winsock2.h>
typedef int socklen_t;
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
#include <set>
#include <queue>
#include <time.h>
namespace FIX
{
/// Monitors events on a collection of sockets.
class SocketMonitor
{
public:
class Strategy;
SocketMonitor( int timeout = 0 );
virtual ~SocketMonitor();
bool addConnect( int socket );
bool addRead( int socket );
bool addWrite( int socket );
bool drop( int socket );
void signal( int socket );
void unsignal( int socket );
void block( Strategy& strategy, bool poll = 0, double timeout = 0.0 );
size_t numSockets()
{ return m_readSockets.size() - 1; }
private:
typedef std::set < int > Sockets;
typedef std::queue < int > Queue;
void setsockopt();
bool bind();
bool listen();
void buildSet( const Sockets&, fd_set& );
inline timeval* getTimeval( bool poll, double timeout );
inline bool sleepIfEmpty( bool poll );
void processReadSet( Strategy&, fd_set& );
void processWriteSet( Strategy&, fd_set& );
void processExceptSet( Strategy&, fd_set& );
int m_timeout;
timeval m_timeval;
#ifndef SELECT_DECREMENTS_TIME
clock_t m_ticks;
#endif
int m_signal;
int m_interrupt;
Sockets m_connectSockets;
Sockets m_readSockets;
Sockets m_writeSockets;
Queue m_dropped;
public:
class Strategy
{
public:
virtual ~Strategy()
{}
virtual void onConnect( SocketMonitor&, int socket ) = 0;
virtual void onEvent( SocketMonitor&, int socket ) = 0;
virtual void onWrite( SocketMonitor&, int socket ) = 0;
virtual void onError( SocketMonitor&, int socket ) = 0;
virtual void onError( SocketMonitor& ) = 0;
virtual void onTimeout( SocketMonitor& )
{}}
;
};
}
#endif //FIX_SOCKETMONITOR_H
+100
View File
@@ -0,0 +1,100 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_SOCKETSERVER_H
#define FIX_SOCKETSERVER_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "SocketMonitor.h"
#include "Exceptions.h"
#include <map>
#include <set>
#include <queue>
namespace FIX
{
/// Information about listening socket
struct SocketInfo
{
SocketInfo()
: m_socket( -1 ), m_port( 0 ), m_noDelay( false ),
m_sendBufSize( 0 ), m_rcvBufSize( 0 ) {}
SocketInfo( int socket, short port, bool noDelay, int sendBufSize, int rcvBufSize )
: m_socket( socket ), m_port( port ), m_noDelay( noDelay ),
m_sendBufSize( sendBufSize ), m_rcvBufSize( rcvBufSize ) {}
int m_socket;
short m_port;
bool m_noDelay;
int m_sendBufSize;
int m_rcvBufSize;
};
/// Listens for and accepts incoming socket connections on a port.
class SocketServer
{
public:
class Strategy;
SocketServer( int timeout = 0 );
int add( int port, bool reuse = false, bool noDelay = false,
int sendBufSize = 0, int rcvBufSize = 0 ) throw( SocketException& );
int accept( int socket );
void close();
bool block( Strategy& strategy, bool poll = 0, double timeout = 0.0 );
size_t numConnections() { return m_monitor.numSockets() - 1; }
SocketMonitor& getMonitor() { return m_monitor; }
int socketToPort( int socket );
int portToSocket( int port );
private:
typedef std::map<int, SocketInfo>
SocketToInfo;
typedef std::map<int, SocketInfo>
PortToInfo;
SocketToInfo m_socketToInfo;
PortToInfo m_portToInfo;
SocketMonitor m_monitor;
public:
class Strategy
{
public:
virtual ~Strategy() {}
virtual void onConnect( SocketServer&, int acceptSocket, int socket ) = 0;
virtual void onWrite( SocketServer&, int socket ) = 0;
virtual bool onData( SocketServer&, int socket ) = 0;
virtual void onDisconnect( SocketServer&, int socket ) = 0;
virtual void onError( SocketServer& ) = 0;
virtual void onTimeout( SocketServer& ) {};
};
};
}
#endif //FIX_SOCKETSERVER_H
@@ -0,0 +1,98 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_THREADEDSOCKETACCEPTOR_H
#define FIX_THREADEDSOCKETACCEPTOR_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Acceptor.h"
#include "ThreadedSocketConnection.h"
#include "Mutex.h"
namespace FIX
{
/// Threaded Socket implementation of Acceptor.
class ThreadedSocketAcceptor : public Acceptor
{
friend class SocketConnection;
public:
ThreadedSocketAcceptor( Application&, MessageStoreFactory&,
const SessionSettings& ) throw( ConfigError );
ThreadedSocketAcceptor( Application&, MessageStoreFactory&,
const SessionSettings&,
LogFactory& ) throw( ConfigError );
virtual ~ThreadedSocketAcceptor();
private:
struct AcceptorThreadInfo
{
AcceptorThreadInfo( ThreadedSocketAcceptor* pAcceptor, int socket, int port )
: m_pAcceptor( pAcceptor ), m_socket( socket ), m_port( port ) {}
ThreadedSocketAcceptor* m_pAcceptor;
int m_socket;
int m_port;
};
struct ConnectionThreadInfo
{
ConnectionThreadInfo( ThreadedSocketAcceptor* pAcceptor,
ThreadedSocketConnection* pConnection )
: m_pAcceptor( pAcceptor ), m_pConnection( pConnection ) {}
ThreadedSocketAcceptor* m_pAcceptor;
ThreadedSocketConnection* m_pConnection;
};
bool readSettings( const SessionSettings& );
typedef std::set < int > Sockets;
typedef std::set < SessionID > Sessions;
typedef std::map < int, Sessions > PortToSessions;
typedef std::map < int, int > SocketToPort;
typedef std::map < int, thread_id > SocketToThread;
void onConfigure( const SessionSettings& ) throw ( ConfigError );
void onInitialize( const SessionSettings& ) throw ( RuntimeError );
void onStart();
bool onPoll( double timeout );
void onStop();
void addThread( int s, thread_id t );
void removeThread( int s );
static THREAD_PROC socketAcceptorThread( void* p );
static THREAD_PROC socketConnectionThread( void* p );
Sockets m_sockets;
PortToSessions m_portToSessions;
SocketToPort m_socketToPort;
SocketToThread m_threads;
Mutex m_mutex;
};
/*! @} */
}
#endif //FIX_THREADEDSOCKETACCEPTOR_H
@@ -0,0 +1,82 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_THREADEDSOCKETCONNECTION_H
#define FIX_THREADEDSOCKETCONNECTION_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Parser.h"
#include "Responder.h"
#include "SessionID.h"
#include <set>
#include <map>
namespace FIX
{
class ThreadedSocketAcceptor;
class ThreadedSocketInitiator;
class Session;
class Application;
class Log;
/// Encapsulates a socket file descriptor (multi-threaded).
class ThreadedSocketConnection : Responder
{
public:
typedef std::set<SessionID> Sessions;
ThreadedSocketConnection( int s, Sessions sessions, Log* pLog );
ThreadedSocketConnection( const SessionID&, int s,
const std::string& address, short port,
Log* pLog );
virtual ~ThreadedSocketConnection() ;
Session* getSession() const { return m_pSession; }
int getSocket() const { return m_socket; }
bool connect();
void disconnect();
bool read();
private:
bool readMessage( std::string& msg ) throw( SocketRecvFailed );
void processStream();
bool send( const std::string& );
bool setSession( const std::string& msg );
int m_socket;
char m_buffer[BUFSIZ];
std::string m_address;
int m_port;
Log* m_pLog;
Parser m_parser;
Sessions m_sessions;
Session* m_pSession;
bool m_disconnect;
fd_set m_fds;
};
}
#endif //FIX_THREADEDSOCKETCONNECTION_H
@@ -0,0 +1,84 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_THREADEDSOCKETINITIATOR_H
#define FIX_THREADEDSOCKETINITIATOR_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Initiator.h"
#include "ThreadedSocketConnection.h"
#include <map>
namespace FIX
{
/*! \addtogroup user
* @{
*/
/// Threaded Socket implementation of Initiator.
class ThreadedSocketInitiator : public Initiator
{
public:
ThreadedSocketInitiator( Application&, MessageStoreFactory&,
const SessionSettings& ) throw( ConfigError );
ThreadedSocketInitiator( Application&, MessageStoreFactory&,
const SessionSettings&,
LogFactory& ) throw( ConfigError );
virtual ~ThreadedSocketInitiator();
private:
typedef std::map < int, thread_id > SocketToThread;
typedef std::map < SessionID, int > SessionToHostNum;
typedef std::pair < ThreadedSocketInitiator*, ThreadedSocketConnection* > ThreadPair;
void onConfigure( const SessionSettings& ) throw ( ConfigError );
void onInitialize( const SessionSettings& ) throw ( RuntimeError );
void onStart();
bool onPoll( double timeout );
void onStop();
void doConnect( const SessionID& s, const Dictionary& d );
void addThread( int s, thread_id t );
void removeThread( int s );
void lock() { Locker l(m_mutex); }
static THREAD_PROC socketThread( void* p );
void getHost( const SessionID&, const Dictionary&, std::string&, short& );
SessionSettings m_settings;
SessionToHostNum m_sessionToHostNum;
time_t m_lastConnect;
int m_reconnectInterval;
bool m_noDelay;
int m_sendBufSize;
int m_rcvBufSize;
SocketToThread m_threads;
Mutex m_mutex;
};
/*! @} */
}
#endif //FIX_THREADEDSOCKETINITIATOR_H
+258
View File
@@ -0,0 +1,258 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_TIMERANGE_H
#define FIX_TIMERANGE_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "FieldTypes.h"
namespace FIX
{
/// Keeps track of when session is active
class TimeRange
{
public:
TimeRange( const UtcTimeOnly& startTime, const UtcTimeOnly& endTime,
int startDay = -1, int endDay = -1 );
TimeRange( const LocalTimeOnly& startTime, const LocalTimeOnly& endTime,
int startDay = -1, int endDay = -1 );
static bool isInRange( const UtcTimeOnly& start,
const UtcTimeOnly& end,
const DateTime& time )
{
return isInRange
( (DateTime)start, (DateTime)end, (DateTime)time );
}
static bool isInRange( const UtcTimeOnly& startTime,
const UtcTimeOnly& endTime,
int startDay,
int endDay,
const DateTime& time,
int day )
{
return isInRange
( (DateTime)startTime, (DateTime)endTime,
startDay, endDay,
(DateTime)time, day );
}
static bool isInRange( const UtcTimeOnly& startTime,
const UtcTimeOnly& endTime,
int startDay,
int endDay,
const DateTime& time )
{
return isInRange
( (DateTime)startTime, (DateTime)endTime,
startDay, endDay,
(DateTime)time );
}
static bool isInSameRange( const UtcTimeOnly& start,
const UtcTimeOnly& end,
const DateTime& time1,
const DateTime& time2 )
{
return isInSameRange
( (DateTime)start, (DateTime)end,
(DateTime)time1, (DateTime)time2 );
}
static bool isInSameRange( const UtcTimeOnly& startTime,
const UtcTimeOnly& endTime,
int startDay,
int endDay,
const DateTime& time1,
const DateTime& time2 )
{
return isInSameRange
( (DateTime)startTime, (DateTime)endTime,
startDay, endDay,
(DateTime)time1, (DateTime)time2 );
}
static bool isInRange( const LocalTimeOnly& start,
const LocalTimeOnly& end,
const DateTime& time )
{
return isInRange
( (DateTime)start, (DateTime)end, (DateTime)time );
}
static bool isInRange( const LocalTimeOnly& startTime,
const LocalTimeOnly& endTime,
int startDay,
int endDay,
const DateTime& time,
int day )
{
return isInRange
( (DateTime)startTime, (DateTime)endTime,
startDay, endDay,
(DateTime)time, day );
}
static bool isInRange( const LocalTimeOnly& startTime,
const LocalTimeOnly& endTime,
int startDay,
int endDay,
const DateTime& time )
{
return isInRange
( (DateTime)startTime, (DateTime)endTime,
startDay, endDay,
(DateTime)time );
}
static bool isInSameRange( const LocalTimeOnly& start,
const LocalTimeOnly& end,
const DateTime& time1,
const DateTime& time2 )
{
return isInSameRange
( (DateTime)start, (DateTime)end,
(DateTime)time1, (DateTime)time2 );
}
static bool isInSameRange( const LocalTimeOnly& startTime,
const LocalTimeOnly& endTime,
int startDay,
int endDay,
const DateTime& time1,
const DateTime& time2 )
{
return isInSameRange
( (DateTime)startTime, (DateTime)endTime,
startDay, endDay,
(DateTime)time1, (DateTime)time2 );
}
private:
static bool isInRange( const DateTime& start,
const DateTime& end,
const DateTime& time );
static bool isInRange( const DateTime& startTime,
const DateTime& endTime,
int startDay,
int endDay,
const DateTime& time,
int day );
static bool isInRange( const DateTime& startTime,
const DateTime& endTime,
int startDay,
int endDay,
const DateTime& time );
static bool isInSameRange( const DateTime& start,
const DateTime& end,
const DateTime& time1,
const DateTime& time2 );
static bool isInSameRange( const DateTime& startTime,
const DateTime& endTime,
int startDay,
int endDay,
const DateTime& time1,
const DateTime& time2 );
public:
bool isInRange( const DateTime& dateTime, int day )
{
if( m_startDay < 0 && m_endDay < 0 )
return isInRange( m_startTime, m_endTime, dateTime );
else
return isInRange
( m_startTime, m_endTime, m_startDay, m_endDay, dateTime, day );
}
bool isInRange( const UtcTimeStamp& dateTime )
{
if( m_useLocalTime )
{
LocalTimeStamp localDateTime( dateTime.getTimeT() );
return isInRange( localDateTime, localDateTime.getWeekDay() );
}
return isInRange( dateTime, dateTime.getWeekDay() );
}
bool isInRange( const LocalTimeStamp& dateTime )
{
if( !m_useLocalTime )
{
LocalTimeStamp utcDateTime( dateTime.getTimeT() );
return isInRange( utcDateTime, utcDateTime.getWeekDay() );
}
return isInRange( dateTime, dateTime.getWeekDay() );
}
bool isInSameRange( const UtcTimeStamp& time1, const UtcTimeStamp& time2 )
{
if( m_useLocalTime )
{
LocalTimeStamp localTime1( time1.getTimeT() );
LocalTimeStamp localTime2( time2.getTimeT() );
return isInSameRange( (DateTime)localTime1, (DateTime)localTime2 );
}
return isInSameRange( (DateTime)time1, (DateTime)time2 );
}
bool isInSameRange( const LocalTimeStamp& time1, const LocalTimeStamp& time2 )
{
if( !m_useLocalTime )
{
UtcTimeStamp utcTime1( time1.getTimeT() );
UtcTimeStamp utcTime2( time2.getTimeT() );
return isInSameRange( (DateTime)utcTime1, (DateTime)utcTime2 );
}
return isInSameRange( (DateTime)time1, (DateTime)time2 );
}
private:
bool isInSameRange( const DateTime& time1, const DateTime& time2 )
{
if( m_startDay < 0 && m_endDay < 0 )
return isInSameRange( m_startTime, m_endTime, time1, time2 );
else
return isInSameRange
( m_startTime, m_endTime, m_startDay, m_endDay, time1, time2 );
}
UtcTimeOnly m_startTime;
UtcTimeOnly m_endTime;
int m_startDay;
int m_endDay;
bool m_useLocalTime;
};
}
#endif
+219
View File
@@ -0,0 +1,219 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_UTILITY_H
#define FIX_UTILITY_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#ifndef _MSC_VER
#include "Allocator.h"
#endif
#ifdef HAVE_STLPORT
#define ALLOCATOR std::allocator
#elif ENABLE_DEBUG_ALLOCATOR
#include <ext/debug_allocator.h>
#define ALLOCATOR __gnu_cxx::debug_allocator
#elif ENABLE_NEW_ALLOCATOR
#include <ext/new_allocator.h>
#define ALLOCATOR __gnu_cxx::new_allocator
#elif ENABLE_BOOST_FAST_POOL_ALLOCATOR
#include <boost/pool/pool_alloc.hpp>
#define ALLOCATOR boost::fast_pool_allocator
#elif ENABLE_MT_ALLOCATOR
#include <ext/mt_allocator.h>
#define ALLOCATOR __gnu_cxx::__mt_alloc
#elif ENABLE_BOOST_POOL_ALLOCATOR
#include <boost/pool/pool_alloc.hpp>
#define ALLOCATOR boost::pool_allocator
#elif ENABLE_POOL_ALLOCATOR
#include <ext/pool_allocator.h>
#define ALLOCATOR __gnu_cxx::__pool_alloc
#elif ENABLE_BITMAP_ALLOCATOR
#include <ext/bitmap_allocator.h>
#define ALLOCATOR __gnu_cxx::bitmap_allocator
#elif ENABLE_TBB_ALLOCATOR
#include <tbb/scalable_allocator.h>
#define ALLOCATOR tbb::scalable_allocator
#else
#define ALLOCATOR std::allocator
#endif
#ifdef _MSC_VER
/////////////////////////////////////////////
#include <Winsock2.h>
#include <process.h>
#include <direct.h>
#include <time.h>
typedef int socklen_t;
typedef int ssize_t;
/////////////////////////////////////////////
#else
/////////////////////////////////////////////
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <fcntl.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>
#include <errno.h>
#include <time.h>
#include <stdlib.h>
/////////////////////////////////////////////
#endif
#include <string>
#include <cstring>
#include <cctype>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <memory>
#if defined(HAVE_STD_SHARED_PTR)
namespace ptr = std;
#elif defined(HAVE_STD_TR1_SHARED_PTR)
#include <tr1/memory>
namespace ptr = std::tr1;
#else
namespace ptr = std;
#endif
namespace FIX
{
void string_replace( const std::string& oldValue,
const std::string& newValue,
std::string& value );
std::string string_toLower( const std::string& value );
std::string string_toUpper( const std::string& value );
std::string string_strip( const std::string& value );
void socket_init();
void socket_term();
int socket_createAcceptor( int port, bool reuse = false );
int socket_createConnector();
int socket_connect( int s, const char* address, int port );
int socket_accept( int s );
ssize_t socket_send( int s, const char* msg, size_t length );
void socket_close( int s );
bool socket_fionread( int s, int& bytes );
bool socket_disconnected( int s );
int socket_setsockopt( int s, int opt );
int socket_setsockopt( int s, int opt, int optval );
int socket_getsockopt( int s, int opt, int& optval );
#ifndef _MSC_VER
int socket_fcntl( int s, int opt, int arg );
int socket_getfcntlflag( int s, int arg );
int socket_setfcntlflag( int s, int arg );
#endif
void socket_setnonblock( int s );
bool socket_isValid( int socket );
#ifndef _MSC_VER
bool socket_isBad( int s );
#endif
void socket_invalidate( int& socket );
short socket_hostport( int socket );
const char* socket_hostname( int socket );
const char* socket_hostname( const char* name );
const char* socket_peername( int socket );
std::pair<int, int> socket_createpair();
tm time_gmtime( const time_t* t );
tm time_localtime( const time_t* t );
#ifdef _MSC_VER
typedef unsigned int (_stdcall THREAD_START_ROUTINE)(void *);
#define THREAD_PROC unsigned int _stdcall
#else
extern "C" { typedef void * (THREAD_START_ROUTINE)(void *); }
#define THREAD_PROC void *
#endif
#ifdef _MSC_VER
typedef unsigned thread_id;
#else
typedef pthread_t thread_id;
#endif
bool thread_spawn( THREAD_START_ROUTINE func, void* var, thread_id& thread );
bool thread_spawn( THREAD_START_ROUTINE func, void* var );
void thread_join( thread_id thread );
void thread_detach( thread_id thread );
thread_id thread_self();
void process_sleep( double s );
std::string file_separator();
void file_mkdir( const char* path );
FILE* file_fopen( const char* path, const char* mode );
void file_fclose( FILE* file );
bool file_exists( const char* path );
void file_unlink( const char* path );
int file_rename( const char* oldpath, const char* newpath );
std::string file_appendpath( const std::string& path, const std::string& file );
}
#if( _MSC_VER >= 1400 )
#define HAVE_FSCANF_S 1
#define FILE_FSCANF fscanf_s
#else
#define FILE_FSCANF fscanf
#endif
#if( _MSC_VER >= 1400 )
#define HAVE_SPRINTF_S 1
#define STRING_SPRINTF sprintf_s
#else
#define STRING_SPRINTF sprintf
#endif
#if (!defined(_MSC_VER) || (_MSC_VER >= 1300)) && !defined(HAVE_STLPORT)
using std::abort;
using std::sprintf;
using std::atoi;
using std::atol;
using std::atof;
using std::isdigit;
using std::strcmp;
using std::strftime;
using std::strlen;
using std::abs;
using std::labs;
using std::memcpy;
using std::memset;
using std::exit;
using std::strtod;
using std::strtol;
using std::strerror;
#endif
#endif
+62
View File
@@ -0,0 +1,62 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_VALUES_BASE_H
#define FIX_VALUES_BASE_H
#include "FixValues.h"
#include <string>
namespace FIX
{
const char BeginString_FIXT11[] = "FIXT.1.1";
const char BeginString_FIX50[] = "FIX.5.0";
const char BeginString_FIX44[] = "FIX.4.4";
const char BeginString_FIX43[] = "FIX.4.3";
const char BeginString_FIX42[] = "FIX.4.2";
const char BeginString_FIX41[] = "FIX.4.1";
const char BeginString_FIX40[] = "FIX.4.0";
const char SessionRejectReason_INVALID_TAG_NUMBER_TEXT[] = "Invalid tag number";
const char SessionRejectReason_REQUIRED_TAG_MISSING_TEXT[] = "Required tag missing";
const char SessionRejectReason_TAG_NOT_DEFINED_FOR_THIS_MESSAGE_TYPE_TEXT[] = "Tag not defined for this message type";
const char SessionRejectReason_UNDEFINED_TAG_TEXT[] = "Undefined Tag";
const char SessionRejectReason_TAG_SPECIFIED_WITHOUT_A_VALUE_TEXT[] = "Tag specified without a value";
const char SessionRejectReason_VALUE_IS_INCORRECT_TEXT[] = "Value is incorrect (out of range) for this tag";
const char SessionRejectReason_INCORRECT_DATA_FORMAT_FOR_VALUE_TEXT[] = "Incorrect data format for value";
const char SessionRejectReason_DECRYPTION_PROBLEM_TEXT[] = "Decryption problem";
const char SessionRejectReason_SIGNATURE_PROBLEM_TEXT[] = "Signature problem";
const char SessionRejectReason_COMPID_PROBLEM_TEXT[] = "CompID problem";
const char SessionRejectReason_SENDINGTIME_ACCURACY_PROBLEM_TEXT[] = "SendingTime accuracy problem";
const char SessionRejectReason_INVALID_MSGTYPE_TEXT[] = "Invalid MsgType";
const char SessionRejectReason_TAG_APPEARS_MORE_THAN_ONCE_TEXT[] = "Tag appears more than once";
const char SessionRejectReason_TAG_SPECIFIED_OUT_OF_REQUIRED_ORDER_TEXT[] = "Tag specified out of required order";
const char SessionRejectReason_INCORRECT_NUMINGROUP_COUNT_FOR_REPEATING_GROUP_TEXT[] = "Incorrect NumInGroup count for repeating group";
const char BusinessRejectReason_OTHER_TEXT[] = "Other";
const char BusinessRejectReason_UNKNOWN_ID_TEXT[] = "Unknown ID";
const char BusinessRejectReason_UNKNOWN_SECURITY_TEXT[] = "Unknown Security";
const char BusinessRejectReason_UNSUPPORTED_MESSAGE_TYPE_TEXT[] = "Unsupported Message Type";
const char BusinessRejectReason_APPLICATION_NOT_AVAILABLE_TEXT[] = "Application Not Available";
const char BusinessRejectReason_CONDITIONALLY_REQUIRED_FIELD_MISSING_TEXT[] = "Conditionally Required Field Missing";
const char BusinessRejectReason_NOT_AUTHORIZED_TEXT[] = "Not Authorized";
const char BusinessRejectReason_DELIVERTO_FIRM_NOT_AVAILABLE_AT_THIS_TIME_TEXT[] = "Deliver to firm not available at this time";
}
#endif //FIX_VALUES_BASE_H
@@ -0,0 +1,52 @@
#ifndef FIX40_ADVERTISEMENT_H
#define FIX40_ADVERTISEMENT_H
#include "Message.h"
namespace FIX40
{
class Advertisement : public Message
{
public:
Advertisement() : Message(MsgType()) {}
Advertisement(const FIX::Message& m) : Message(m) {}
Advertisement(const Message& m) : Message(m) {}
Advertisement(const Advertisement& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("7"); }
Advertisement(
const FIX::AdvId& aAdvId,
const FIX::AdvTransType& aAdvTransType,
const FIX::Symbol& aSymbol,
const FIX::AdvSide& aAdvSide,
const FIX::Shares& aShares )
: Message(MsgType())
{
set(aAdvId);
set(aAdvTransType);
set(aSymbol);
set(aAdvSide);
set(aShares);
}
FIELD_SET(*this, FIX::AdvId);
FIELD_SET(*this, FIX::AdvTransType);
FIELD_SET(*this, FIX::AdvRefID);
FIELD_SET(*this, FIX::Symbol);
FIELD_SET(*this, FIX::SymbolSfx);
FIELD_SET(*this, FIX::SecurityID);
FIELD_SET(*this, FIX::IDSource);
FIELD_SET(*this, FIX::Issuer);
FIELD_SET(*this, FIX::SecurityDesc);
FIELD_SET(*this, FIX::AdvSide);
FIELD_SET(*this, FIX::Shares);
FIELD_SET(*this, FIX::Price);
FIELD_SET(*this, FIX::Currency);
FIELD_SET(*this, FIX::TransactTime);
FIELD_SET(*this, FIX::Text);
};
}
#endif
+109
View File
@@ -0,0 +1,109 @@
#ifndef FIX40_ALLOCATION_H
#define FIX40_ALLOCATION_H
#include "Message.h"
namespace FIX40
{
class Allocation : public Message
{
public:
Allocation() : Message(MsgType()) {}
Allocation(const FIX::Message& m) : Message(m) {}
Allocation(const Message& m) : Message(m) {}
Allocation(const Allocation& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("J"); }
Allocation(
const FIX::AllocID& aAllocID,
const FIX::AllocTransType& aAllocTransType,
const FIX::Side& aSide,
const FIX::Symbol& aSymbol,
const FIX::Shares& aShares,
const FIX::AvgPx& aAvgPx,
const FIX::TradeDate& aTradeDate )
: Message(MsgType())
{
set(aAllocID);
set(aAllocTransType);
set(aSide);
set(aSymbol);
set(aShares);
set(aAvgPx);
set(aTradeDate);
}
FIELD_SET(*this, FIX::AllocID);
FIELD_SET(*this, FIX::AllocTransType);
FIELD_SET(*this, FIX::RefAllocID);
FIELD_SET(*this, FIX::Side);
FIELD_SET(*this, FIX::Symbol);
FIELD_SET(*this, FIX::SymbolSfx);
FIELD_SET(*this, FIX::SecurityID);
FIELD_SET(*this, FIX::IDSource);
FIELD_SET(*this, FIX::Issuer);
FIELD_SET(*this, FIX::SecurityDesc);
FIELD_SET(*this, FIX::Shares);
FIELD_SET(*this, FIX::AvgPx);
FIELD_SET(*this, FIX::Currency);
FIELD_SET(*this, FIX::AvgPrxPrecision);
FIELD_SET(*this, FIX::TradeDate);
FIELD_SET(*this, FIX::TransactTime);
FIELD_SET(*this, FIX::SettlmntTyp);
FIELD_SET(*this, FIX::FutSettDate);
FIELD_SET(*this, FIX::NetMoney);
FIELD_SET(*this, FIX::SettlCurrAmt);
FIELD_SET(*this, FIX::SettlCurrency);
FIELD_SET(*this, FIX::OpenClose);
FIELD_SET(*this, FIX::Text);
FIELD_SET(*this, FIX::NoOrders);
class NoOrders: public FIX::Group
{
public:
NoOrders() : FIX::Group(73,11,FIX::message_order(11,37,66,105,0)) {}
FIELD_SET(*this, FIX::ClOrdID);
FIELD_SET(*this, FIX::OrderID);
FIELD_SET(*this, FIX::ListID);
FIELD_SET(*this, FIX::WaveNo);
};
FIELD_SET(*this, FIX::NoExecs);
class NoExecs: public FIX::Group
{
public:
NoExecs() : FIX::Group(124,17,FIX::message_order(17,32,31,30,0)) {}
FIELD_SET(*this, FIX::ExecID);
FIELD_SET(*this, FIX::LastShares);
FIELD_SET(*this, FIX::LastPx);
FIELD_SET(*this, FIX::LastMkt);
};
FIELD_SET(*this, FIX::NoMiscFees);
class NoMiscFees: public FIX::Group
{
public:
NoMiscFees() : FIX::Group(136,137,FIX::message_order(137,138,139,0)) {}
FIELD_SET(*this, FIX::MiscFeeAmt);
FIELD_SET(*this, FIX::MiscFeeCurr);
FIELD_SET(*this, FIX::MiscFeeType);
};
FIELD_SET(*this, FIX::NoAllocs);
class NoAllocs: public FIX::Group
{
public:
NoAllocs() : FIX::Group(78,79,FIX::message_order(79,80,81,76,109,12,13,85,92,86,0)) {}
FIELD_SET(*this, FIX::AllocAccount);
FIELD_SET(*this, FIX::AllocShares);
FIELD_SET(*this, FIX::ProcessCode);
FIELD_SET(*this, FIX::ExecBroker);
FIELD_SET(*this, FIX::ClientID);
FIELD_SET(*this, FIX::Commission);
FIELD_SET(*this, FIX::CommType);
FIELD_SET(*this, FIX::NoDlvyInst);
FIELD_SET(*this, FIX::BrokerOfCredit);
FIELD_SET(*this, FIX::DlvyInst);
};
};
}
#endif
@@ -0,0 +1,41 @@
#ifndef FIX40_ALLOCATIONINSTRUCTIONACK_H
#define FIX40_ALLOCATIONINSTRUCTIONACK_H
#include "Message.h"
namespace FIX40
{
class AllocationInstructionAck : public Message
{
public:
AllocationInstructionAck() : Message(MsgType()) {}
AllocationInstructionAck(const FIX::Message& m) : Message(m) {}
AllocationInstructionAck(const Message& m) : Message(m) {}
AllocationInstructionAck(const AllocationInstructionAck& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("P"); }
AllocationInstructionAck(
const FIX::AllocID& aAllocID,
const FIX::TradeDate& aTradeDate,
const FIX::AllocStatus& aAllocStatus )
: Message(MsgType())
{
set(aAllocID);
set(aTradeDate);
set(aAllocStatus);
}
FIELD_SET(*this, FIX::ClientID);
FIELD_SET(*this, FIX::ExecBroker);
FIELD_SET(*this, FIX::AllocID);
FIELD_SET(*this, FIX::TradeDate);
FIELD_SET(*this, FIX::TransactTime);
FIELD_SET(*this, FIX::AllocStatus);
FIELD_SET(*this, FIX::AllocRejCode);
FIELD_SET(*this, FIX::Text);
};
}
#endif
@@ -0,0 +1,48 @@
#ifndef FIX40_DONTKNOWTRADE_H
#define FIX40_DONTKNOWTRADE_H
#include "Message.h"
namespace FIX40
{
class DontKnowTrade : public Message
{
public:
DontKnowTrade() : Message(MsgType()) {}
DontKnowTrade(const FIX::Message& m) : Message(m) {}
DontKnowTrade(const Message& m) : Message(m) {}
DontKnowTrade(const DontKnowTrade& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("Q"); }
DontKnowTrade(
const FIX::DKReason& aDKReason,
const FIX::Symbol& aSymbol,
const FIX::Side& aSide,
const FIX::OrderQty& aOrderQty,
const FIX::LastShares& aLastShares,
const FIX::LastPx& aLastPx )
: Message(MsgType())
{
set(aDKReason);
set(aSymbol);
set(aSide);
set(aOrderQty);
set(aLastShares);
set(aLastPx);
}
FIELD_SET(*this, FIX::OrderID);
FIELD_SET(*this, FIX::ExecID);
FIELD_SET(*this, FIX::DKReason);
FIELD_SET(*this, FIX::Symbol);
FIELD_SET(*this, FIX::Side);
FIELD_SET(*this, FIX::OrderQty);
FIELD_SET(*this, FIX::LastShares);
FIELD_SET(*this, FIX::LastPx);
FIELD_SET(*this, FIX::Text);
};
}
#endif
+42
View File
@@ -0,0 +1,42 @@
#ifndef FIX40_EMAIL_H
#define FIX40_EMAIL_H
#include "Message.h"
namespace FIX40
{
class Email : public Message
{
public:
Email() : Message(MsgType()) {}
Email(const FIX::Message& m) : Message(m) {}
Email(const Message& m) : Message(m) {}
Email(const Email& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("C"); }
Email(
const FIX::EmailType& aEmailType,
const FIX::LinesOfText& aLinesOfText,
const FIX::Text& aText )
: Message(MsgType())
{
set(aEmailType);
set(aLinesOfText);
set(aText);
}
FIELD_SET(*this, FIX::EmailType);
FIELD_SET(*this, FIX::OrigTime);
FIELD_SET(*this, FIX::RelatdSym);
FIELD_SET(*this, FIX::OrderID);
FIELD_SET(*this, FIX::ClOrdID);
FIELD_SET(*this, FIX::LinesOfText);
FIELD_SET(*this, FIX::Text);
FIELD_SET(*this, FIX::RawDataLength);
FIELD_SET(*this, FIX::RawData);
};
}
#endif
@@ -0,0 +1,102 @@
#ifndef FIX40_EXECUTIONREPORT_H
#define FIX40_EXECUTIONREPORT_H
#include "Message.h"
namespace FIX40
{
class ExecutionReport : public Message
{
public:
ExecutionReport() : Message(MsgType()) {}
ExecutionReport(const FIX::Message& m) : Message(m) {}
ExecutionReport(const Message& m) : Message(m) {}
ExecutionReport(const ExecutionReport& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("8"); }
ExecutionReport(
const FIX::OrderID& aOrderID,
const FIX::ExecID& aExecID,
const FIX::ExecTransType& aExecTransType,
const FIX::OrdStatus& aOrdStatus,
const FIX::Symbol& aSymbol,
const FIX::Side& aSide,
const FIX::OrderQty& aOrderQty,
const FIX::LastShares& aLastShares,
const FIX::LastPx& aLastPx,
const FIX::CumQty& aCumQty,
const FIX::AvgPx& aAvgPx )
: Message(MsgType())
{
set(aOrderID);
set(aExecID);
set(aExecTransType);
set(aOrdStatus);
set(aSymbol);
set(aSide);
set(aOrderQty);
set(aLastShares);
set(aLastPx);
set(aCumQty);
set(aAvgPx);
}
FIELD_SET(*this, FIX::OrderID);
FIELD_SET(*this, FIX::ClOrdID);
FIELD_SET(*this, FIX::ClientID);
FIELD_SET(*this, FIX::ExecBroker);
FIELD_SET(*this, FIX::ListID);
FIELD_SET(*this, FIX::ExecID);
FIELD_SET(*this, FIX::ExecTransType);
FIELD_SET(*this, FIX::ExecRefID);
FIELD_SET(*this, FIX::OrdStatus);
FIELD_SET(*this, FIX::OrdRejReason);
FIELD_SET(*this, FIX::Account);
FIELD_SET(*this, FIX::SettlmntTyp);
FIELD_SET(*this, FIX::FutSettDate);
FIELD_SET(*this, FIX::Symbol);
FIELD_SET(*this, FIX::SymbolSfx);
FIELD_SET(*this, FIX::SecurityID);
FIELD_SET(*this, FIX::IDSource);
FIELD_SET(*this, FIX::Issuer);
FIELD_SET(*this, FIX::SecurityDesc);
FIELD_SET(*this, FIX::Side);
FIELD_SET(*this, FIX::OrderQty);
FIELD_SET(*this, FIX::OrdType);
FIELD_SET(*this, FIX::Price);
FIELD_SET(*this, FIX::StopPx);
FIELD_SET(*this, FIX::Currency);
FIELD_SET(*this, FIX::TimeInForce);
FIELD_SET(*this, FIX::ExpireTime);
FIELD_SET(*this, FIX::ExecInst);
FIELD_SET(*this, FIX::Rule80A);
FIELD_SET(*this, FIX::LastShares);
FIELD_SET(*this, FIX::LastPx);
FIELD_SET(*this, FIX::LastMkt);
FIELD_SET(*this, FIX::LastCapacity);
FIELD_SET(*this, FIX::CumQty);
FIELD_SET(*this, FIX::AvgPx);
FIELD_SET(*this, FIX::TradeDate);
FIELD_SET(*this, FIX::TransactTime);
FIELD_SET(*this, FIX::ReportToExch);
FIELD_SET(*this, FIX::Commission);
FIELD_SET(*this, FIX::CommType);
FIELD_SET(*this, FIX::NetMoney);
FIELD_SET(*this, FIX::SettlCurrAmt);
FIELD_SET(*this, FIX::SettlCurrency);
FIELD_SET(*this, FIX::Text);
FIELD_SET(*this, FIX::NoMiscFees);
class NoMiscFees: public FIX::Group
{
public:
NoMiscFees() : FIX::Group(136,137,FIX::message_order(137,138,139,0)) {}
FIELD_SET(*this, FIX::MiscFeeAmt);
FIELD_SET(*this, FIX::MiscFeeCurr);
FIELD_SET(*this, FIX::MiscFeeType);
};
};
}
#endif
+23
View File
@@ -0,0 +1,23 @@
#ifndef FIX40_HEARTBEAT_H
#define FIX40_HEARTBEAT_H
#include "Message.h"
namespace FIX40
{
class Heartbeat : public Message
{
public:
Heartbeat() : Message(MsgType()) {}
Heartbeat(const FIX::Message& m) : Message(m) {}
Heartbeat(const Message& m) : Message(m) {}
Heartbeat(const Heartbeat& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("0"); }
FIELD_SET(*this, FIX::TestReqID);
};
}
#endif
+56
View File
@@ -0,0 +1,56 @@
#ifndef FIX40_IOI_H
#define FIX40_IOI_H
#include "Message.h"
namespace FIX40
{
class IOI : public Message
{
public:
IOI() : Message(MsgType()) {}
IOI(const FIX::Message& m) : Message(m) {}
IOI(const Message& m) : Message(m) {}
IOI(const IOI& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("6"); }
IOI(
const FIX::IOIid& aIOIid,
const FIX::IOITransType& aIOITransType,
const FIX::Symbol& aSymbol,
const FIX::Side& aSide,
const FIX::IOIShares& aIOIShares )
: Message(MsgType())
{
set(aIOIid);
set(aIOITransType);
set(aSymbol);
set(aSide);
set(aIOIShares);
}
FIELD_SET(*this, FIX::IOIid);
FIELD_SET(*this, FIX::IOITransType);
FIELD_SET(*this, FIX::IOIRefID);
FIELD_SET(*this, FIX::Symbol);
FIELD_SET(*this, FIX::SymbolSfx);
FIELD_SET(*this, FIX::SecurityID);
FIELD_SET(*this, FIX::IDSource);
FIELD_SET(*this, FIX::Issuer);
FIELD_SET(*this, FIX::SecurityDesc);
FIELD_SET(*this, FIX::Side);
FIELD_SET(*this, FIX::IOIShares);
FIELD_SET(*this, FIX::Price);
FIELD_SET(*this, FIX::Currency);
FIELD_SET(*this, FIX::ValidUntilTime);
FIELD_SET(*this, FIX::IOIQltyInd);
FIELD_SET(*this, FIX::IOIOthSvc);
FIELD_SET(*this, FIX::IOINaturalFlag);
FIELD_SET(*this, FIX::IOIQualifier);
FIELD_SET(*this, FIX::Text);
};
}
#endif
@@ -0,0 +1,32 @@
#ifndef FIX40_LISTCANCELREQUEST_H
#define FIX40_LISTCANCELREQUEST_H
#include "Message.h"
namespace FIX40
{
class ListCancelRequest : public Message
{
public:
ListCancelRequest() : Message(MsgType()) {}
ListCancelRequest(const FIX::Message& m) : Message(m) {}
ListCancelRequest(const Message& m) : Message(m) {}
ListCancelRequest(const ListCancelRequest& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("K"); }
ListCancelRequest(
const FIX::ListID& aListID )
: Message(MsgType())
{
set(aListID);
}
FIELD_SET(*this, FIX::ListID);
FIELD_SET(*this, FIX::WaveNo);
FIELD_SET(*this, FIX::Text);
};
}
#endif
@@ -0,0 +1,32 @@
#ifndef FIX40_LISTEXECUTE_H
#define FIX40_LISTEXECUTE_H
#include "Message.h"
namespace FIX40
{
class ListExecute : public Message
{
public:
ListExecute() : Message(MsgType()) {}
ListExecute(const FIX::Message& m) : Message(m) {}
ListExecute(const Message& m) : Message(m) {}
ListExecute(const ListExecute& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("L"); }
ListExecute(
const FIX::ListID& aListID )
: Message(MsgType())
{
set(aListID);
}
FIELD_SET(*this, FIX::ListID);
FIELD_SET(*this, FIX::WaveNo);
FIELD_SET(*this, FIX::Text);
};
}
#endif
+47
View File
@@ -0,0 +1,47 @@
#ifndef FIX40_LISTSTATUS_H
#define FIX40_LISTSTATUS_H
#include "Message.h"
namespace FIX40
{
class ListStatus : public Message
{
public:
ListStatus() : Message(MsgType()) {}
ListStatus(const FIX::Message& m) : Message(m) {}
ListStatus(const Message& m) : Message(m) {}
ListStatus(const ListStatus& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("N"); }
ListStatus(
const FIX::ListID& aListID,
const FIX::NoRpts& aNoRpts,
const FIX::RptSeq& aRptSeq )
: Message(MsgType())
{
set(aListID);
set(aNoRpts);
set(aRptSeq);
}
FIELD_SET(*this, FIX::ListID);
FIELD_SET(*this, FIX::WaveNo);
FIELD_SET(*this, FIX::NoRpts);
FIELD_SET(*this, FIX::RptSeq);
FIELD_SET(*this, FIX::NoOrders);
class NoOrders: public FIX::Group
{
public:
NoOrders() : FIX::Group(73,11,FIX::message_order(11,14,84,6,0)) {}
FIELD_SET(*this, FIX::ClOrdID);
FIELD_SET(*this, FIX::CumQty);
FIELD_SET(*this, FIX::CxlQty);
FIELD_SET(*this, FIX::AvgPx);
};
};
}
#endif
@@ -0,0 +1,32 @@
#ifndef FIX40_LISTSTATUSREQUEST_H
#define FIX40_LISTSTATUSREQUEST_H
#include "Message.h"
namespace FIX40
{
class ListStatusRequest : public Message
{
public:
ListStatusRequest() : Message(MsgType()) {}
ListStatusRequest(const FIX::Message& m) : Message(m) {}
ListStatusRequest(const Message& m) : Message(m) {}
ListStatusRequest(const ListStatusRequest& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("M"); }
ListStatusRequest(
const FIX::ListID& aListID )
: Message(MsgType())
{
set(aListID);
}
FIELD_SET(*this, FIX::ListID);
FIELD_SET(*this, FIX::WaveNo);
FIELD_SET(*this, FIX::Text);
};
}
#endif
+35
View File
@@ -0,0 +1,35 @@
#ifndef FIX40_LOGON_H
#define FIX40_LOGON_H
#include "Message.h"
namespace FIX40
{
class Logon : public Message
{
public:
Logon() : Message(MsgType()) {}
Logon(const FIX::Message& m) : Message(m) {}
Logon(const Message& m) : Message(m) {}
Logon(const Logon& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("A"); }
Logon(
const FIX::EncryptMethod& aEncryptMethod,
const FIX::HeartBtInt& aHeartBtInt )
: Message(MsgType())
{
set(aEncryptMethod);
set(aHeartBtInt);
}
FIELD_SET(*this, FIX::EncryptMethod);
FIELD_SET(*this, FIX::HeartBtInt);
FIELD_SET(*this, FIX::RawDataLength);
FIELD_SET(*this, FIX::RawData);
};
}
#endif
+23
View File
@@ -0,0 +1,23 @@
#ifndef FIX40_LOGOUT_H
#define FIX40_LOGOUT_H
#include "Message.h"
namespace FIX40
{
class Logout : public Message
{
public:
Logout() : Message(MsgType()) {}
Logout(const FIX::Message& m) : Message(m) {}
Logout(const Message& m) : Message(m) {}
Logout(const Logout& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("5"); }
FIELD_SET(*this, FIX::Text);
};
}
#endif
+58
View File
@@ -0,0 +1,58 @@
#ifndef FIX40_MESSAGES_H
#define FIX40_MESSAGES_H
#include "../Message.h"
#include "../Group.h"
namespace FIX40
{
class Header : public FIX::Header
{
public:
FIELD_SET(*this, FIX::BeginString);
FIELD_SET(*this, FIX::BodyLength);
FIELD_SET(*this, FIX::MsgType);
FIELD_SET(*this, FIX::SenderCompID);
FIELD_SET(*this, FIX::TargetCompID);
FIELD_SET(*this, FIX::OnBehalfOfCompID);
FIELD_SET(*this, FIX::DeliverToCompID);
FIELD_SET(*this, FIX::SecureDataLen);
FIELD_SET(*this, FIX::SecureData);
FIELD_SET(*this, FIX::MsgSeqNum);
FIELD_SET(*this, FIX::SenderSubID);
FIELD_SET(*this, FIX::TargetSubID);
FIELD_SET(*this, FIX::OnBehalfOfSubID);
FIELD_SET(*this, FIX::DeliverToSubID);
FIELD_SET(*this, FIX::PossDupFlag);
FIELD_SET(*this, FIX::PossResend);
FIELD_SET(*this, FIX::SendingTime);
FIELD_SET(*this, FIX::OrigSendingTime);
};
class Trailer : public FIX::Trailer
{
public:
FIELD_SET(*this, FIX::SignatureLength);
FIELD_SET(*this, FIX::Signature);
FIELD_SET(*this, FIX::CheckSum);
};
class Message : public FIX::Message
{
public:
Message( const FIX::MsgType& msgtype )
: FIX::Message(
FIX::BeginString("FIX.4.0"), msgtype )
{}
Message(const FIX::Message& m) : FIX::Message(m) {}
Message(const Message& m) : FIX::Message(m) {}
Header& getHeader() { return (Header&)m_header; }
const Header& getHeader() const { return (Header&)m_header; }
Trailer& getTrailer() { return (Trailer&)m_trailer; }
const Trailer& getTrailer() const { return (Trailer&)m_trailer; }
};
}
#endif
@@ -0,0 +1,334 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX40_MESSAGECRACKER_H
#define FIX40_MESSAGECRACKER_H
#include "../SessionID.h"
#include "../Exceptions.h"
#include "../fix40/Message.h"
namespace FIX40
{
class Heartbeat;
class TestRequest;
class ResendRequest;
class Reject;
class SequenceReset;
class Logout;
class IOI;
class Advertisement;
class ExecutionReport;
class OrderCancelReject;
class Logon;
class News;
class Email;
class NewOrderSingle;
class NewOrderList;
class OrderCancelRequest;
class OrderCancelReplaceRequest;
class OrderStatusRequest;
class Allocation;
class ListCancelRequest;
class ListExecute;
class ListStatusRequest;
class ListStatus;
class AllocationInstructionAck;
class DontKnowTrade;
class QuoteRequest;
class Quote;
class MessageCracker
{
public:
virtual ~MessageCracker() {}
virtual void onMessage( const Message&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( Message&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( const Heartbeat&, const FIX::SessionID& )
{}
virtual void onMessage( const TestRequest&, const FIX::SessionID& )
{}
virtual void onMessage( const ResendRequest&, const FIX::SessionID& )
{}
virtual void onMessage( const Reject&, const FIX::SessionID& )
{}
virtual void onMessage( const SequenceReset&, const FIX::SessionID& )
{}
virtual void onMessage( const Logout&, const FIX::SessionID& )
{}
virtual void onMessage( const IOI&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( const Advertisement&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( const ExecutionReport&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( const OrderCancelReject&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( const Logon&, const FIX::SessionID& )
{}
virtual void onMessage( const News&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( const Email&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( const NewOrderSingle&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( const NewOrderList&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( const OrderCancelRequest&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( const OrderCancelReplaceRequest&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( const OrderStatusRequest&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( const Allocation&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( const ListCancelRequest&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( const ListExecute&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( const ListStatusRequest&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( const ListStatus&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( const AllocationInstructionAck&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( const DontKnowTrade&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( const QuoteRequest&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( const Quote&, const FIX::SessionID& )
{ throw FIX::UnsupportedMessageType(); }
virtual void onMessage( Heartbeat&, const FIX::SessionID& ) {}
virtual void onMessage( TestRequest&, const FIX::SessionID& ) {}
virtual void onMessage( ResendRequest&, const FIX::SessionID& ) {}
virtual void onMessage( Reject&, const FIX::SessionID& ) {}
virtual void onMessage( SequenceReset&, const FIX::SessionID& ) {}
virtual void onMessage( Logout&, const FIX::SessionID& ) {}
virtual void onMessage( IOI&, const FIX::SessionID& ) {}
virtual void onMessage( Advertisement&, const FIX::SessionID& ) {}
virtual void onMessage( ExecutionReport&, const FIX::SessionID& ) {}
virtual void onMessage( OrderCancelReject&, const FIX::SessionID& ) {}
virtual void onMessage( Logon&, const FIX::SessionID& ) {}
virtual void onMessage( News&, const FIX::SessionID& ) {}
virtual void onMessage( Email&, const FIX::SessionID& ) {}
virtual void onMessage( NewOrderSingle&, const FIX::SessionID& ) {}
virtual void onMessage( NewOrderList&, const FIX::SessionID& ) {}
virtual void onMessage( OrderCancelRequest&, const FIX::SessionID& ) {}
virtual void onMessage( OrderCancelReplaceRequest&, const FIX::SessionID& ) {}
virtual void onMessage( OrderStatusRequest&, const FIX::SessionID& ) {}
virtual void onMessage( Allocation&, const FIX::SessionID& ) {}
virtual void onMessage( ListCancelRequest&, const FIX::SessionID& ) {}
virtual void onMessage( ListExecute&, const FIX::SessionID& ) {}
virtual void onMessage( ListStatusRequest&, const FIX::SessionID& ) {}
virtual void onMessage( ListStatus&, const FIX::SessionID& ) {}
virtual void onMessage( AllocationInstructionAck&, const FIX::SessionID& ) {}
virtual void onMessage( DontKnowTrade&, const FIX::SessionID& ) {}
virtual void onMessage( QuoteRequest&, const FIX::SessionID& ) {}
virtual void onMessage( Quote&, const FIX::SessionID& ) {}
public:
void crack( const Message& message,
const FIX::SessionID& sessionID )
{
const std::string& msgTypeValue
= message.getHeader().getField( FIX::FIELD::MsgType );
if( msgTypeValue == "0" )
onMessage( (const Heartbeat&)message, sessionID );
else
if( msgTypeValue == "1" )
onMessage( (const TestRequest&)message, sessionID );
else
if( msgTypeValue == "2" )
onMessage( (const ResendRequest&)message, sessionID );
else
if( msgTypeValue == "3" )
onMessage( (const Reject&)message, sessionID );
else
if( msgTypeValue == "4" )
onMessage( (const SequenceReset&)message, sessionID );
else
if( msgTypeValue == "5" )
onMessage( (const Logout&)message, sessionID );
else
if( msgTypeValue == "6" )
onMessage( (const IOI&)message, sessionID );
else
if( msgTypeValue == "7" )
onMessage( (const Advertisement&)message, sessionID );
else
if( msgTypeValue == "8" )
onMessage( (const ExecutionReport&)message, sessionID );
else
if( msgTypeValue == "9" )
onMessage( (const OrderCancelReject&)message, sessionID );
else
if( msgTypeValue == "A" )
onMessage( (const Logon&)message, sessionID );
else
if( msgTypeValue == "B" )
onMessage( (const News&)message, sessionID );
else
if( msgTypeValue == "C" )
onMessage( (const Email&)message, sessionID );
else
if( msgTypeValue == "D" )
onMessage( (const NewOrderSingle&)message, sessionID );
else
if( msgTypeValue == "E" )
onMessage( (const NewOrderList&)message, sessionID );
else
if( msgTypeValue == "F" )
onMessage( (const OrderCancelRequest&)message, sessionID );
else
if( msgTypeValue == "G" )
onMessage( (const OrderCancelReplaceRequest&)message, sessionID );
else
if( msgTypeValue == "H" )
onMessage( (const OrderStatusRequest&)message, sessionID );
else
if( msgTypeValue == "J" )
onMessage( (const Allocation&)message, sessionID );
else
if( msgTypeValue == "K" )
onMessage( (const ListCancelRequest&)message, sessionID );
else
if( msgTypeValue == "L" )
onMessage( (const ListExecute&)message, sessionID );
else
if( msgTypeValue == "M" )
onMessage( (const ListStatusRequest&)message, sessionID );
else
if( msgTypeValue == "N" )
onMessage( (const ListStatus&)message, sessionID );
else
if( msgTypeValue == "P" )
onMessage( (const AllocationInstructionAck&)message, sessionID );
else
if( msgTypeValue == "Q" )
onMessage( (const DontKnowTrade&)message, sessionID );
else
if( msgTypeValue == "R" )
onMessage( (const QuoteRequest&)message, sessionID );
else
if( msgTypeValue == "S" )
onMessage( (const Quote&)message, sessionID );
else onMessage( message, sessionID );
}
void crack( Message& message,
const FIX::SessionID& sessionID )
{
FIX::MsgType msgType;
message.getHeader().getField(msgType);
std::string msgTypeValue = msgType.getValue();
if( msgTypeValue == "0" )
onMessage( (Heartbeat&)message, sessionID );
else
if( msgTypeValue == "1" )
onMessage( (TestRequest&)message, sessionID );
else
if( msgTypeValue == "2" )
onMessage( (ResendRequest&)message, sessionID );
else
if( msgTypeValue == "3" )
onMessage( (Reject&)message, sessionID );
else
if( msgTypeValue == "4" )
onMessage( (SequenceReset&)message, sessionID );
else
if( msgTypeValue == "5" )
onMessage( (Logout&)message, sessionID );
else
if( msgTypeValue == "6" )
onMessage( (IOI&)message, sessionID );
else
if( msgTypeValue == "7" )
onMessage( (Advertisement&)message, sessionID );
else
if( msgTypeValue == "8" )
onMessage( (ExecutionReport&)message, sessionID );
else
if( msgTypeValue == "9" )
onMessage( (OrderCancelReject&)message, sessionID );
else
if( msgTypeValue == "A" )
onMessage( (Logon&)message, sessionID );
else
if( msgTypeValue == "B" )
onMessage( (News&)message, sessionID );
else
if( msgTypeValue == "C" )
onMessage( (Email&)message, sessionID );
else
if( msgTypeValue == "D" )
onMessage( (NewOrderSingle&)message, sessionID );
else
if( msgTypeValue == "E" )
onMessage( (NewOrderList&)message, sessionID );
else
if( msgTypeValue == "F" )
onMessage( (OrderCancelRequest&)message, sessionID );
else
if( msgTypeValue == "G" )
onMessage( (OrderCancelReplaceRequest&)message, sessionID );
else
if( msgTypeValue == "H" )
onMessage( (OrderStatusRequest&)message, sessionID );
else
if( msgTypeValue == "J" )
onMessage( (Allocation&)message, sessionID );
else
if( msgTypeValue == "K" )
onMessage( (ListCancelRequest&)message, sessionID );
else
if( msgTypeValue == "L" )
onMessage( (ListExecute&)message, sessionID );
else
if( msgTypeValue == "M" )
onMessage( (ListStatusRequest&)message, sessionID );
else
if( msgTypeValue == "N" )
onMessage( (ListStatus&)message, sessionID );
else
if( msgTypeValue == "P" )
onMessage( (AllocationInstructionAck&)message, sessionID );
else
if( msgTypeValue == "Q" )
onMessage( (DontKnowTrade&)message, sessionID );
else
if( msgTypeValue == "R" )
onMessage( (QuoteRequest&)message, sessionID );
else
if( msgTypeValue == "S" )
onMessage( (Quote&)message, sessionID );
else onMessage( message, sessionID );
}
};
}
#endif
@@ -0,0 +1,84 @@
#ifndef FIX40_NEWORDERLIST_H
#define FIX40_NEWORDERLIST_H
#include "Message.h"
namespace FIX40
{
class NewOrderList : public Message
{
public:
NewOrderList() : Message(MsgType()) {}
NewOrderList(const FIX::Message& m) : Message(m) {}
NewOrderList(const Message& m) : Message(m) {}
NewOrderList(const NewOrderList& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("E"); }
NewOrderList(
const FIX::ListID& aListID,
const FIX::ListSeqNo& aListSeqNo,
const FIX::ListNoOrds& aListNoOrds,
const FIX::ClOrdID& aClOrdID,
const FIX::HandlInst& aHandlInst,
const FIX::Symbol& aSymbol,
const FIX::Side& aSide,
const FIX::OrderQty& aOrderQty,
const FIX::OrdType& aOrdType )
: Message(MsgType())
{
set(aListID);
set(aListSeqNo);
set(aListNoOrds);
set(aClOrdID);
set(aHandlInst);
set(aSymbol);
set(aSide);
set(aOrderQty);
set(aOrdType);
}
FIELD_SET(*this, FIX::ListID);
FIELD_SET(*this, FIX::WaveNo);
FIELD_SET(*this, FIX::ListSeqNo);
FIELD_SET(*this, FIX::ListNoOrds);
FIELD_SET(*this, FIX::ListExecInst);
FIELD_SET(*this, FIX::ClOrdID);
FIELD_SET(*this, FIX::ClientID);
FIELD_SET(*this, FIX::ExecBroker);
FIELD_SET(*this, FIX::Account);
FIELD_SET(*this, FIX::SettlmntTyp);
FIELD_SET(*this, FIX::FutSettDate);
FIELD_SET(*this, FIX::HandlInst);
FIELD_SET(*this, FIX::ExecInst);
FIELD_SET(*this, FIX::MinQty);
FIELD_SET(*this, FIX::MaxFloor);
FIELD_SET(*this, FIX::ExDestination);
FIELD_SET(*this, FIX::ProcessCode);
FIELD_SET(*this, FIX::Symbol);
FIELD_SET(*this, FIX::SymbolSfx);
FIELD_SET(*this, FIX::SecurityID);
FIELD_SET(*this, FIX::IDSource);
FIELD_SET(*this, FIX::Issuer);
FIELD_SET(*this, FIX::SecurityDesc);
FIELD_SET(*this, FIX::PrevClosePx);
FIELD_SET(*this, FIX::Side);
FIELD_SET(*this, FIX::LocateReqd);
FIELD_SET(*this, FIX::OrderQty);
FIELD_SET(*this, FIX::OrdType);
FIELD_SET(*this, FIX::Price);
FIELD_SET(*this, FIX::StopPx);
FIELD_SET(*this, FIX::Currency);
FIELD_SET(*this, FIX::TimeInForce);
FIELD_SET(*this, FIX::ExpireTime);
FIELD_SET(*this, FIX::Commission);
FIELD_SET(*this, FIX::CommType);
FIELD_SET(*this, FIX::Rule80A);
FIELD_SET(*this, FIX::ForexReq);
FIELD_SET(*this, FIX::SettlCurrency);
FIELD_SET(*this, FIX::Text);
};
}
#endif
@@ -0,0 +1,75 @@
#ifndef FIX40_NEWORDERSINGLE_H
#define FIX40_NEWORDERSINGLE_H
#include "Message.h"
namespace FIX40
{
class NewOrderSingle : public Message
{
public:
NewOrderSingle() : Message(MsgType()) {}
NewOrderSingle(const FIX::Message& m) : Message(m) {}
NewOrderSingle(const Message& m) : Message(m) {}
NewOrderSingle(const NewOrderSingle& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("D"); }
NewOrderSingle(
const FIX::ClOrdID& aClOrdID,
const FIX::HandlInst& aHandlInst,
const FIX::Symbol& aSymbol,
const FIX::Side& aSide,
const FIX::OrderQty& aOrderQty,
const FIX::OrdType& aOrdType )
: Message(MsgType())
{
set(aClOrdID);
set(aHandlInst);
set(aSymbol);
set(aSide);
set(aOrderQty);
set(aOrdType);
}
FIELD_SET(*this, FIX::ClOrdID);
FIELD_SET(*this, FIX::ClientID);
FIELD_SET(*this, FIX::ExecBroker);
FIELD_SET(*this, FIX::Account);
FIELD_SET(*this, FIX::SettlmntTyp);
FIELD_SET(*this, FIX::FutSettDate);
FIELD_SET(*this, FIX::HandlInst);
FIELD_SET(*this, FIX::ExecInst);
FIELD_SET(*this, FIX::MinQty);
FIELD_SET(*this, FIX::MaxFloor);
FIELD_SET(*this, FIX::ExDestination);
FIELD_SET(*this, FIX::ProcessCode);
FIELD_SET(*this, FIX::Symbol);
FIELD_SET(*this, FIX::SymbolSfx);
FIELD_SET(*this, FIX::SecurityID);
FIELD_SET(*this, FIX::IDSource);
FIELD_SET(*this, FIX::Issuer);
FIELD_SET(*this, FIX::SecurityDesc);
FIELD_SET(*this, FIX::PrevClosePx);
FIELD_SET(*this, FIX::Side);
FIELD_SET(*this, FIX::LocateReqd);
FIELD_SET(*this, FIX::OrderQty);
FIELD_SET(*this, FIX::OrdType);
FIELD_SET(*this, FIX::Price);
FIELD_SET(*this, FIX::StopPx);
FIELD_SET(*this, FIX::Currency);
FIELD_SET(*this, FIX::IOIid);
FIELD_SET(*this, FIX::QuoteID);
FIELD_SET(*this, FIX::TimeInForce);
FIELD_SET(*this, FIX::ExpireTime);
FIELD_SET(*this, FIX::Commission);
FIELD_SET(*this, FIX::CommType);
FIELD_SET(*this, FIX::Rule80A);
FIELD_SET(*this, FIX::ForexReq);
FIELD_SET(*this, FIX::SettlCurrency);
FIELD_SET(*this, FIX::Text);
};
}
#endif
+38
View File
@@ -0,0 +1,38 @@
#ifndef FIX40_NEWS_H
#define FIX40_NEWS_H
#include "Message.h"
namespace FIX40
{
class News : public Message
{
public:
News() : Message(MsgType()) {}
News(const FIX::Message& m) : Message(m) {}
News(const Message& m) : Message(m) {}
News(const News& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("B"); }
News(
const FIX::LinesOfText& aLinesOfText,
const FIX::Text& aText )
: Message(MsgType())
{
set(aLinesOfText);
set(aText);
}
FIELD_SET(*this, FIX::OrigTime);
FIELD_SET(*this, FIX::Urgency);
FIELD_SET(*this, FIX::RelatdSym);
FIELD_SET(*this, FIX::LinesOfText);
FIELD_SET(*this, FIX::Text);
FIELD_SET(*this, FIX::RawDataLength);
FIELD_SET(*this, FIX::RawData);
};
}
#endif
@@ -0,0 +1,38 @@
#ifndef FIX40_ORDERCANCELREJECT_H
#define FIX40_ORDERCANCELREJECT_H
#include "Message.h"
namespace FIX40
{
class OrderCancelReject : public Message
{
public:
OrderCancelReject() : Message(MsgType()) {}
OrderCancelReject(const FIX::Message& m) : Message(m) {}
OrderCancelReject(const Message& m) : Message(m) {}
OrderCancelReject(const OrderCancelReject& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("9"); }
OrderCancelReject(
const FIX::OrderID& aOrderID,
const FIX::ClOrdID& aClOrdID )
: Message(MsgType())
{
set(aOrderID);
set(aClOrdID);
}
FIELD_SET(*this, FIX::OrderID);
FIELD_SET(*this, FIX::ClOrdID);
FIELD_SET(*this, FIX::ClientID);
FIELD_SET(*this, FIX::ExecBroker);
FIELD_SET(*this, FIX::ListID);
FIELD_SET(*this, FIX::CxlRejReason);
FIELD_SET(*this, FIX::Text);
};
}
#endif
@@ -0,0 +1,75 @@
#ifndef FIX40_ORDERCANCELREPLACEREQUEST_H
#define FIX40_ORDERCANCELREPLACEREQUEST_H
#include "Message.h"
namespace FIX40
{
class OrderCancelReplaceRequest : public Message
{
public:
OrderCancelReplaceRequest() : Message(MsgType()) {}
OrderCancelReplaceRequest(const FIX::Message& m) : Message(m) {}
OrderCancelReplaceRequest(const Message& m) : Message(m) {}
OrderCancelReplaceRequest(const OrderCancelReplaceRequest& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("G"); }
OrderCancelReplaceRequest(
const FIX::OrigClOrdID& aOrigClOrdID,
const FIX::ClOrdID& aClOrdID,
const FIX::HandlInst& aHandlInst,
const FIX::Symbol& aSymbol,
const FIX::Side& aSide,
const FIX::OrderQty& aOrderQty,
const FIX::OrdType& aOrdType )
: Message(MsgType())
{
set(aOrigClOrdID);
set(aClOrdID);
set(aHandlInst);
set(aSymbol);
set(aSide);
set(aOrderQty);
set(aOrdType);
}
FIELD_SET(*this, FIX::OrderID);
FIELD_SET(*this, FIX::ClientID);
FIELD_SET(*this, FIX::ExecBroker);
FIELD_SET(*this, FIX::OrigClOrdID);
FIELD_SET(*this, FIX::ClOrdID);
FIELD_SET(*this, FIX::ListID);
FIELD_SET(*this, FIX::Account);
FIELD_SET(*this, FIX::SettlmntTyp);
FIELD_SET(*this, FIX::FutSettDate);
FIELD_SET(*this, FIX::HandlInst);
FIELD_SET(*this, FIX::ExecInst);
FIELD_SET(*this, FIX::MinQty);
FIELD_SET(*this, FIX::MaxFloor);
FIELD_SET(*this, FIX::ExDestination);
FIELD_SET(*this, FIX::Symbol);
FIELD_SET(*this, FIX::SymbolSfx);
FIELD_SET(*this, FIX::SecurityID);
FIELD_SET(*this, FIX::IDSource);
FIELD_SET(*this, FIX::Issuer);
FIELD_SET(*this, FIX::SecurityDesc);
FIELD_SET(*this, FIX::Side);
FIELD_SET(*this, FIX::OrderQty);
FIELD_SET(*this, FIX::OrdType);
FIELD_SET(*this, FIX::Price);
FIELD_SET(*this, FIX::StopPx);
FIELD_SET(*this, FIX::Currency);
FIELD_SET(*this, FIX::TimeInForce);
FIELD_SET(*this, FIX::ExpireTime);
FIELD_SET(*this, FIX::Commission);
FIELD_SET(*this, FIX::CommType);
FIELD_SET(*this, FIX::Rule80A);
FIELD_SET(*this, FIX::ForexReq);
FIELD_SET(*this, FIX::SettlCurrency);
FIELD_SET(*this, FIX::Text);
};
}
#endif
@@ -0,0 +1,55 @@
#ifndef FIX40_ORDERCANCELREQUEST_H
#define FIX40_ORDERCANCELREQUEST_H
#include "Message.h"
namespace FIX40
{
class OrderCancelRequest : public Message
{
public:
OrderCancelRequest() : Message(MsgType()) {}
OrderCancelRequest(const FIX::Message& m) : Message(m) {}
OrderCancelRequest(const Message& m) : Message(m) {}
OrderCancelRequest(const OrderCancelRequest& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("F"); }
OrderCancelRequest(
const FIX::OrigClOrdID& aOrigClOrdID,
const FIX::ClOrdID& aClOrdID,
const FIX::CxlType& aCxlType,
const FIX::Symbol& aSymbol,
const FIX::Side& aSide,
const FIX::OrderQty& aOrderQty )
: Message(MsgType())
{
set(aOrigClOrdID);
set(aClOrdID);
set(aCxlType);
set(aSymbol);
set(aSide);
set(aOrderQty);
}
FIELD_SET(*this, FIX::OrigClOrdID);
FIELD_SET(*this, FIX::OrderID);
FIELD_SET(*this, FIX::ClOrdID);
FIELD_SET(*this, FIX::ListID);
FIELD_SET(*this, FIX::CxlType);
FIELD_SET(*this, FIX::ClientID);
FIELD_SET(*this, FIX::ExecBroker);
FIELD_SET(*this, FIX::Symbol);
FIELD_SET(*this, FIX::SymbolSfx);
FIELD_SET(*this, FIX::SecurityID);
FIELD_SET(*this, FIX::IDSource);
FIELD_SET(*this, FIX::Issuer);
FIELD_SET(*this, FIX::SecurityDesc);
FIELD_SET(*this, FIX::Side);
FIELD_SET(*this, FIX::OrderQty);
FIELD_SET(*this, FIX::Text);
};
}
#endif
@@ -0,0 +1,42 @@
#ifndef FIX40_ORDERSTATUSREQUEST_H
#define FIX40_ORDERSTATUSREQUEST_H
#include "Message.h"
namespace FIX40
{
class OrderStatusRequest : public Message
{
public:
OrderStatusRequest() : Message(MsgType()) {}
OrderStatusRequest(const FIX::Message& m) : Message(m) {}
OrderStatusRequest(const Message& m) : Message(m) {}
OrderStatusRequest(const OrderStatusRequest& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("H"); }
OrderStatusRequest(
const FIX::ClOrdID& aClOrdID,
const FIX::Symbol& aSymbol,
const FIX::Side& aSide )
: Message(MsgType())
{
set(aClOrdID);
set(aSymbol);
set(aSide);
}
FIELD_SET(*this, FIX::OrderID);
FIELD_SET(*this, FIX::ClOrdID);
FIELD_SET(*this, FIX::ClientID);
FIELD_SET(*this, FIX::ExecBroker);
FIELD_SET(*this, FIX::Symbol);
FIELD_SET(*this, FIX::SymbolSfx);
FIELD_SET(*this, FIX::Issuer);
FIELD_SET(*this, FIX::SecurityDesc);
FIELD_SET(*this, FIX::Side);
};
}
#endif
+46
View File
@@ -0,0 +1,46 @@
#ifndef FIX40_QUOTE_H
#define FIX40_QUOTE_H
#include "Message.h"
namespace FIX40
{
class Quote : public Message
{
public:
Quote() : Message(MsgType()) {}
Quote(const FIX::Message& m) : Message(m) {}
Quote(const Message& m) : Message(m) {}
Quote(const Quote& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("S"); }
Quote(
const FIX::QuoteID& aQuoteID,
const FIX::Symbol& aSymbol,
const FIX::BidPx& aBidPx )
: Message(MsgType())
{
set(aQuoteID);
set(aSymbol);
set(aBidPx);
}
FIELD_SET(*this, FIX::QuoteReqID);
FIELD_SET(*this, FIX::QuoteID);
FIELD_SET(*this, FIX::Symbol);
FIELD_SET(*this, FIX::SymbolSfx);
FIELD_SET(*this, FIX::SecurityID);
FIELD_SET(*this, FIX::IDSource);
FIELD_SET(*this, FIX::Issuer);
FIELD_SET(*this, FIX::SecurityDesc);
FIELD_SET(*this, FIX::BidPx);
FIELD_SET(*this, FIX::OfferPx);
FIELD_SET(*this, FIX::BidSize);
FIELD_SET(*this, FIX::OfferSize);
FIELD_SET(*this, FIX::ValidUntilTime);
};
}
#endif
@@ -0,0 +1,41 @@
#ifndef FIX40_QUOTEREQUEST_H
#define FIX40_QUOTEREQUEST_H
#include "Message.h"
namespace FIX40
{
class QuoteRequest : public Message
{
public:
QuoteRequest() : Message(MsgType()) {}
QuoteRequest(const FIX::Message& m) : Message(m) {}
QuoteRequest(const Message& m) : Message(m) {}
QuoteRequest(const QuoteRequest& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("R"); }
QuoteRequest(
const FIX::QuoteReqID& aQuoteReqID,
const FIX::Symbol& aSymbol )
: Message(MsgType())
{
set(aQuoteReqID);
set(aSymbol);
}
FIELD_SET(*this, FIX::QuoteReqID);
FIELD_SET(*this, FIX::Symbol);
FIELD_SET(*this, FIX::SymbolSfx);
FIELD_SET(*this, FIX::SecurityID);
FIELD_SET(*this, FIX::IDSource);
FIELD_SET(*this, FIX::Issuer);
FIELD_SET(*this, FIX::SecurityDesc);
FIELD_SET(*this, FIX::PrevClosePx);
FIELD_SET(*this, FIX::Side);
FIELD_SET(*this, FIX::OrderQty);
};
}
#endif
+31
View File
@@ -0,0 +1,31 @@
#ifndef FIX40_REJECT_H
#define FIX40_REJECT_H
#include "Message.h"
namespace FIX40
{
class Reject : public Message
{
public:
Reject() : Message(MsgType()) {}
Reject(const FIX::Message& m) : Message(m) {}
Reject(const Message& m) : Message(m) {}
Reject(const Reject& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("3"); }
Reject(
const FIX::RefSeqNum& aRefSeqNum )
: Message(MsgType())
{
set(aRefSeqNum);
}
FIELD_SET(*this, FIX::RefSeqNum);
FIELD_SET(*this, FIX::Text);
};
}
#endif
@@ -0,0 +1,33 @@
#ifndef FIX40_RESENDREQUEST_H
#define FIX40_RESENDREQUEST_H
#include "Message.h"
namespace FIX40
{
class ResendRequest : public Message
{
public:
ResendRequest() : Message(MsgType()) {}
ResendRequest(const FIX::Message& m) : Message(m) {}
ResendRequest(const Message& m) : Message(m) {}
ResendRequest(const ResendRequest& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("2"); }
ResendRequest(
const FIX::BeginSeqNo& aBeginSeqNo,
const FIX::EndSeqNo& aEndSeqNo )
: Message(MsgType())
{
set(aBeginSeqNo);
set(aEndSeqNo);
}
FIELD_SET(*this, FIX::BeginSeqNo);
FIELD_SET(*this, FIX::EndSeqNo);
};
}
#endif
@@ -0,0 +1,31 @@
#ifndef FIX40_SEQUENCERESET_H
#define FIX40_SEQUENCERESET_H
#include "Message.h"
namespace FIX40
{
class SequenceReset : public Message
{
public:
SequenceReset() : Message(MsgType()) {}
SequenceReset(const FIX::Message& m) : Message(m) {}
SequenceReset(const Message& m) : Message(m) {}
SequenceReset(const SequenceReset& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("4"); }
SequenceReset(
const FIX::NewSeqNo& aNewSeqNo )
: Message(MsgType())
{
set(aNewSeqNo);
}
FIELD_SET(*this, FIX::GapFillFlag);
FIELD_SET(*this, FIX::NewSeqNo);
};
}
#endif
@@ -0,0 +1,30 @@
#ifndef FIX40_TESTREQUEST_H
#define FIX40_TESTREQUEST_H
#include "Message.h"
namespace FIX40
{
class TestRequest : public Message
{
public:
TestRequest() : Message(MsgType()) {}
TestRequest(const FIX::Message& m) : Message(m) {}
TestRequest(const Message& m) : Message(m) {}
TestRequest(const TestRequest& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("1"); }
TestRequest(
const FIX::TestReqID& aTestReqID )
: Message(MsgType())
{
set(aTestReqID);
}
FIELD_SET(*this, FIX::TestReqID);
};
}
#endif
@@ -0,0 +1,62 @@
#ifndef FIX41_ADVERTISEMENT_H
#define FIX41_ADVERTISEMENT_H
#include "Message.h"
namespace FIX41
{
class Advertisement : public Message
{
public:
Advertisement() : Message(MsgType()) {}
Advertisement(const FIX::Message& m) : Message(m) {}
Advertisement(const Message& m) : Message(m) {}
Advertisement(const Advertisement& m) : Message(m) {}
static FIX::MsgType MsgType() { return FIX::MsgType("7"); }
Advertisement(
const FIX::AdvId& aAdvId,
const FIX::AdvTransType& aAdvTransType,
const FIX::Symbol& aSymbol,
const FIX::AdvSide& aAdvSide,
const FIX::Shares& aShares )
: Message(MsgType())
{
set(aAdvId);
set(aAdvTransType);
set(aSymbol);
set(aAdvSide);
set(aShares);
}
FIELD_SET(*this, FIX::AdvId);
FIELD_SET(*this, FIX::AdvTransType);
FIELD_SET(*this, FIX::AdvRefID);
FIELD_SET(*this, FIX::Symbol);
FIELD_SET(*this, FIX::SymbolSfx);
FIELD_SET(*this, FIX::SecurityID);
FIELD_SET(*this, FIX::IDSource);
FIELD_SET(*this, FIX::SecurityType);
FIELD_SET(*this, FIX::MaturityMonthYear);
FIELD_SET(*this, FIX::MaturityDay);
FIELD_SET(*this, FIX::PutOrCall);
FIELD_SET(*this, FIX::StrikePrice);
FIELD_SET(*this, FIX::OptAttribute);
FIELD_SET(*this, FIX::SecurityExchange);
FIELD_SET(*this, FIX::Issuer);
FIELD_SET(*this, FIX::SecurityDesc);
FIELD_SET(*this, FIX::AdvSide);
FIELD_SET(*this, FIX::Shares);
FIELD_SET(*this, FIX::Price);
FIELD_SET(*this, FIX::Currency);
FIELD_SET(*this, FIX::TradeDate);
FIELD_SET(*this, FIX::TransactTime);
FIELD_SET(*this, FIX::Text);
FIELD_SET(*this, FIX::URLLink);
FIELD_SET(*this, FIX::LastMkt);
};
}
#endif
Loaded 100 of 671 files, more files were not shown because too many files have changed in this diff. Show more