forked from ChunelFeng/CGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGElementManager.cpp
More file actions
150 lines (106 loc) · 3.31 KB
/
GElementManager.cpp
File metadata and controls
150 lines (106 loc) · 3.31 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/***************************
@Author: Chunel
@Contact: chunel@foxmail.com
@File: GElementManager.cpp
@Time: 2021/6/2 10:33 下午
@Desc:
***************************/
#include "GElementManager.h"
CGRAPH_NAMESPACE_BEGIN
GElementManager::GElementManager() {
engine_ = nullptr;
}
GElementManager::~GElementManager() {
/**
* manager中的节点,在析构的时候不需要释放。
* 所有的节点信息在GPipeLine类中统一申请和释放
*/
CGRAPH_DELETE_PTR(engine_)
}
CStatus GElementManager::init() {
CGRAPH_FUNCTION_BEGIN
/** 首先判定,注册的element全部不为空 */
for (auto element : manager_elements_) {
CGRAPH_ASSERT_NOT_NULL(element)
}
status = initEngine();
CGRAPH_FUNCTION_CHECK_STATUS
for (GElementPtr element : manager_elements_) {
status = element->fatProcessor(CFunctionType::INIT);
CGRAPH_FUNCTION_CHECK_STATUS
element->is_init_ = true;
}
CGRAPH_FUNCTION_END
}
CStatus GElementManager::destroy() {
CGRAPH_FUNCTION_BEGIN
for (GElementPtr element : manager_elements_) {
status = element->fatProcessor(CFunctionType::DESTROY);
CGRAPH_FUNCTION_CHECK_STATUS
element->is_init_ = false;
}
CGRAPH_DELETE_PTR(engine_)
CGRAPH_FUNCTION_END
}
CStatus GElementManager::run() {
CGRAPH_FUNCTION_BEGIN
CGRAPH_ASSERT_NOT_NULL(engine_)
status = engine_->run(); // 通过引擎来执行全部的逻辑
CGRAPH_FUNCTION_CHECK_STATUS
status = engine_->afterRunCheck();
CGRAPH_FUNCTION_END
}
CStatus GElementManager::add(GElementPtr element) {
CGRAPH_FUNCTION_BEGIN
CGRAPH_ASSERT_NOT_NULL(element)
this->manager_elements_.emplace(element);
CGRAPH_FUNCTION_END
}
CBool GElementManager::find(GElementPtr element) const {
if (nullptr == element) {
return false;
}
return manager_elements_.end() != manager_elements_.find(element);
}
CStatus GElementManager::remove(GElementPtr element) {
CGRAPH_FUNCTION_BEGIN
CGRAPH_ASSERT_NOT_NULL(element)
manager_elements_.erase(element);
CGRAPH_FUNCTION_END
}
CStatus GElementManager::clear() {
CGRAPH_FUNCTION_BEGIN
for (auto element : manager_elements_) {
CGRAPH_DELETE_PTR(element)
}
manager_elements_.clear();
CGRAPH_FUNCTION_END
}
GElementManagerPtr GElementManager::setScheduleStrategy(int strategy) {
CGRAPH_ASSERT_NOT_NULL_RETURN_NULL(engine_)
engine_->schedule_strategy_ = strategy;
return this;
}
GElementManagerPtr GElementManager::setEngineType(GEngineType engineType) {
engine_type_ = engineType;
return this;
}
CStatus GElementManager::initEngine() {
CGRAPH_FUNCTION_BEGIN
CGRAPH_DELETE_PTR(engine_)
switch (engine_type_) {
case GEngineType::STATIC : engine_ = CGRAPH_SAFE_MALLOC_COBJECT(GStaticEngine) break;
case GEngineType::DYNAMIC : engine_ = CGRAPH_SAFE_MALLOC_COBJECT(GDynamicEngine) break;
default: status = CStatus("unknown engine type");
}
CGRAPH_FUNCTION_CHECK_STATUS
engine_->thread_pool_ = thread_pool_;
status = engine_->setup(manager_elements_);
CGRAPH_FUNCTION_END
}
GElementManagerPtr GElementManager::setThreadPool(UThreadPoolPtr ptr) {
CGRAPH_ASSERT_NOT_NULL_RETURN_NULL(ptr)
this->thread_pool_ = ptr;
return this;
}
CGRAPH_NAMESPACE_END