diff --git a/src/GraphCtrl/GraphAspect/GAspectManager.h b/src/GraphCtrl/GraphAspect/GAspectManager.h index d342c335..b4a966ea 100644 --- a/src/GraphCtrl/GraphAspect/GAspectManager.h +++ b/src/GraphCtrl/GraphAspect/GAspectManager.h @@ -52,11 +52,13 @@ class GAspectManager : public GAspectObject, CGRAPH_NO_ALLOWED_COPY(GAspectManager) private: - GAspectPtrArr aspect_arr_; // 存储aspect的容器 + GAspectPtrArr aspect_arr_ {}; // 存储aspect的容器 friend class GElement; friend class CAllocator; friend class GElementManager; + friend class GStorage; + friend struct _GElementStorage; }; using GAspectManagerPtr = GAspectManager *; diff --git a/src/GraphCtrl/GraphElement/GElement.h b/src/GraphCtrl/GraphElement/GElement.h index 1068ef42..be8ef3c9 100644 --- a/src/GraphCtrl/GraphElement/GElement.h +++ b/src/GraphCtrl/GraphElement/GElement.h @@ -504,8 +504,8 @@ class GElement : public GElementObject, friend class GSeparateOptimizer; friend class GElementRepository; friend class GPerf; - friend class _GElementStorage; friend class GStorage; + friend struct _GElementStorage; CGRAPH_DECLARE_GPARAM_MANAGER_WRAPPER_WITH_MEMBER CGRAPH_DECLARE_GEVENT_MANAGER_WRAPPER_WITH_MEMBER diff --git a/src/GraphCtrl/GraphPipeline/_GStroage/GStorage.cpp b/src/GraphCtrl/GraphPipeline/_GStroage/GStorage.cpp index 3330ee06..dc7c254c 100644 --- a/src/GraphCtrl/GraphPipeline/_GStroage/GStorage.cpp +++ b/src/GraphCtrl/GraphPipeline/_GStroage/GStorage.cpp @@ -17,6 +17,15 @@ CGRAPH_NAMESPACE_BEGIN CGRAPH_INTERNAL_NAMESPACE_BEGIN +UREFL_CREATE_STRUCT_TRAIT_INFO(_GEventStorage, + UREFL_DECLARE_FIELD(_GEventStorage, key_, 1), + UREFL_DECLARE_FIELD(_GEventStorage, event_clz_name_, 2) +) + +UREFL_CREATE_STRUCT_TRAIT_INFO(_GAspectStorage, + UREFL_DECLARE_FIELD(_GAspectStorage, aspect_clz_name_, 1) +) + UREFL_CREATE_STRUCT_TRAIT_INFO(_GElementStorage, UREFL_DECLARE_FIELD(_GElementStorage, name_, 1), UREFL_DECLARE_FIELD(_GElementStorage, loop_, 2), @@ -31,12 +40,8 @@ UREFL_CREATE_STRUCT_TRAIT_INFO(_GElementStorage, UREFL_DECLARE_FIELD(_GElementStorage, clz_name_, 11), UREFL_DECLARE_FIELD(_GElementStorage, belong_session_, 12), UREFL_DECLARE_FIELD(_GElementStorage, element_type_, 13), - UREFL_DECLARE_FIELD(_GElementStorage, children_, 14) -) - -UREFL_CREATE_STRUCT_TRAIT_INFO(_GEventStorage, - UREFL_DECLARE_FIELD(_GEventStorage, key_, 1), - UREFL_DECLARE_FIELD(_GEventStorage, event_clz_name_, 2) + UREFL_DECLARE_FIELD(_GElementStorage, children_, 14), + UREFL_DECLARE_FIELD(_GElementStorage, aspect_storages_, 15) ) UREFL_CREATE_STRUCT_TRAIT_INFO(UThreadPoolConfig, @@ -194,6 +199,9 @@ CStatus GStorage::loadElement(GPipelinePtr pipeline, const _GPipelineStorage& st } else { element->belong_ = eleCache[cur.belong_session_]; } + + status += loadAspect(element, cur.aspect_storages_); + CGRAPH_FUNCTION_CHECK_STATUS } // 设定依赖关系 @@ -221,15 +229,34 @@ CStatus GStorage::loadElement(GPipelinePtr pipeline, const _GPipelineStorage& st } +CStatus GStorage::loadAspect(GElementPtr element, const std::vector<_GAspectStorage>& aspStorages) { + CGRAPH_FUNCTION_BEGIN + CGRAPH_ASSERT_NOT_NULL(element) + + if (!aspStorages.empty()) { + element->aspect_manager_ = CAllocator::safeMallocCObject(); + for (const auto &gas: aspStorages) { + GAspectPtr aspect = dynamic_cast(GStorageFactory::createByType(gas.aspect_clz_name_)); + CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION(!aspect, + gas.aspect_clz_name_ + " type create aspect failed."); + element->aspect_manager_->add(aspect); + } + } + + CGRAPH_FUNCTION_END +} + + CStatus GStorage::loadEvent(GPipelinePtr pipeline, const _GPipelineStorage& storage) { CGRAPH_FUNCTION_BEGIN CGRAPH_ASSERT_NOT_NULL(pipeline, pipeline->event_manager_, pipeline->param_manager_) + // 为了确保每个 event 中都可以获取参数信息 pipeline->event_manager_->param_manager_ = pipeline->param_manager_; - for (const auto& es : storage.event_storages_) { - GEventPtr event = dynamic_cast(GStorageFactory::createByType(es.event_clz_name_)); + for (const auto& ges : storage.event_storages_) { + GEventPtr event = dynamic_cast(GStorageFactory::createByType(ges.event_clz_name_)); CGRAPH_ASSERT_NOT_NULL(event) - pipeline->event_manager_->events_map_[es.key_] = event; + pipeline->event_manager_->events_map_[ges.key_] = event; } CGRAPH_FUNCTION_END diff --git a/src/GraphCtrl/GraphPipeline/_GStroage/GStorage.h b/src/GraphCtrl/GraphPipeline/_GStroage/GStorage.h index 4d811c16..a313fee1 100644 --- a/src/GraphCtrl/GraphPipeline/_GStroage/GStorage.h +++ b/src/GraphCtrl/GraphPipeline/_GStroage/GStorage.h @@ -17,6 +17,7 @@ CGRAPH_NAMESPACE_BEGIN class GPipeline; +class GElement; class GStorage : public GraphObject { protected: @@ -54,6 +55,8 @@ class GStorage : public GraphObject { static CStatus loadEvent(GPipeline* pipeline, const _GPipelineStorage& storage); + static CStatus loadAspect(GElementPtr element, const std::vector<_GAspectStorage>& aspStorages); + friend class GPipeline; }; diff --git a/src/GraphCtrl/GraphPipeline/_GStroage/GStorageDefine.h b/src/GraphCtrl/GraphPipeline/_GStroage/GStorageDefine.h index 72bd6845..7e731f42 100644 --- a/src/GraphCtrl/GraphPipeline/_GStroage/GStorageDefine.h +++ b/src/GraphCtrl/GraphPipeline/_GStroage/GStorageDefine.h @@ -19,6 +19,26 @@ CGRAPH_NAMESPACE_BEGIN +struct _GEventStorage : public CStruct { + explicit _GEventStorage() = default; + explicit _GEventStorage(const std::string& key, const std::string& clz) { + key_ = key; + event_clz_name_ = clz; + } + + std::string key_ {}; + std::string event_clz_name_ {}; +}; + +struct _GAspectStorage : public CStruct { + explicit _GAspectStorage() = default; + explicit _GAspectStorage(const std::string& clz) { + aspect_clz_name_ = clz; + } + + std::string aspect_clz_name_ {}; +}; + struct _GElementStorage : public CStruct { std::string name_ {}; CSize loop_ { CGRAPH_DEFAULT_LOOP_TIMES }; @@ -34,6 +54,7 @@ struct _GElementStorage : public CStruct { std::string clz_name_ {}; // 记录element 的真实类型信息 std::vector dependence_sessions_ {}; std::vector<_GElementStorage> children_ {}; + std::vector<_GAspectStorage> aspect_storages_ {}; explicit _GElementStorage() = default; @@ -56,6 +77,11 @@ struct _GElementStorage : public CStruct { for (const auto* child : element->getChildren()) { children_.emplace_back(child); } + if (element->aspect_manager_) { + for (const auto* aspect : element->aspect_manager_->aspect_arr_) { + aspect_storages_.emplace_back(typeid(*aspect).name()); + } + } } /** @@ -83,17 +109,6 @@ struct _GElementStorage : public CStruct { friend class GStorage; }; -struct _GEventStorage : public CStruct { - explicit _GEventStorage() = default; - explicit _GEventStorage(const std::string& key, const std::string& clz) { - key_ = key; - event_clz_name_ = clz; - } - - std::string key_ {}; - std::string event_clz_name_ {}; -}; - struct _GPipelineStorage : public CStruct { std::vector<_GElementStorage> element_storages_ {}; // 记录pipeline中所有 element 的信息 std::vector<_GEventStorage> event_storages_ {}; // 记录pipeline中所有 event 的信息 diff --git a/src/GraphCtrl/GraphPipeline/_GStroage/GStorageFactory.h b/src/GraphCtrl/GraphPipeline/_GStroage/GStorageFactory.h index 500f1baf..4c2bb9ad 100644 --- a/src/GraphCtrl/GraphPipeline/_GStroage/GStorageFactory.h +++ b/src/GraphCtrl/GraphPipeline/_GStroage/GStorageFactory.h @@ -20,6 +20,7 @@ class GEvent; class GParam; class GDaemon; class GStage; +class GAspect; class GStorageFactory : public GraphObject { public: @@ -32,6 +33,7 @@ class GStorageFactory : public GraphObject { c_enable_if_t::value || std::is_base_of::value || std::is_base_of::value + || std::is_base_of::value || std::is_base_of::value || std::is_base_of::value, int> = 0> static CVoid registerMetaType() { @@ -56,10 +58,8 @@ class GStorageFactory : public GraphObject { friend class GStorage; }; - #define CGRAPH_REGISTER_META_TYPE(_CLZ) GStorageFactory::registerMetaType<_CLZ>(); \ - CGRAPH_NAMESPACE_END #endif //CGRAPH_GSTORAGEFACTORY_H