-
Notifications
You must be signed in to change notification settings - Fork 207
/
Copy pathccapi_fix_connection.h
70 lines (69 loc) · 1.95 KB
/
ccapi_fix_connection.h
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef INCLUDE_CCAPI_CPP_CCAPI_FIX_CONNECTION_H_
#define INCLUDE_CCAPI_CPP_CCAPI_FIX_CONNECTION_H_
#include <string>
#include "ccapi_cpp/ccapi_logger.h"
#include "ccapi_cpp/ccapi_subscription.h"
namespace beast = boost::beast;
namespace ccapi {
/**
* This class represents a TCP socket connection for the FIX API.
*/
template <class T>
class FixConnection CCAPI_FINAL {
public:
FixConnection(std::string host, std::string port, Subscription subscription, std::shared_ptr<T> streamPtr)
: host(host), port(port), subscription(subscription), streamPtr(streamPtr) {
this->id = subscription.getCorrelationId();
this->url = host + ":" + port;
}
std::string toString() const {
std::ostringstream oss;
oss << streamPtr;
std::string output = "FixConnection [id = " + id + ", host = " + host + ", port = " + port + ", subscription = " + ccapi::toString(subscription) +
", status = " + statusToString(status) + ", streamPtr = " + oss.str() + "]";
return output;
}
enum class Status {
UNKNOWN,
CONNECTING,
OPEN,
FAILED,
CLOSING,
CLOSED,
};
static std::string statusToString(Status status) {
std::string output;
switch (status) {
case Status::UNKNOWN:
output = "UNKNOWN";
break;
case Status::CONNECTING:
output = "CONNECTING";
break;
case Status::OPEN:
output = "OPEN";
break;
case Status::FAILED:
output = "FAILED";
break;
case Status::CLOSING:
output = "CLOSING";
break;
case Status::CLOSED:
output = "CLOSED";
break;
default:
CCAPI_LOGGER_FATAL(CCAPI_UNSUPPORTED_VALUE);
}
return output;
}
std::string id;
std::string host;
std::string port;
std::string url;
Subscription subscription;
Status status{Status::UNKNOWN};
std::shared_ptr<T> streamPtr;
};
} /* namespace ccapi */
#endif // INCLUDE_CCAPI_CPP_CCAPI_FIX_CONNECTION_H_