Skip to content

Commit e581dfb

Browse files
author
loscaz
committed
add prio for call back
1 parent 92ad6d0 commit e581dfb

File tree

7 files changed

+127
-111
lines changed

7 files changed

+127
-111
lines changed

src/plugin/kernel/include/AFCClassMetaModule.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ class AFCClassMetaModule final : public AFIClassMetaModule
4141

4242
bool Load() override;
4343

44-
bool AddClassCallBack(const std::string& class_name, CLASS_EVENT_FUNCTOR&& cb) override;
44+
bool AddClassCallBack(const std::string& class_name, CLASS_EVENT_FUNCTOR&& cb, const int32_t prio) override;
4545

46-
bool DoEvent(const AFGUID& id, const std::string& class_name, const ArkEntityEvent class_event,
46+
bool DoClassEvent(const AFGUID& id, const std::string& class_name, const ArkEntityEvent class_event,
4747
const AFIDataList& args) override;
4848

4949
ARK_SHARE_PTR<AFClassMeta> FindMeta(const std::string& class_name) override;

src/plugin/kernel/include/AFCKernelModule.hpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,25 @@ class AFCKernelModule final : public AFIKernelModule
9494

9595
bool InnerDestroyEntity(ARK_SHARE_PTR<AFIEntity> pEntity);
9696

97-
bool AddClassCallBack(const std::string& class_name, CLASS_EVENT_FUNCTOR&& cb) override;
9897
bool AddEventCallBack(const AFGUID& self, const int event_id, EVENT_PROCESS_FUNCTOR&& cb) override;
99-
bool AddDataCallBack(const std::string& class_name, const std::string& name, DATA_NODE_EVENT_FUNCTOR&& cb) override;
100-
bool AddTableCallBack(
101-
const std::string& class_name, const std::string& name, DATA_TABLE_EVENT_FUNCTOR&& cb) override;
98+
bool AddClassCallBack(const std::string& class_name, CLASS_EVENT_FUNCTOR&& cb, const int32_t prio) override;
99+
bool AddDataCallBack(const std::string& class_name, const std::string& name, DATA_NODE_EVENT_FUNCTOR&& cb,
100+
const int32_t prio) override;
101+
bool AddTableCallBack(const std::string& class_name, const std::string& name, DATA_TABLE_EVENT_FUNCTOR&& cb,
102+
const int32_t prio) override;
102103

103-
bool AddDataCallBack(const std::string& class_name, const uint32_t index, DATA_NODE_EVENT_FUNCTOR&& cb) override;
104-
bool AddTableCallBack(const std::string& class_name, const uint32_t index, DATA_TABLE_EVENT_FUNCTOR&& cb) override;
104+
bool AddDataCallBack(
105+
const std::string& class_name, const uint32_t index, DATA_NODE_EVENT_FUNCTOR&& cb, const int32_t prio) override;
106+
bool AddTableCallBack(const std::string& class_name, const uint32_t index, DATA_TABLE_EVENT_FUNCTOR&& cb,
107+
const int32_t prio) override;
105108

106109
bool AddContainerCallBack(
107-
const std::string& class_name, const uint32_t index, CONTAINER_EVENT_FUNCTOR&& cb) override;
108-
bool AddCommonContainerCallBack(CONTAINER_EVENT_FUNCTOR&& cb) override;
110+
const std::string& class_name, const uint32_t index, CONTAINER_EVENT_FUNCTOR&& cb, const int32_t prio) override;
111+
bool AddCommonContainerCallBack(CONTAINER_EVENT_FUNCTOR&& cb, const int32_t prio) override;
109112

110-
bool AddCommonClassEvent(CLASS_EVENT_FUNCTOR&& cb) override;
111-
bool AddCommonNodeEvent(DATA_NODE_EVENT_FUNCTOR&& cb) override;
112-
bool AddCommonTableEvent(DATA_TABLE_EVENT_FUNCTOR&& cb) override;
113+
bool AddCommonClassEvent(CLASS_EVENT_FUNCTOR&& cb, const int32_t prio) override;
114+
bool AddCommonNodeEvent(DATA_NODE_EVENT_FUNCTOR&& cb, const int32_t prio) override;
115+
bool AddCommonTableEvent(DATA_TABLE_EVENT_FUNCTOR&& cb, const int32_t prio) override;
113116

