| 12 | using namespace CGraph; |
| 13 | |
| 14 | void tutorial_cluster() { |
| 15 | CStatus status; |
| 16 | GPipelinePtr pipeline = GPipelineFactory::create(); |
| 17 | GElementPtr a, b_cluster, c, d = nullptr; |
| 18 | |
| 19 | b_cluster = pipeline->createGGroup<GCluster>({ |
| 20 | pipeline->createGNode<MyNode1>(GNodeInfo("nodeB1", 1)), // 创建名为nodeB1的node信息,并将其放入b_cluster中 |
| 21 | pipeline->createGNode<MyNode1>(GNodeInfo("nodeB2", 3)), // 创建名为nodeB2且自循环3次的node信息,并将其放入b_cluster中 |
| 22 | pipeline->createGNode<MyNode2>(GNodeInfo("nodeB3", 1)) |
| 23 | }); // 创建cluster信息,包含了三个node信息 |
| 24 | |
| 25 | /* 正式使用时,请对所有返回值进行判定 */ |
| 26 | status = pipeline->registerGElement<MyNode1>(&a, {}, "nodeA", 1); // 将名为nodeA的node信息,注册入pipeline中 |
| 27 | status += pipeline->registerGElement<GCluster>(&b_cluster, {a}, "clusterB", 2); // 将名为clusterB,依赖a执行且自循环2次的cluster信息,注册入pipeline中 |
| 28 | status += pipeline->registerGElement<MyNode1>(&c, {a}, "nodeC", 1); |
| 29 | status += pipeline->registerGElement<MyNode2>(&d, {b_cluster, c}, "nodeD", 2); |
| 30 | if (!status.isOK()) { |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * 如果想查看当前 pipeline 的流图结构信息, |
| 36 | * 请调用 dump()方法,并且将输出的内容(不包含node内部的打印信息), |
| 37 | * 复制到 https://dreampuf.github.io/GraphvizOnline/ 中查看效果 |
| 38 | */ |
| 39 | // pipeline->dump(); |
| 40 | |
| 41 | /* process函数,相当于 init(),run()*n,destroy()函数,同时调用 */ |
| 42 | status = pipeline->process(); |
| 43 | CGRAPH_ECHO("pipeline process status is : [%d]", status.getCode()); |
| 44 | |
| 45 | GPipelineFactory::clear(); // clear表示清空所有的pipeline信息 |
| 46 | } |
| 47 | |
| 48 | |
| 49 | int main () { |