BetaTrader
A HFT Eco-System
Loading...
Searching...
No Matches
FixSessionManager.h
Go to the documentation of this file.
1#pragma once
2
4#include <cstdint>
5#include <mutex>
6#include <string>
7#include <unordered_map>
8#include <vector>
10
11namespace fix {
12
14 public:
15 // Optional repository for sequence persistence
17
18 // Load valid clients provided by the database config
19 void loadConfig(const std::vector<std::string>& validClients);
20
21 // Attempts to authenticate a Logon request.
22 // Returns true if SenderCompID is valid.
23 bool authenticate(uint32_t sessionId, const std::string& senderCompId);
24
25 // Validates an incoming sequence number.
26 // Returns true if strictly next expected, false if gap or too low.
27 bool validateSequence(uint32_t sessionId, uint32_t incomingSeqNum);
28
29 // Handle a Logout request (marks session offline, preserves mapping for ack).
30 void handleLogout(uint32_t sessionId);
31
32 // Cleans up the connection-to-CompID mapping after the logout ack has been sent.
33 void cleanupConnection(uint32_t sessionId);
34
35 // Get current session state (returns nullptr if session not found)
36 SessionState* getSessionState(uint32_t sessionId);
37
42 uint32_t useNextOutboundSequence(uint32_t sessionId);
43
47 void incrementOutboundSequence(uint32_t sessionId);
48
49
51 std::unordered_map<std::string, SessionState> getAllSessionStates() const;
52
54 std::mutex& getMutex() { return mMutex; }
55
56
57 private:
58 mutable std::mutex mMutex;
59 std::unordered_map<std::string, bool> mValidClients;
60 // States keyed by SenderCompID
61 std::unordered_map<std::string, SessionState> mSessionStates;
62 // Mapping of active connection ID to its authenticated CompID
63 std::unordered_map<uint32_t, std::string> mConnectionToCompId;
65 };
66
67
68} // namespace fix
Repository for managing sequence numbers.
Definition SequenceRepository.h:23
Definition FixSessionManager.h:13
void cleanupConnection(uint32_t sessionId)
Definition FixSessionManager.cpp:103
std::unordered_map< std::string, SessionState > mSessionStates
Definition FixSessionManager.h:61
void handleLogout(uint32_t sessionId)
Definition FixSessionManager.cpp:86
bool validateSequence(uint32_t sessionId, uint32_t incomingSeqNum)
Definition FixSessionManager.cpp:53
void incrementOutboundSequence(uint32_t sessionId)
Increments the outbound sequence number without returning it.
Definition FixSessionManager.cpp:139
bool authenticate(uint32_t sessionId, const std::string &senderCompId)
Definition FixSessionManager.cpp:19
std::mutex & getMutex()
Returns a reference to the internal mutex for external synchronization.
Definition FixSessionManager.h:54
uint32_t useNextOutboundSequence(uint32_t sessionId)
Increments and persists the outbound sequence number.
Definition FixSessionManager.cpp:120
std::unordered_map< uint32_t, std::string > mConnectionToCompId
Definition FixSessionManager.h:63
std::mutex mMutex
Definition FixSessionManager.h:58
SessionState * getSessionState(uint32_t sessionId)
Definition FixSessionManager.cpp:108
void loadConfig(const std::vector< std::string > &validClients)
Definition FixSessionManager.cpp:10
std::unordered_map< std::string, SessionState > getAllSessionStates() const
Returns a thread-safe snapshot of all session states.
Definition FixSessionManager.cpp:143
::data::SequenceRepository * mSeqRepo
Definition FixSessionManager.h:64
std::unordered_map< std::string, bool > mValidClients
Definition FixSessionManager.h:59
Definition BusinessMessageReject.h:12
Definition SessionState.h:7