114117
// convert db data and entity
115118
bool EntityToDBData(ARK_SHARE_PTR<AFIEntity> pEntity, AFMsg::pb_db_entity& pb_data);

src/plugin/kernel/include/AFClassCallBackManager.hpp

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,97 +31,94 @@ class AFClassCallBackManager final
3131
{
3232
private:
3333
// class event list
34-
AFList<CLASS_EVENT_FUNCTOR> class_events_;
34+
std::multimap<int32_t, CLASS_EVENT_FUNCTOR> class_events_;
3535

3636
// data call backs list
37-
using DataCallBacks = std::vector<DATA_NODE_EVENT_FUNCTOR>;
37+
using DataCallBacks = std::multimap<int32_t, DATA_NODE_EVENT_FUNCTOR>;
3838
AFHashmap<uint32_t, DataCallBacks> data_call_backs_list_;
3939

4040
// table call backs list
41-
using TableCallBacks = std::vector<DATA_TABLE_EVENT_FUNCTOR>;
41+
using TableCallBacks = std::multimap<int32_t, DATA_TABLE_EVENT_FUNCTOR>;
4242
AFHashmap<uint32_t, TableCallBacks> table_call_backs_list_;
4343

4444
// container call backs list
45-
using ContainerCallBacks = std::vector<CONTAINER_EVENT_FUNCTOR>;
45+
using ContainerCallBacks = std::multimap<int32_t, CONTAINER_EVENT_FUNCTOR>;
4646
AFHashmap<uint32_t, ContainerCallBacks> container_call_backs_list_;
4747

4848
public:
4949
explicit AFClassCallBackManager() = default;
5050

51-
virtual ~AFClassCallBackManager()
52-
{
53-
class_events_.clear();
54-
}
51+
virtual ~AFClassCallBackManager() = default;
5552

56-
bool AddClassCallBack(CLASS_EVENT_FUNCTOR&& cb)
53+
bool AddClassCallBack(CLASS_EVENT_FUNCTOR&& cb, const int32_t prio)
5754
{
58-
class_events_.emplace_back(std::forward<CLASS_EVENT_FUNCTOR>(cb));
55+
class_events_.insert(std::make_pair(prio, std::forward<CLASS_EVENT_FUNCTOR>(cb)));
5956
return true;
6057
}
6158

62-
bool AddDataCallBack(const uint32_t index, DATA_NODE_EVENT_FUNCTOR&& cb)
59+
bool AddDataCallBack(const uint32_t index, DATA_NODE_EVENT_FUNCTOR&& cb, const int32_t prio)
6360
{
6461
auto iter = data_call_backs_list_.find(index);
6562
if (iter == data_call_backs_list_.end())
6663
{
6764
DataCallBacks* pDataCBs = ARK_NEW DataCallBacks;
6865
ARK_ASSERT_RET_VAL(pDataCBs != nullptr, false);
6966

70-
pDataCBs->push_back(std::forward<DATA_NODE_EVENT_FUNCTOR>(cb));
67+
pDataCBs->insert(std::make_pair(prio, std::forward<DATA_NODE_EVENT_FUNCTOR>(cb)));
7168
data_call_backs_list_.insert(index, pDataCBs);
7269
}
7370
else
7471
{
75-
iter->second->push_back(cb);
72+
iter->second->insert(std::make_pair(prio, std::forward<DATA_NODE_EVENT_FUNCTOR>(cb)));
7673
}
7774

7875
return true;
7976
}
8077

81-
bool AddTableCallBack(const uint32_t index, DATA_TABLE_EVENT_FUNCTOR&& cb)
78+
bool AddTableCallBack(const uint32_t index, DATA_TABLE_EVENT_FUNCTOR&& cb, const int32_t prio)
8279
{
8380
auto iter = table_call_backs_list_.find(index);
8481
if (iter == table_call_backs_list_.end())
8582
{
8683
TableCallBacks* pTableCBs = ARK_NEW TableCallBacks;
8784
ARK_ASSERT_RET_VAL(pTableCBs != nullptr, false);
8885

89-
pTableCBs->push_back(std::forward<DATA_TABLE_EVENT_FUNCTOR>(cb));
86+
pTableCBs->insert(std::make_pair(prio, std::forward<DATA_TABLE_EVENT_FUNCTOR>(cb)));
9087
table_call_backs_list_.insert(index, pTableCBs);
9188
}
9289
else
9390
{
94-
iter->second->push_back(cb);
91+
iter->second->insert(std::make_pair(prio, std::forward<DATA_TABLE_EVENT_FUNCTOR>(cb)));
9592
}
9693

9794
return true;
9895
}
9996

100-
bool AddContainerCallBack(const uint32_t index, CONTAINER_EVENT_FUNCTOR&& cb)
97+
bool AddContainerCallBack(const uint32_t index, CONTAINER_EVENT_FUNCTOR&& cb, const int32_t prio)
10198
{
10299
auto iter = container_call_backs_list_.find(index);
103100
if (iter == container_call_backs_list_.end())
104101
{
105102
ContainerCallBacks* pContainerCBs = ARK_NEW ContainerCallBacks;
106103
ARK_ASSERT_RET_VAL(pContainerCBs != nullptr, false);
107104

108-
pContainerCBs->push_back(std::forward<CONTAINER_EVENT_FUNCTOR>(cb));
105+
pContainerCBs->insert(std::make_pair(prio, std::forward<CONTAINER_EVENT_FUNCTOR>(cb)));
109106
container_call_backs_list_.insert(index, pContainerCBs);
110107
}
111108
else
112109
{
113-
iter->second->push_back(cb);
110+
iter->second->insert(std::make_pair(prio, std::forward<CONTAINER_EVENT_FUNCTOR>(cb)));
114111
}
115112

116113
return true;
117114
}
118115

119-
bool DoEvent(
116+
bool OnClassEvent(
120117
const AFGUID& id, const std::string& class_name, const ArkEntityEvent eClassEvent, const AFIDataList& valueList)
121118
{
122-
for (auto iter : class_events_)
119+
for (auto& iter : class_events_)
123120
{
124-
iter(id, class_name, eClassEvent, valueList);
121+
iter.second(id, class_name, eClassEvent, valueList);
125122
}
126123

127124
return true;
@@ -136,9 +133,9 @@ class AFClassCallBackManager final
136133
return false;
137134
}
138135

139-
for (auto& cb : *data_call_backs)
136+
for (auto& iter : *data_call_backs)
140137
{
141-
cb(self, name, index, old_data, new_data);
138+
iter.second(self, name, index, old_data, new_data);
142139
}
143140

144141
return true;
@@ -153,9 +150,9 @@ class AFClassCallBackManager final
153150
return false;
154151
}
155152

156-
for (auto& cb : *table_call_backs)
153+
for (auto& iter : *table_call_backs)
157154
{
158-
cb(id, event_data, old_data, new_data);
155+
iter.second(id, event_data, old_data, new_data);
159156
}
160157

161158
return true;
@@ -170,9 +167,9 @@ class AFClassCallBackManager final
170167
return false;
171168
}
172169

