forked from ChunelFeng/CGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGEventManager.cpp
More file actions
90 lines (68 loc) · 2.18 KB
/
GEventManager.cpp
File metadata and controls
90 lines (68 loc) · 2.18 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
/***************************
@Author: Chunel
@Contact: chunel@foxmail.com
@File: GEventManager.cpp
@Time: 2023/1/20 23:08
@Desc:
***************************/
#include "GEventManager.h"
CGRAPH_NAMESPACE_BEGIN
CStatus GEventManager::init() {
CGRAPH_FUNCTION_BEGIN
for (auto& iter : events_map_) {
// fatInit 中包含了init(),和部分其他逻辑
status += (iter.second)->fatInit();
}
CGRAPH_FUNCTION_END
}
CStatus GEventManager::destroy() {
CGRAPH_FUNCTION_BEGIN
for (auto& iter : events_map_) {
status += (iter.second)->fatDestroy();
}
CGRAPH_FUNCTION_END
}
CStatus GEventManager::clear() {
CGRAPH_FUNCTION_BEGIN
for (auto& iter : events_map_) {
CGRAPH_DELETE_PTR(iter.second)
}
events_map_.clear();
CGRAPH_FUNCTION_END
}
CStatus GEventManager::trigger(const std::string &key, GEventType type, GEventAsyncStrategy strategy) {
CGRAPH_FUNCTION_BEGIN
auto result = events_map_.find(key);
CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION(events_map_.end() == result,
"event key [" + key + "] no find")
auto event = result->second;
CGRAPH_ASSERT_NOT_NULL(event)
status = event->process(type, strategy);
CGRAPH_FUNCTION_END
}
std::shared_future<CVoid> GEventManager::asyncTrigger(const std::string &key, GEventAsyncStrategy strategy) {
auto result = events_map_.find(key);
CGRAPH_THROW_EXCEPTION_BY_CONDITION(events_map_.end() == result || !result->second,
"event key [" + key + "] no find");
auto event = result->second;
return event->asyncProcess(strategy);
}
GEventObjectPtr GEventManager::setThreadPool(UThreadPoolPtr ptr) {
CGRAPH_ASSERT_NOT_NULL_THROW_ERROR(ptr)
for (auto& iter : events_map_) {
CGRAPH_ASSERT_NOT_NULL_THROW_ERROR(iter.second)
(iter.second)->setThreadPool(ptr);
}
return this;
}
GEventManager::~GEventManager() {
clear();
}
CStatus GEventManager::reset() {
CGRAPH_FUNCTION_BEGIN
for (auto& iter : events_map_) {
iter.second->asyncWait(GEventAsyncStrategy::PIPELINE_RUN_FINISH);
}
CGRAPH_FUNCTION_END
}
CGRAPH_NAMESPACE_END