| 12 | using namespace CGraph; |
| 13 | |
| 14 | void tutorial_cancel() { |
| 15 | GPipelinePtr pipeline = GPipelineFactory::create(); |
| 16 | GElementPtr a, b, c, d = nullptr; |
| 17 | |
| 18 | CStatus status = pipeline->registerGElement<MyNode1>(&a, {}, "nodeA"); |
| 19 | status += pipeline->registerGElement<MyNode1>(&b, {a}, "nodeB"); |
| 20 | status += pipeline->registerGElement<MyNode1>(&c, {b}, "nodeC"); |
| 21 | status += pipeline->registerGElement<MyNode2>(&d, {c}, "nodeD"); |
| 22 | if (!status.isOK()) { |
| 23 | return; // 使用时,请对所有CGraph接口的返回值做判定。今后tutorial例子中省略该操作。 |
| 24 | } |
| 25 | |
| 26 | pipeline->init(); |
| 27 | |
| 28 | // 异步执行,并且等待结束 |
| 29 | auto result = pipeline->asyncRun(); |
| 30 | CGRAPH_ECHO("pipeline async run first time, BEGIN."); |
| 31 | result.wait(); |
| 32 | CGRAPH_ECHO("pipeline async run first time, FINISH."); |
| 33 | CGRAPH_ECHO("======================"); |
| 34 | |
| 35 | result = pipeline->asyncRun(); |
| 36 | CGRAPH_ECHO("pipeline async run second time, BEGIN."); |
| 37 | CGRAPH_SLEEP_MILLISECOND(1500) |
| 38 | |
| 39 | /** |
| 40 | * pipeline整体流程,正常执行需要4000ms |
| 41 | * 等1500ms之后,手动cancel一下 |
| 42 | */ |
| 43 | pipeline->cancel(); |
| 44 | CGRAPH_ECHO("pipeline async run second time, CANCEL."); |
| 45 | CGRAPH_ECHO("======================"); |
| 46 | |
| 47 | result.wait(); // 请务必等待执行完成之后,再进行destroy逻辑 |
| 48 | pipeline->destroy(); |
| 49 | GPipelineFactory::remove(pipeline); |
| 50 | } |
| 51 | |
| 52 | |
| 53 | int main () { |