| 17 | using namespace CGraph; |
| 18 | |
| 19 | void tutorial_aspect_param() { |
| 20 | GPipelinePtr pipeline = GPipelineFactory::create(); |
| 21 | MyConnParam paramA; |
| 22 | paramA.ip_ = "127.0.0.1"; |
| 23 | paramA.port_ = 6666; |
| 24 | |
| 25 | MyConnParam paramB; |
| 26 | paramB.ip_ = "255.255.255.255"; |
| 27 | paramB.port_ = 9999; |
| 28 | |
| 29 | GElementPtr a, b, c = nullptr; |
| 30 | |
| 31 | pipeline->registerGElement<MyNode1>(&a, {}, "nodeA", 1); |
| 32 | pipeline->registerGElement<MyNode2>(&b, {a}, "nodeB", 1); |
| 33 | pipeline->registerGElement<MyWriteParamNode>(&c, {b}, "nodeC", 2); |
| 34 | |
| 35 | /** 给a节点添加 MyConnAspect 切面的逻辑,并且传入 paramA 相关参数 */ |
| 36 | a->addGAspect<MyConnAspect, MyConnParam>(¶mA); |
| 37 | |
| 38 | /** 给b节点添加多个切面,有的传递参数,有的不传递 */ |
| 39 | b->addGAspect<MyConnAspect, MyConnParam>(¶mB)->addGAspect<MyTimerAspect>(); |
| 40 | |
| 41 | /** 在切面中,获取pipeline中的参数,并且进行对应处理 */ |
| 42 | c->addGAspect<MyPipelineParamAspect>(); |
| 43 | |
| 44 | pipeline->process(); |
| 45 | GPipelineFactory::clear(); |
| 46 | } |
| 47 | |
| 48 | |
| 49 | int main() { |