| 12 | using namespace CGraph; |
| 13 | |
| 14 | void tutorial_simple() { |
| 15 | /* 创建图对应的pipeline */ |
| 16 | GPipelinePtr pipeline = GPipelineFactory::create(); |
| 17 | |
| 18 | /* 定义GElementPtr类型的变量 */ |
| 19 | GElementPtr a, b, c, d = nullptr; |
| 20 | |
| 21 | /** |
| 22 | * 注册节点,其中MyNode1和MyNode2必须为GNode的子类,否则无法通过编译。 |
| 23 | * status+= 操作,可以用于记录链路异常问题 |
| 24 | * */ |
| 25 | CStatus status = pipeline->registerGElement<MyNode1>(&a, {}, "nodeA"); // 将名为nodeA,无执行依赖的node信息,注册入pipeline中 |
| 26 | status += pipeline->registerGElement<MyNode2>(&b, {a}, "nodeB"); // 将名为nodeB,依赖a执行的node信息,注册入pipeline中 |
| 27 | status += pipeline->registerGElement<MyNode1>(&c, {a}, "nodeC"); |
| 28 | status += pipeline->registerGElement<MyNode2>(&d, {b, c}, "nodeD"); // 将名为nodeD,依赖{b,c}执行的node信息,注册入pipeline中 |
| 29 | if (!status.isOK()) { |
| 30 | return; // 使用时,请对所有CGraph接口的返回值做判定。今后tutorial例子中省略该操作。 |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | UThreadPoolConfig config; // (可选)推荐根据自己设定的dag逻辑,来配置调度信息 |
| 35 | config.default_thread_size_ = 2; |
| 36 | config.secondary_thread_size_ = 0; // 更多配置信息,请参考 UThreadPoolDefine.h 中的描述 |
| 37 | pipeline->setUniqueThreadPoolConfig(config); |
| 38 | */ |
| 39 | |
| 40 | /* 图信息初始化,准备开始计算 */ |
| 41 | status += pipeline->init(); |
| 42 | |
| 43 | /* 运行流图信息。初始化后,支持多次循环计算 */ |
| 44 | for (int i = 0; i < 3; i++) { |
| 45 | status = pipeline->run(); |
| 46 | CGRAPH_ECHO("==== tutorial_simple, loop : [%d], and run status = [%d].", i + 1, status.getCode()); |
| 47 | } |
| 48 | |
| 49 | /* 图信息逆初始化,准备结束计算 */ |
| 50 | status += pipeline->destroy(); |
| 51 | GPipelineFactory::remove(pipeline); |
| 52 | } |
| 53 | |
| 54 | |
| 55 | int main () { |