MCPcopy Create free account
hub / github.com/ChunelFeng/CGraph / MySubMessageNode

Class MySubMessageNode

tutorial/MyGNode/MySubMessageNode.h:16–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14
15template <typename ...Args>
16class MySubMessageNode : public CGraph::GTemplateNode<Args ...> {
17public:
18 explicit MySubMessageNode(int connId) {
19 conn_id_ = connId;
20 }
21
22 CStatus init() override {
23 CGraph::CGRAPH_ECHO("==> [%s] [init] get conn id = [%d]",
24 this->getName().c_str(), conn_id_);
25 return CStatus();
26 }
27
28 CStatus run() override {
29 std::shared_ptr<MyMessageParam> mp = nullptr; // 通过智能指针类型,接收一个消息。相比value接收(Recv or Sub),性能会好一些
30 CStatus status = CGRAPH_SUB_MPARAM(MyMessageParam, conn_id_, mp)
31 if (!status.isOK()) {
32 CGraph::CGRAPH_ECHO("[%s] recv message error", this->getName().c_str());
33 return status;
34 }
35
36 CGraph::CGRAPH_ECHO("[%s] conn id = [%d], num = [%d], info = [%s]",
37 this->getName().c_str(), conn_id_, mp->num, mp->info.c_str());
38 return status;
39 }
40
41private:
42 CIndex conn_id_;
43};
44
45#endif //CGRAPH_MYSUBMESSAGENODE_H

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected