Index  Source Files  Annotated Class List  Alphabetical Class List  Class Hierarchy  Graphical Class Hierarchy   
 

/home/orenmnero/autobuild/quickfix/src/C++/SessionFactory.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Copyright (c) quickfixengine.org  All rights reserved.
00003 **
00004 ** This file is part of the QuickFIX FIX Engine
00005 **
00006 ** This file may be distributed under the terms of the quickfixengine.org
00007 ** license as defined by quickfixengine.org and appearing in the file
00008 ** LICENSE included in the packaging of this file.
00009 **
00010 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00011 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00012 **
00013 ** See http://www.quickfixengine.org/LICENSE for licensing information.
00014 **
00015 ** Contact ask@quickfixengine.org if any conditions of this licensing are
00016 ** not clear to you.
00017 **
00018 ****************************************************************************/
00019 
00020 #ifdef _MSC_VER
00021 #include "stdafx.h"
00022 #else
00023 #include "config.h"
00024 #endif
00025 #include "CallStack.h"
00026 
00027 #include "SessionFactory.h"
00028 #include "SessionSettings.h"
00029 #include "Session.h"
00030 
00031 namespace FIX
00032 {
00033 SessionFactory::~SessionFactory()
00034 { QF_STACK_IGNORE_BEGIN
00035   Dictionaries::iterator i = m_dictionaries.begin();
00036   for ( ; i != m_dictionaries.end(); ++i )
00037     delete i->second;
00038   QF_STACK_IGNORE_END
00039 }
00040 
00041 Session* SessionFactory::create( const SessionID& sessionID,
00042                                  const Dictionary& settings ) throw( ConfigError )
00043 { QF_STACK_PUSH(SessionFactory::create)
00044 
00045   std::string connectionType = settings.getString( CONNECTION_TYPE );
00046   if ( connectionType != "acceptor" && connectionType != "initiator" )
00047     throw ConfigError( "Invalid ConnectionType" );
00048 
00049   if( connectionType == "acceptor" && settings.has(SESSION_QUALIFIER) )
00050     throw ConfigError( "SessionQualifier cannot be used with acceptor." );
00051 
00052   bool useDataDictionary = true;
00053   if ( settings.has( USE_DATA_DICTIONARY ) )
00054     useDataDictionary = settings.getBool( USE_DATA_DICTIONARY );
00055 
00056   DataDictionary dataDictionary;
00057   if ( useDataDictionary )
00058   {
00059     std::string path = settings.getString( DATA_DICTIONARY );
00060     Dictionaries::iterator i = m_dictionaries.find( path );
00061     if ( i != m_dictionaries.end() )
00062       dataDictionary = *i->second;
00063     else
00064     {
00065       DataDictionary* p = new DataDictionary( path );
00066       dataDictionary = *p;
00067       m_dictionaries[ path ] = p;
00068     }
00069   }
00070 
00071   if( settings.has( VALIDATE_FIELDS_OUT_OF_ORDER ) )
00072   {
00073     dataDictionary.checkFieldsOutOfOrder
00074     ( settings.getBool( VALIDATE_FIELDS_OUT_OF_ORDER ) );
00075   }
00076   if( settings.has( VALIDATE_FIELDS_HAVE_VALUES ) )
00077   {
00078     dataDictionary.checkFieldsHaveValues
00079     ( settings.getBool( VALIDATE_FIELDS_HAVE_VALUES ) );
00080   }
00081   if( settings.has( VALIDATE_USER_DEFINED_FIELDS ) )
00082   {
00083     dataDictionary.checkUserDefinedFields
00084     ( settings.getBool( VALIDATE_USER_DEFINED_FIELDS ) );
00085   }    
00086 
00087   UtcTimeOnly startTime;
00088   UtcTimeOnly endTime;
00089   try
00090   {
00091     startTime = UtcTimeOnlyConvertor::convert
00092                 ( settings.getString( START_TIME ) );
00093     endTime = UtcTimeOnlyConvertor::convert
00094               ( settings.getString( END_TIME ) );
00095   }
00096   catch ( FieldConvertError & e ) { throw ConfigError( e.what() ); }
00097 
00098   int startDay = -1;
00099   int endDay = -1;
00100 
00101   try
00102   {
00103     startDay = settings.getDay( START_DAY );
00104     endDay = settings.getDay( END_DAY );
00105   }
00106   catch( ConfigError & ) {}
00107   catch( FieldConvertError & e ) { throw ConfigError( e.what() ); }
00108 
00109   if( startDay >= 0 && endDay < 0 )
00110     throw ConfigError( "StartDay used without EndDay" );
00111   if( endDay >= 0 && startDay < 0 )
00112     throw ConfigError( "EndDay used without StartDay" );
00113 
00114   HeartBtInt heartBtInt( 0 );
00115   if ( connectionType == "initiator" )
00116   {
00117     heartBtInt = HeartBtInt( settings.getLong( HEARTBTINT ) );
00118     if ( heartBtInt <= 0 ) throw ConfigError( "Heartbeat must be greater than zero" );
00119   }
00120 
00121   Session* pSession = 0;
00122   pSession = new Session( m_application, m_messageStoreFactory,
00123                           sessionID, dataDictionary,
00124                           SessionTime(startTime, endTime, startDay, endDay),
00125                           heartBtInt, m_pLogFactory );
00126 
00127   if ( settings.has( CHECK_COMPID ) )
00128     pSession->checkCompId( settings.getBool( CHECK_COMPID ) );
00129   if ( settings.has( CHECK_LATENCY ) )
00130     pSession->checkLatency( settings.getBool( CHECK_LATENCY ) );
00131   if ( settings.has( MAX_LATENCY ) )
00132     pSession->setMaxLatency( settings.getLong( MAX_LATENCY ) );
00133   if ( settings.has( LOGON_TIMEOUT ) )
00134     pSession->setLogonTimeout( settings.getLong( LOGON_TIMEOUT ) );
00135   if ( settings.has( LOGOUT_TIMEOUT ) )
00136     pSession->setLogoutTimeout( settings.getLong( LOGOUT_TIMEOUT ) );
00137   if ( settings.has( RESET_ON_LOGON ) )
00138     pSession->setResetOnLogon( settings.getBool( RESET_ON_LOGON ) );
00139   if ( settings.has( RESET_ON_LOGOUT ) )
00140     pSession->setResetOnLogout( settings.getBool( RESET_ON_LOGOUT ) );
00141   if ( settings.has( RESET_ON_DISCONNECT ) )
00142     pSession->setResetOnDisconnect( settings.getBool( RESET_ON_DISCONNECT ) );
00143   if ( settings.has( REFRESH_ON_LOGON ) )
00144     pSession->setRefreshOnLogon( settings.getBool( REFRESH_ON_LOGON ) );
00145   if ( settings.has( MILLISECONDS_IN_TIMESTAMP ) )
00146     pSession->setMillisecondsInTimeStamp( settings.getBool( MILLISECONDS_IN_TIMESTAMP ) );
00147 
00148   return pSession;
00149 
00150   QF_STACK_POP
00151 }
00152 }

Generated on Mon Jul 24 19:36:30 2006 for QuickFIX by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2001