| 12 | using namespace CGraph; |
| 13 | |
| 14 | void tutorial_suspend() { |
| 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<MyNode2>(&b, {a}, "nodeB", 3); |
| 20 | status += pipeline->registerGElement<MyNode1>(&c, {a}, "nodeC", 3); |
| 21 | status += pipeline->registerGElement<MyNode2>(&d, {b, c}, "nodeD"); |
| 22 | if (!status.isOK()) { |
| 23 | std::cout << status.getInfo() << std::endl; |
| 24 | return; // 使用时,请对所有CGraph接口的返回值做判定。今后tutorial例子中省略该操作。 |
| 25 | } |
| 26 | |
| 27 | status += pipeline->init(); |
| 28 | |
| 29 | CGRAPH_ECHO("pipeline async run, BEGIN."); |
| 30 | auto result = pipeline->asyncRun(); |
| 31 | CGRAPH_SLEEP_MILLISECOND(2600) |
| 32 | |
| 33 | CGRAPH_ECHO("pipeline async run, SUSPEND."); |
| 34 | status += pipeline->suspend(); // 暂停执行,保留当前pipeline内部所有参数信息和状态信息 |
| 35 | |
| 36 | CGRAPH_SLEEP_MILLISECOND(7200) |
| 37 | CGRAPH_ECHO("pipeline async run, RESUME after 7200ms."); |
| 38 | status += pipeline->resume(); // 暂停一段时间后,恢复执行 |
| 39 | |
| 40 | result.wait(); // 等待pipeline异步执行结束 |
| 41 | pipeline->destroy(); |
| 42 | |
| 43 | GPipelineFactory::remove(pipeline); |
| 44 | } |
| 45 | |
| 46 | |
| 47 | int main () { |