-
Notifications
You must be signed in to change notification settings - Fork 236
Expand file tree
/
Copy pathccapi_event.h
More file actions
117 lines (98 loc) · 3.65 KB
/
Copy pathccapi_event.h
File metadata and controls
117 lines (98 loc) · 3.65 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#pragma once
#include <vector>
#include "ccapi_cpp/ccapi_logger.h"
#include "ccapi_cpp/ccapi_message.h"
namespace ccapi {
/**
** A single event resulting from a subscription or a request. Event objects are created by the API and passed to the application either through a registered
*EventHandler or EventQueue. Event objects contain Message objects which can be accessed using the getMessageList() function. The Event object is a handle to an
*event. The event is the basic unit of work provided to applications. Each Event object consists of an Type attribute and zero or more Message objects.
*/
class Event {
public:
enum class Type {
UNKNOWN,
SESSION_STATUS,
SUBSCRIPTION_STATUS,
REQUEST_STATUS,
RESPONSE,
SUBSCRIPTION_DATA,
AUTHORIZATION_STATUS,
FIX,
FIX_STATUS,
HEARTBEAT,
};
static std::string typeToString(Type type) {
std::string output;
switch (type) {
case Type::UNKNOWN:
output = "UNKNOWN";
break;
case Type::SESSION_STATUS:
output = "SESSION_STATUS";
break;
case Type::SUBSCRIPTION_STATUS:
output = "SUBSCRIPTION_STATUS";
break;
case Type::REQUEST_STATUS:
output = "REQUEST_STATUS";
break;
case Type::RESPONSE:
output = "RESPONSE";
break;
case Type::SUBSCRIPTION_DATA:
output = "SUBSCRIPTION_DATA";
break;
case Type::AUTHORIZATION_STATUS:
output = "AUTHORIZATION_STATUS";
break;
case Type::FIX:
output = "FIX";
break;
case Type::FIX_STATUS:
output = "FIX_STATUS";
break;
case Type::HEARTBEAT:
output = "HEARTBEAT";
break;
default:
CCAPI_LOGGER_FATAL(CCAPI_UNSUPPORTED_VALUE);
}
return output;
}
std::string toString() const {
std::string output = "Event [type = " + typeToString(type) + ", messageList = " + ccapi::toString(messageList) + "]";
return output;
}
std::string toPrettyString(const int space = 2, const int leftToIndent = 0, const bool indentFirstLine = true) const {
std::string sl(leftToIndent, ' ');
std::string ss(leftToIndent + space, ' ');
std::string output = (indentFirstLine ? sl : "") + "Event [\n" + ss + "type = " + typeToString(type) + ",\n" + ss +
"messageList = " + ccapi::toPrettyString(messageList, space, leftToIndent + space, false) + "\n" + sl + "]";
return output;
}
const std::vector<Message>& getMessageList() const { return messageList; }
void addMessages(const std::vector<Message>& newMessageList) {
this->messageList.insert(std::end(this->messageList), std::begin(newMessageList), std::end(newMessageList));
}
void addMessages(std::vector<Message>& newMessageList) {
if (this->messageList.empty()) {
this->messageList = std::move(newMessageList);
} else {
this->messageList.reserve(this->messageList.size() + newMessageList.size());
std::move(std::begin(newMessageList), std::end(newMessageList), std::back_inserter(this->messageList));
}
}
void addMessage(const Message& newMessage) { this->messageList.push_back(newMessage); }
void addMessage(Message& newMessage) { this->messageList.emplace_back(std::move(newMessage)); }
void setMessageList(const std::vector<Message>& messageList) { this->messageList = messageList; }
void setMessageList(std::vector<Message>& messageList) { this->messageList = std::move(messageList); }
Type getType() const { return type; }
void setType(Type type) { this->type = type; }
#ifndef CCAPI_EXPOSE_INTERNAL
private:
#endif
Type type{Type::UNKNOWN};
std::vector<Message> messageList;
};
} /* namespace ccapi */