Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ CStatus GDynamicEngine::setup(const GSortedGElementPtrSet& elements) {


CStatus GDynamicEngine::run() {
cur_status_.reset();
prepareRun();

switch (dag_type_) {
case internal::GEngineDagType::COMMON:
Expand Down Expand Up @@ -207,13 +207,6 @@ CVoid GDynamicEngine::fatWait() {
*/
return (finished_end_size_ >= total_end_size_) || cur_status_.isErr();
});

// 状态异常的情况下刷新所有element,避免错误的中间状态被带入下一次process
if (unlikely(cur_status_.isErr())) {
for (auto* element : total_element_arr_) {
element->refresh();
}
}
}


Expand Down Expand Up @@ -307,4 +300,15 @@ CVoid GDynamicEngine::serialRunAll() {
}
}


CVoid GDynamicEngine::prepareRun() {
if (unlikely(!cur_status_.isOK())) {
// 状态异常的情况下刷新所有element,避免错误的中间状态被带入下一次process
for (auto* element : total_element_arr_) {
element->refresh();
}
cur_status_.reset();
}
}

CGRAPH_NAMESPACE_END
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ class GDynamicEngine : public GEngine {
*/
CVoid serialRunAll();

/**
* 执行运行前的准备工作
* @return
*/
CVoid prepareRun();

private:
GElementPtrArr total_element_arr_ {}; // pipeline中所有的元素信息集合
GElementPtrArr front_element_arr_ {}; // 没有依赖的元素信息
Expand Down
24 changes: 23 additions & 1 deletion src/GraphCtrl/GraphPipeline/_GStroage/GStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ UREFL_CREATE_STRUCT_TRAIT_INFO(_GParamStorage,
UREFL_DECLARE_FIELD(_GParamStorage, clz_name_, 2)
)

UREFL_CREATE_STRUCT_TRAIT_INFO(_GPassedParamStorage,
UREFL_DECLARE_FIELD(_GPassedParamStorage, key_, 1),
UREFL_DECLARE_FIELD(_GPassedParamStorage, clz_name_, 2)
)

UREFL_CREATE_STRUCT_TRAIT_INFO(_GElementStorage,
UREFL_DECLARE_FIELD(_GElementStorage, name_, 1),
UREFL_DECLARE_FIELD(_GElementStorage, loop_, 2),
Expand All @@ -57,7 +62,8 @@ UREFL_CREATE_STRUCT_TRAIT_INFO(_GElementStorage,
UREFL_DECLARE_FIELD(_GElementStorage, belong_session_, 12),
UREFL_DECLARE_FIELD(_GElementStorage, element_type_, 13),
UREFL_DECLARE_FIELD(_GElementStorage, children_, 14),
UREFL_DECLARE_FIELD(_GElementStorage, aspect_storages_, 15)
UREFL_DECLARE_FIELD(_GElementStorage, aspect_storages_, 15),
UREFL_DECLARE_FIELD(_GElementStorage, eparam_storages_, 16)
)

UREFL_CREATE_STRUCT_TRAIT_INFO(UThreadPoolConfig,
Expand Down Expand Up @@ -266,6 +272,7 @@ CStatus GStorage::loadElement(GPipelinePtr pipeline, const _GPipelineStorage& st
}

status += loadAspect(element, cur.aspect_storages_);
status += loadEParam(element, cur.eparam_storages_);
CGRAPH_FUNCTION_CHECK_STATUS
}

Expand Down Expand Up @@ -386,6 +393,21 @@ CStatus GStorage::loadAspect(GElementPtr element, const std::vector<_GAspectStor
CGRAPH_FUNCTION_END
}


CStatus GStorage::loadEParam(GElementPtr element, const std::vector<_GPassedParamStorage>& psdParamStorages) {
CGRAPH_FUNCTION_BEGIN
CGRAPH_ASSERT_NOT_NULL(element)

for (const auto& pps : psdParamStorages) {
GPassedParamPtr ep = dynamic_cast<GPassedParamPtr>(GStorageFactory::createByType(pps.clz_name_));
CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION(!ep,
pps.clz_name_ + " type create passed param failed.");
element->local_params_[pps.key_] = ep;
}

CGRAPH_FUNCTION_END
}

CGRAPH_NAMESPACE_END

#endif
8 changes: 8 additions & 0 deletions src/GraphCtrl/GraphPipeline/_GStroage/GStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ class GStorage : public GraphObject {
*/
static CStatus loadAspect(GElementPtr element, const std::vector<_GAspectStorage>& aspStorages);

/**
* 加载 eparam 信息
* @param element
* @param psdParamStorages
* @return
*/
static CStatus loadEParam(GElementPtr element, const std::vector<_GPassedParamStorage>& psdParamStorages);

friend class GPipeline;
};

Expand Down
37 changes: 24 additions & 13 deletions src/GraphCtrl/GraphPipeline/_GStroage/GStorageDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,38 @@

CGRAPH_NAMESPACE_BEGIN

struct _GEventStorage : public CStruct {
struct _GStorageBasic : public CStruct {
std::string clz_name_ {};
};

struct _GEventStorage : public _GStorageBasic {
explicit _GEventStorage() = default;
explicit _GEventStorage(const std::string& key, const std::string& clz) {
key_ = key;
clz_name_ = clz;
}

std::string key_ {};
std::string clz_name_ {};
};

struct _GAspectStorage : public CStruct {
struct _GAspectStorage : public _GStorageBasic {
explicit _GAspectStorage() = default;
explicit _GAspectStorage(const std::string& clz) {
clz_name_ = clz;
}

std::string clz_name_ {};
};

struct _GDaemonStorage : public CStruct {
struct _GDaemonStorage : public _GStorageBasic {
explicit _GDaemonStorage() = default;
explicit _GDaemonStorage(CMSec msec, const std::string& clz) {
msec_ = msec;
clz_name_ = clz;
}

CMSec msec_ {0};
std::string clz_name_ {};
};

struct _GStageStorage : public CStruct {
struct _GStageStorage : public _GStorageBasic {
explicit _GStageStorage() = default;
explicit _GStageStorage(const std::string& key, CInt threshold, const std::string& clz) {
key_ = key;
Expand All @@ -60,23 +60,30 @@ struct _GStageStorage : public CStruct {

std::string key_ {};
CInt threshold_ {0};
std::string clz_name_ {};
};

struct _GParamStorage : public CStruct {
struct _GParamStorage : public _GStorageBasic {
explicit _GParamStorage() = default;
explicit _GParamStorage(const std::string& key, CBool backtrace, const std::string& clz) {
key_ = key;
backtrace_ = backtrace;
clz_name_ = clz;
}

std::string key_ {};
std::string clz_name_ {};
CBool backtrace_ { false };
};

struct _GElementStorage : public CStruct {
struct _GPassedParamStorage : public _GStorageBasic {
explicit _GPassedParamStorage() = default;
explicit _GPassedParamStorage(const std::string& key, const std::string& clz) {
key_ = key;
clz_name_ = clz;
}

std::string key_ {};
};

struct _GElementStorage : public _GStorageBasic {
std::string name_ {};
CSize loop_ { CGRAPH_DEFAULT_LOOP_TIMES };
std::string session_ {};
Expand All @@ -92,6 +99,7 @@ struct _GElementStorage : public CStruct {
std::vector<std::string> dependence_sessions_ {};
std::vector<_GElementStorage> children_ {};
std::vector<_GAspectStorage> aspect_storages_ {};
std::vector<_GPassedParamStorage> eparam_storages_ {};

explicit _GElementStorage() = default;

Expand Down Expand Up @@ -119,6 +127,9 @@ struct _GElementStorage : public CStruct {
aspect_storages_.emplace_back(typeid(*aspect).name());
}
}
for (const auto& lp : element->local_params_) {
eparam_storages_.emplace_back(lp.first, typeid(*(lp.second)).name());
}
}

/**
Expand Down
12 changes: 7 additions & 5 deletions src/GraphCtrl/GraphPipeline/_GStroage/GStorageFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class GParam;
class GDaemon;
class GStage;
class GAspect;
class GPassedParam;

class GStorageFactory : public GraphObject {
public:
Expand All @@ -31,11 +32,12 @@ class GStorageFactory : public GraphObject {
*/
template<typename T,
c_enable_if_t<std::is_base_of<GElement, T>::value
|| std::is_base_of<GParam, T>::value
|| std::is_base_of<GDaemon, T>::value
|| std::is_base_of<GAspect, T>::value
|| std::is_base_of<GStage, T>::value
|| std::is_base_of<GEvent, T>::value, int> = 0>
|| std::is_base_of<GParam, T>::value
|| std::is_base_of<GDaemon, T>::value
|| std::is_base_of<GAspect, T>::value
|| std::is_base_of<GStage, T>::value
|| std::is_base_of<GPassedParam, T>::value
|| std::is_base_of<GEvent, T>::value, int> = 0>
static CVoid registerMetaType() {
const char* key = typeid(T).name();
meta_types_[key] = []() { return CAllocator::safeMallocCObject<T>(); };
Expand Down
3 changes: 1 addition & 2 deletions tutorial/MyGNode/HelloCGraphNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
class HelloCGraphNode : public CGraph::GNode {
public:
CStatus run() override {
CStatus status;
std::cout << "Hello, CGraph." << std::endl;
return status;
return CStatus();
}
};

Expand Down
Loading