173-
for (auto& cb : *container_call_backs)
170+
for (auto& iter : *container_call_backs)
174171
{
175-
cb(self, index, op_type, src_index, dest_index);
172+
iter.second(self, index, op_type, src_index, dest_index);
176173
}
177174

178175
return true;

src/plugin/kernel/interface/AFIClassMetaModule.hpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,9 @@ class AFIClassMetaModule : public AFIModule
3333
public:
3434
virtual bool Load() = 0;
3535

36-
template<typename BaseType>
37-
bool AddClassCallBack(const std::string& class_name, BaseType* pBase,
38-
int (BaseType::*handler)(const AFGUID&, const std::string&, const ArkEntityEvent, const AFIDataList&))
39-
{
40-
return AddClassCallBack(
41-
class_name, std::make_shared<CLASS_EVENT_FUNCTOR>(std::bind(handler, pBase, std::placeholders::_1,
42-
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)));
43-
}
44-
45-
virtual bool AddClassCallBack(const std::string& class_name, CLASS_EVENT_FUNCTOR&& cb) = 0;
46-
47-
virtual bool DoEvent(
36+
virtual bool AddClassCallBack(const std::string& class_name, CLASS_EVENT_FUNCTOR&& cb, const int32_t prio) = 0;
37+
38+
virtual bool DoClassEvent(
4839
const AFGUID& id, const std::string& class_name, const ArkEntityEvent class_event, const AFIDataList& args) = 0;
4940

5041
virtual ARK_SHARE_PTR<AFClassMeta> FindMeta(const std::string& class_name) = 0;

0 commit comments

Comments
 (0)