Line data Source code
1 : /**
2 : Copyright (c) 2020 Roman Katuntsev <sbkarr@stappler.org>
3 : Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
4 :
5 : Permission is hereby granted, free of charge, to any person obtaining a copy
6 : of this software and associated documentation files (the "Software"), to deal
7 : in the Software without restriction, including without limitation the rights
8 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 : copies of the Software, and to permit persons to whom the Software is
10 : furnished to do so, subject to the following conditions:
11 :
12 : The above copyright notice and this permission notice shall be included in
13 : all copies or substantial portions of the Software.
14 :
15 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 : THE SOFTWARE.
22 : **/
23 :
24 : #include "XLEventHeader.h"
25 : #include "XLEvent.h"
26 :
27 : namespace STAPPLER_VERSIONIZED stappler::xenolith {
28 :
29 : struct EventList {
30 5544 : static EventList *getInstance() {
31 : static EventList *instance = nullptr;
32 5544 : if (!instance) {
33 15 : instance = new EventList();
34 : }
35 5544 : return instance;
36 : }
37 :
38 251 : uint32_t addEventHeader(const EventHeader *header) {
39 251 : _knownEvents.insert(header);
40 251 : return (uint32_t)_knownEvents.size();
41 : }
42 :
43 5293 : void removeEventHeader(const EventHeader *header) {
44 5293 : _knownEvents.erase(header);
45 5293 : }
46 :
47 : Set<const EventHeader *> _knownEvents;
48 : };
49 :
50 11 : EventHeader::Category EventHeader::getCategoryForName(StringView catName) {
51 11 : return string::hash32(catName);
52 : }
53 :
54 251 : EventHeader::EventHeader(Category cat, StringView name)
55 251 : : _category(cat), _name(name) {
56 251 : assert(!name.empty());
57 251 : _id = EventList::getInstance()->addEventHeader(this);
58 251 : }
59 :
60 251 : EventHeader::EventHeader(StringView catName, StringView eventName)
61 251 : : EventHeader(string::hash32(catName), eventName) { }
62 :
63 5031 : EventHeader::EventHeader(const EventHeader &other) : _category(other._category), _id(other._id), _name(other._name) { }
64 11 : EventHeader::EventHeader(EventHeader &&other) : _category(other._category), _id(other._id), _name(std::move(other._name)) { }
65 :
66 10 : EventHeader &EventHeader::operator=(const EventHeader &other) {
67 10 : _category = other._category;
68 10 : _id = other._id;
69 10 : _name = other._name;
70 10 : return *this;
71 : }
72 11 : EventHeader &EventHeader::operator=(EventHeader &&other) {
73 11 : _category = other._category;
74 11 : _id = other._id;
75 11 : _name = std::move(other._name);
76 11 : return *this;
77 : }
78 :
79 5293 : EventHeader::~EventHeader() {
80 5293 : EventList::getInstance()->removeEventHeader(this);
81 5293 : }
82 :
83 22 : EventHeader::Category EventHeader::getCategory() const {
84 22 : return _category;
85 : }
86 :
87 4882 : EventHeader::EventID EventHeader::getEventID() const {
88 4882 : return _id;
89 : }
90 :
91 11 : StringView EventHeader::getName() const {
92 11 : return _name;
93 : }
94 :
95 11 : bool EventHeader::isInCategory(EventHeader::Category cat) const {
96 11 : return cat == _category;
97 : }
98 :
99 10 : EventHeader::operator int() {
100 10 : return _id;
101 : }
102 :
103 11 : bool EventHeader::operator == (const Event &event) const {
104 11 : return event.getEventID() == _id;
105 : }
106 :
107 2249 : void EventHeader::send(Ref *object, int64_t value) const {
108 2249 : Event::send(*this, object, value);
109 2249 : }
110 11 : void EventHeader::send(Ref *object, double value) const {
111 11 : Event::send(*this, object, value);
112 11 : }
113 123 : void EventHeader::send(Ref *object, bool value) const {
114 123 : Event::send(*this, object, value);
115 123 : }
116 11 : void EventHeader::send(Ref *object, Ref *value) const {
117 11 : Event::send(*this, object, value);
118 11 : }
119 10 : void EventHeader::send(Ref *object, const char *value) const {
120 10 : Event::send(*this, object, value);
121 10 : }
122 26 : void EventHeader::send(Ref *object, const String &value) const {
123 26 : Event::send(*this, object, value);
124 26 : }
125 11 : void EventHeader::send(Ref *object, const StringView &value) const {
126 11 : Event::send(*this, object, value);
127 11 : }
128 11 : void EventHeader::send(Ref *object, const Value &value) const {
129 11 : Event::send(*this, object, value);
130 11 : }
131 60 : void EventHeader::send(Ref *object) const {
132 60 : Event::send(*this, object);
133 60 : }
134 :
135 : }
|