192 lines
7.9 KiB
C++
192 lines
7.9 KiB
C++
#pragma once
|
|
/*
|
|
* Copyright Onix Solutions Limited [OnixS]. All rights reserved.
|
|
*
|
|
* This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
|
|
* and international copyright treaties.
|
|
*
|
|
* Access to and use of the software is governed by the terms of the applicable OnixS Software
|
|
* Services Agreement (the Agreement) and Customer end user license agreements granting
|
|
* a non-assignable, non-transferable and non-exclusive license to use the software
|
|
* for it's own data processing purposes under the terms defined in the Agreement.
|
|
*
|
|
* Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
|
|
* of this source code or associated reference material to any other location for further reproduction
|
|
* or redistribution, and any amendments to this copyright notice, are expressly prohibited.
|
|
*
|
|
* Any reproduction or redistribution for sale or hiring of the Software not in accordance with
|
|
* the terms of the Agreement is a violation of copyright law.
|
|
*/
|
|
|
|
#include <string>
|
|
#include <set>
|
|
#include <vector>
|
|
|
|
#include <OnixS/FIXEngine/Compiler.h>
|
|
#include <OnixS/FIXEngine/FIX/Timestamp.h>
|
|
#include <OnixS/FIXEngine/FIX/Dictionary.h>
|
|
|
|
namespace OnixS {
|
|
namespace FIX {
|
|
ONIXS_FIXENGINE_API_DECL(class, IEngineListener);
|
|
ONIXS_FIXENGINE_API_DECL(class, ISessionReactor);
|
|
ONIXS_FIXENGINE_API_DECL(class, EngineSettings);
|
|
|
|
typedef std::vector<OnixS::FIX::Dictionary> Dictionaries;
|
|
typedef std::vector<int> ListenPorts;
|
|
|
|
/// The FIX Engine.
|
|
class ONIXS_FIXENGINE_API Engine
|
|
{
|
|
public:
|
|
/// Initializes the FIX Engine.
|
|
///
|
|
/// @param listenPort The engine listens on this port for incoming connections.
|
|
/// If '0' then only session-initiators can be created.
|
|
/// If '-1' then the telecommunication level is disabled and only the message parsing/assembling can be used.
|
|
/// @param stack An instance of an externally managed reactor for acceptor sessions.
|
|
///
|
|
/// @note This call is thread-safe.
|
|
static Engine * init(int listenPort = 0, ISessionReactor * stack = ONIXS_FIXENGINE_NULLPTR);
|
|
|
|
/// Initializes the FIX Engine.
|
|
///
|
|
/// @param configFile The configuration file.
|
|
/// @param stack An instance of an externally managed reactor for acceptor sessions.
|
|
///
|
|
/// @note This call is thread-safe.
|
|
static Engine * init(const std::string & configFile, ISessionReactor * stack = ONIXS_FIXENGINE_NULLPTR);
|
|
|
|
/// Initializes the FIX Engine.
|
|
///
|
|
/// @param configuration The configuration string.
|
|
/// @param stack An instance of an externally managed reactor for acceptor sessions.
|
|
///
|
|
/// @note This call is thread-safe.
|
|
static Engine * initFromString(const std::string & configuration, ISessionReactor * stack = ONIXS_FIXENGINE_NULLPTR);
|
|
|
|
/// Initializes the FIX Engine.
|
|
///
|
|
/// @param settings Engine settings.
|
|
/// @param stack An instance of an externally managed reactor for acceptor sessions.
|
|
///
|
|
/// @note This call is thread-safe.
|
|
static Engine * init(const EngineSettings & settings, ISessionReactor * stack = ONIXS_FIXENGINE_NULLPTR);
|
|
|
|
/// Logs the given user's message to FIX Engine's log file.
|
|
///
|
|
/// @note This call is thread-safe.
|
|
void log(const std::string & message);
|
|
|
|
/// Shutdowns the FIX Engine and releases all resources.
|
|
///
|
|
/// @note This call is thread-safe.
|
|
static void shutdown();
|
|
|
|
/// Returns the Engine instance.
|
|
///
|
|
/// @throw The OnixS::DomainException if the FIX Engine has not been initialized yet.
|
|
///
|
|
/// @note This call is thread-safe.
|
|
static Engine * instance();
|
|
|
|
/// Returns 'true' if the FIX Engine has been initialized, otherwise - 'false'.
|
|
///
|
|
/// @note This call is thread-safe.
|
|
static bool initialized();
|
|
|
|
/// Returns the listen port.
|
|
///
|
|
/// The FIX Engine listens on this port for incoming connections.
|
|
int listenPort() const;
|
|
|
|
/// Returns the Engine log directory.
|
|
///
|
|
/// Inbound and outbound FIX messages, session's state data,
|
|
/// and the FIX Engine log file are stored in this directory.
|
|
const std::string & logDirectory() const;
|
|
|
|
/// Returns the Engine's license expiration date.
|
|
Timestamp licenseExpirationDate() const;
|
|
|
|
/// Returns the array of loaded dictionaries.
|
|
Dictionaries dictionaries() const;
|
|
|
|
/// Adds the session level dictionary(s) from the XML file(s) with the description of the FIX Dictionary(s).
|
|
/// @note More than one file could be specified. The symbol '|' is used as the file name delimiter.
|
|
/// @param dictionaryFile Specifies the path(s) to the XML file(s) with the description of the FIX Dictionary(s).
|
|
/// @throw The OnixS::DomainException if there are standard dictionary(s) in the XML file(s).
|
|
///
|
|
/// @note This call is thread-safe.
|
|
void addSessionDictionary(const std::string & dictionaryFile);
|
|
|
|
/// Adds the session level dictionary(s) from the plain text string with the description of the FIX Dictionary(s).
|
|
/// @param dialectString Specifies the plain text string with the description of the FIX Dictionary(s).
|
|
/// @throw The OnixS::DomainException if there are standard dictionary(s) in the dialect string.
|
|
///
|
|
/// @note This call is thread-safe.
|
|
void addSessionDictionaryFromString(const std::string & dialectString);
|
|
|
|
/// Adds the listen port(s) for incoming connections.
|
|
/// @throw An exception if the FIX Engine cannot start listening on the specified port(s) or the telecommunication level is disabled (the Listen Port is -1 or 0).
|
|
///
|
|
/// @note This call is thread-safe.
|
|
void addListenPort(int port);
|
|
void addListenPorts(const ListenPorts & ports);
|
|
|
|
/// Removes the listen port(s) for incoming connections.
|
|
/// @throw An exception if the telecommunication level is disabled (the Listen Port is -1 or 0).
|
|
///
|
|
/// @note This call is thread-safe.
|
|
void removeListenPort(int port);
|
|
void removeListenPorts(const ListenPorts & ports);
|
|
|
|
/// Adds the ssl listen port(s) for incoming ssl connections.
|
|
/// @throw An exception if the FIX Engine cannot start listening on the specified ssl port(s) or the telecommunication level is disabled (the Listen Port is -1 or 0).
|
|
///
|
|
/// @note This call is thread-safe.
|
|
void addSslListenPort(int port);
|
|
void addSslListenPorts(const ListenPorts & ports);
|
|
|
|
/// Removes the ssl listen port(s) for incoming ssl connections.
|
|
/// @throw An exception if the telecommunication level is disabled (the Listen Port is -1 or 0).
|
|
///
|
|
/// @note This call is thread-safe.
|
|
void removeSslListenPort(int port);
|
|
void removeSslListenPorts(const ListenPorts & ports);
|
|
|
|
/// Registers the Engine listener.
|
|
/// @throw An exception if the listener is already registered.
|
|
///
|
|
/// @note This call is thread-safe.
|
|
void registerListener(IEngineListener * listener);
|
|
|
|
/// Unregisters the Engine listener.
|
|
///
|
|
/// @note This call is thread-safe.
|
|
void unregisterListener();
|
|
|
|
/// Performs the synchronization of the high-resolution internal time service with the system time on the Windows OS.
|
|
/// On OSes less than Windows 8 and Windows Server 2012, the internal high-resolution time service, is based on the QueryPerformanceCounter API.
|
|
/// This service is synchronized with the system time only once when an application is started, as a result, a time difference can occur in time.
|
|
/// Therefore, for such old windows versions, it makes sense to synchronize the internal time service periodically (e.g. once per day) with the system time to avoid time drift issues.
|
|
///
|
|
/// @throw An exception if there is a session in the non-disconnected state.
|
|
///
|
|
/// @note This call is thread-safe.
|
|
/// @note The method should be called when all sessions are disconnected to avoid time resynchronization side effects.
|
|
void synchronizeHighResolutionTimeServiceWithSystemTime();
|
|
|
|
/// Returns the current Engine-level settings.
|
|
const EngineSettings & settings() const;
|
|
|
|
class Impl;
|
|
|
|
private:
|
|
Engine();
|
|
~Engine();
|
|
};
|
|
|
|
}
|
|
}
|