-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
55 lines (42 loc) · 1.58 KB
/
main.cpp
File metadata and controls
55 lines (42 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "Logger.h"
#include "Order.h"
#include "NetworkInterface.h"
#include "MatchingEngine.h"
#include <thread>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <stdexcept>
// Function to initialize critical components
void initializeSystem(MatchingEngine& engine, NetworkInterface& network) {
Logger::getInstance().log("Initializing critical components...");
// Pre-warm the matching engine with a dummy order
Logger::getInstance().log("Pre-warming matching engine...");
Order dummyOrder(0, 'B', 0.0, 0, 0, 0, false); // Dummy order
engine.processOrder(dummyOrder);
// Pre-warm the network interface
Logger::getInstance().log("Pre-warming network interface...");
network.prepareSocket(); // Ensure the socket is ready
Logger::getInstance().log("Critical components initialized...");
}
int main() {
try {
Logger::getInstance().log("Starting the Order Matching System...");
MatchingEngine engine;
NetworkInterface network(8080);
Logger::getInstance().log("Initializing network interface on port 8080...");
// Initialize critical components
initializeSystem(engine, network);
// Run network interface in a separate thread
std::thread networkThread([&]() {
network.receiveOrders(engine);
});
networkThread.join();
Logger::getInstance().log("Shutting down the system.");
return 0;
} catch (const std::exception& e) {
Logger::getInstance().log(std::string("Error: ") + e.what());
return 1;
}
}