FIX 4.0 Demo 1.0
Loading...
Searching...
No Matches
application.hpp
Go to the documentation of this file.
1
9#pragma once
10
11#include <string>
12#include <functional>
13#include "fix/fix_codec.hpp"
14
15namespace fix40 {
16
17// 前置声明
18class Session;
19class IStore;
20
28struct SessionID {
29 std::string senderCompID;
30 std::string targetCompID;
31
35 SessionID() = default;
36
42 SessionID(const std::string& sender, const std::string& target)
43 : senderCompID(sender), targetCompID(target) {}
44
49 std::string to_string() const {
50 return senderCompID + "->" + targetCompID;
51 }
52
56 bool operator==(const SessionID& other) const {
57 return senderCompID == other.senderCompID &&
59 }
60
64 bool operator!=(const SessionID& other) const {
65 return !(*this == other);
66 }
67};
68
117public:
121 virtual ~Application() = default;
122
123 // =========================================================================
124 // 生命周期回调
125 // =========================================================================
126
136 virtual void onLogon(const SessionID& sessionID) = 0;
137
147 virtual void onLogout(const SessionID& sessionID) = 0;
148
149 // =========================================================================
150 // 业务消息回调
151 // =========================================================================
152
167 virtual void fromApp(const FixMessage& msg, const SessionID& sessionID) = 0;
168
183 virtual void toApp(FixMessage& msg, const SessionID& sessionID) {
184 (void)msg;
185 (void)sessionID;
186 }
187
188 // =========================================================================
189 // 管理消息回调(可选)
190 // =========================================================================
191
202 virtual void fromAdmin(const FixMessage& msg, const SessionID& sessionID) {
203 (void)msg;
204 (void)sessionID;
205 }
206
215 virtual void toAdmin(FixMessage& msg, const SessionID& sessionID) {
216 (void)msg;
217 (void)sessionID;
218 }
219
220 // =========================================================================
221 // 可选:持久化能力探测
222 // =========================================================================
223
233 virtual IStore* getStore() const { return nullptr; }
234};
235
236} // namespace fix40
FIX 应用层抽象接口
Definition application.hpp:116
virtual void onLogout(const SessionID &sessionID)=0
会话登出回调
virtual void toApp(FixMessage &msg, const SessionID &sessionID)
发送业务消息前回调
Definition application.hpp:183
virtual void toAdmin(FixMessage &msg, const SessionID &sessionID)
发送管理消息前回调
Definition application.hpp:215
virtual void onLogon(const SessionID &sessionID)=0
会话登录成功回调
virtual void fromApp(const FixMessage &msg, const SessionID &sessionID)=0
收到业务消息回调
virtual IStore * getStore() const
获取持久化存储接口(可选)
Definition application.hpp:233
virtual ~Application()=default
虚析构函数
virtual void fromAdmin(const FixMessage &msg, const SessionID &sessionID)
收到管理消息回调
Definition application.hpp:202
FIX 消息的面向对象封装
Definition fix_codec.hpp:46
存储接口
Definition store.hpp:61
FIX 消息编解码器
Definition matching_engine.hpp:23
FIX 会话标识符
Definition application.hpp:28
SessionID(const std::string &sender, const std::string &target)
构造会话标识符
Definition application.hpp:42
SessionID()=default
默认构造函数
bool operator!=(const SessionID &other) const
不等比较
Definition application.hpp:64
std::string targetCompID
接收方标识符
Definition application.hpp:30
std::string to_string() const
转换为字符串表示
Definition application.hpp:49
bool operator==(const SessionID &other) const
相等比较
Definition application.hpp:56
std::string senderCompID
发送方标识符
Definition application.hpp:29