| 12 | using namespace CGraph; |
| 13 | |
| 14 | void tutorial_timeout() { |
| 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<MyNode2>(&c, {b}, "nodeC"); |
| 21 | status += pipeline->registerGElement<MyNode1>(&d, {c}, "nodeD"); |
| 22 | |
| 23 | status = pipeline->process(); // 正常运行 |
| 24 | if (status.isOK()) { |
| 25 | std::cout << "---- pipeline run finish" << std::endl; |
| 26 | } |
| 27 | std::cout << "===================" << std::endl; |
| 28 | |
| 29 | /** |
| 30 | * c 正常执行需要 [2000ms],但是设置超时时长为 [300 ms] |
| 31 | * 故在执行的过程中,会出现超时异常。 |
| 32 | * 如果设定为 HOLD_BY_PIPELINE, |
| 33 | * pipeline会确保在 pipeline->run() 执行完成之前,所有超时节点执行结束 |
| 34 | */ |
| 35 | CMSec timeout = 300; |
| 36 | std::cout << "set [" << c->getName() << "] timeout as [" << timeout << "]ms" << std::endl; |
| 37 | c->setTimeout(timeout, GElementTimeoutStrategy::AS_ERROR); |
| 38 | status = pipeline->process(); |
| 39 | if (!status.isOK()) { |
| 40 | // 会报超时的错误 |
| 41 | std::cout << "**** T22-timeout pipeline run error info : " << status.getInfo() << std::endl; |
| 42 | } |
| 43 | |
| 44 | c->setTimeout(0); // 设置回没有timeout的情况,重新执行,确认结果是正常的。 |
| 45 | status = pipeline->process(); |
| 46 | std::cout << "**** T22-timeout return to no timeout, error code is : " << status.getCode() << std::endl; |
| 47 | |
| 48 | GPipelineFactory::remove(pipeline); |
| 49 | } |
| 50 | |
| 51 | |
| 52 | int main () { |