-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpub_sub.h
More file actions
80 lines (72 loc) · 1.82 KB
/
pub_sub.h
File metadata and controls
80 lines (72 loc) · 1.82 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
#ifndef CASINO_PUB_SUB_H
#define CASINO_PUB_SUB_H
#include <sstream>
#include <string>
#include <time.h>
namespace casino {
namespace pub_sub {
enum EventType {
UNKNOWN,
ROLLING,
BETTING,
DISPENSING,
MONEY_WON,
MONEY_LOST,
BET_PLACED
};
class Event {
public:
time_t live_till;
EventType event_type;
std::string desc;
int int_data;
double double_data;
Event()
: live_till(0)
, event_type(UNKNOWN)
, desc("")
, int_data(0)
, double_data(0)
{
}
Event(time_t lt, EventType et)
: live_till(lt)
, event_type(et)
, desc("")
, int_data(0)
, double_data(0)
{
}
Event(time_t lt, EventType et, std::string de, int id, double dd)
: live_till(lt)
, event_type(et)
, desc(de)
, int_data(id)
, double_data(dd)
{
}
std::string to_string() const
{
char timeStr[100];
strftime(timeStr, sizeof(timeStr), "%Y%m%d:%T:%Z", localtime(&live_till));
std::stringstream ss;
ss << "EventType: " << event_type
<< ", LiveTill: " << std::string(timeStr)
<< ", Description: " << desc
<< ", Double-Data: " << double_data
<< ", Integer-Data: " << int_data;
return ss.str();
}
};
class Subscriber {
public:
virtual void accept(Event) = 0;
};
class Publisher {
public:
virtual void subscribe(Subscriber*) = 0;
virtual void unsubscribe(Subscriber*) = 0;
};
} // namespace pub_sub
} // namespace casino
#endif // CASINO_PUB_SUB_H