salsa  0.3.0
Node.hh
1 #pragma once
2 
3 // TODO? #include <Object.hh>
4 #include <json/json.h>
5 #include <memory>
6 #include <salsa.hh>
7 #include <string>
8 
9 #include "NodeInfo.pb.h"
10 #include <Publisher.hh>
11 
12 namespace Salsa {
21 
22 class Node : public std::enable_shared_from_this<Node> // TODO ? public Object
23 {
24 public:
25  Node(std::string name = "", std::string uuid = "");
26  virtual ~Node();
27 
28  // TODO annotate
29  virtual void print() const;
30  virtual void json(Json::Value & root);
31  virtual void publish();
32 
34  std::string name() const { return mpNodeInfo->name(); }
36  std::string uuid() const { return mpNodeInfo->uuid(); }
38  std::weak_ptr<Node> parent() const { return mpParent; }
40  std::vector<std::shared_ptr<Node>> nodes() const { return mChildNodes; }
41 
43  void name(std::string n) { mpNodeInfo->set_name(n); }
45  void uuid(std::string uuid) { mpNodeInfo->set_uuid(uuid); }
47  void parent(std::weak_ptr<Node> node) { mpParent = node; }
48 
50  void add(std::shared_ptr<Node> node)
51  {
52  mChildNodes.push_back(node);
53  node->parent(shared_from_this());
54  }
56  std::shared_ptr<Node> find(std::string name) const;
57 
59  void removeByUUID(std::string uuid);
60 
62  void add(std::shared_ptr<Publisher> pPublisher) { mPublishers.push_back(pPublisher); }
64  std::vector<std::shared_ptr<Publisher>> publishers() const { return mPublishers; }
66  NodeInfo * nodeInfo() const { return mpNodeInfo; }
67 
68 protected:
69  NodeInfo * mpNodeInfo{new NodeInfo()};
70  std::weak_ptr<Node> mpParent;
71  std::vector<std::shared_ptr<Node>> mChildNodes = {};
72  std::vector<std::shared_ptr<Publisher>> mPublishers = {};
73 };
74 } // namespace Salsa
std::shared_ptr< Node > find(std::string name) const
Find node by name.
Definition: Node.cc:113
std::vector< std::shared_ptr< Publisher > > mPublishers
List of publishers.
Definition: Node.hh:72
void add(std::shared_ptr< Publisher > pPublisher)
Adds publisher to the node.
Definition: Node.hh:62
std::weak_ptr< Node > mpParent
Parent node.
Definition: Node.hh:70
Base Node class
Definition: Node.hh:22
Node(std::string name="", std::string uuid="")
Definition: Node.cc:5
virtual void publish()
Definition: Node.cc:150
void add(std::shared_ptr< Node > node)
Adds node to the list of nodes.
Definition: Node.hh:50
virtual void print() const
Definition: Node.cc:91
void uuid(std::string uuid)
Sets node uuid.
Definition: Node.hh:45
void removeByUUID(std::string uuid)
Remove node by uuid.
Definition: Node.cc:130
NodeInfo * mpNodeInfo
Node Info.
Definition: Node.hh:69
std::weak_ptr< Node > parent() const
Returns parent node.
Definition: Node.hh:38
Definition: Actor.cc:2
std::string uuid() const
Returns node UUID.
Definition: Node.hh:36
void parent(std::weak_ptr< Node > node)
Sets parent.
Definition: Node.hh:47
virtual void json(Json::Value &root)
Definition: Node.cc:34
virtual ~Node()
Definition: Node.cc:17
std::vector< std::shared_ptr< Node > > mChildNodes
List of nodes.
Definition: Node.hh:71
std::vector< std::shared_ptr< Node > > nodes() const
Returns nodes.
Definition: Node.hh:40
void name(std::string n)
Sets node name.
Definition: Node.hh:43
std::vector< std::shared_ptr< Publisher > > publishers() const
Returns publishers.
Definition: Node.hh:64
std::string name() const
Returns node name.
Definition: Node.hh:34
NodeInfo * nodeInfo() const
Returns Node Info.
Definition: Node.hh:66