-
Notifications
You must be signed in to change notification settings - Fork 1
/
material.h
57 lines (46 loc) · 1.44 KB
/
material.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/***************************
@Author: Chunel
@Contact: [email protected]
@File: material.h
@Time: 2023/1/15 20:44
@Desc: 设定几个
***************************/
#ifndef CGRAPH_NIO_MATERIAL_H
#define CGRAPH_NIO_MATERIAL_H
#include "3rd-party/CGraph/src/CGraph.h"
using namespace CGraph;
static const char* PARAM_KEY = "my-param";
struct MyParam : public GParam {
int loop_ = 0;
int val_ = 0;
void reset(const CStatus& curStatus) override {
val_ = 0; // 计算数值复位
loop_++; // 记录轮询次数
}
};
class MyNode : public GNode {
public:
CStatus init() override {
return CGRAPH_CREATE_GPARAM(MyParam, PARAM_KEY) // 创建参数
}
CStatus run() override {
auto param = CGRAPH_GET_GPARAM_WITH_NO_EMPTY(MyParam, PARAM_KEY)
param->val_++; // 获取参数,并且给参数赋值
return CStatus();
}
};
// 构建流水线逻辑
GPipelinePtr buildPipeline() {
auto pipeline = GPipelineFactory::create();
GElementPtr a, b = nullptr;
// 设置线程池信息(可选)
UThreadPoolConfig config;
config.default_thread_size_ = 2;
config.max_thread_size_ = 2;
config.monitor_enable_ = false;
pipeline->setUniqueThreadPoolConfig(config);
pipeline->registerGElement<MyNode>(&a, {}, "A");
pipeline->registerGElement<MyNode>(&b, {a}, "B"); // 注册一个链路信息,a->b
return pipeline;
}
#endif //CGRAPH_NIO_MATERIAL_H