salsa 0.7.1
Loading...
Searching...
No Matches
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
12namespace Salsa {
21
22class Node : public std::enable_shared_from_this<Node> // TODO ? public Object
23{
24public:
25 Node(std::string name = "", std::string uuid = "");
26 virtual ~Node();
27
28 virtual void print() const;
29 virtual void json(Json::Value & root);
30 virtual void publish();
31
33 std::string name() const { return mpNodeInfo->name(); }
35 std::string uuid() const { return mpNodeInfo->uuid(); }
37 std::string hostname() const { return mpNodeInfo->hostname(); }
39 std::weak_ptr<Node> parent() const { return mpParent; }
41 std::vector<std::shared_ptr<Node>> nodes() const { return mChildNodes; }
42
44 void name(std::string n) { mpNodeInfo->set_name(n); }
46 void uuid(std::string uuid) { mpNodeInfo->set_uuid(uuid); }
48 void hostname(std::string h) { mpNodeInfo->set_hostname(h); }
50 void parent(std::weak_ptr<Node> node) { mpParent = node; }
51
53 void add(std::shared_ptr<Node> node)
54 {
55 mChildNodes.push_back(node);
56 node->parent(shared_from_this());
57 }
58
59 std::shared_ptr<Node> find(std::string name) const;
60
62 void removeByUUID(std::string uuid);
63
65 void add(std::shared_ptr<Publisher> pPublisher) { mPublishers.push_back(pPublisher); }
67 std::vector<std::shared_ptr<Publisher>> publishers() const { return mPublishers; }
69 NodeInfo * nodeInfo() const { return mpNodeInfo; }
70
71protected:
72 NodeInfo * mpNodeInfo{new NodeInfo()};
73 std::weak_ptr<Node> mpParent;
74 std::vector<std::shared_ptr<Node>> mChildNodes = {};
75 std::vector<std::shared_ptr<Publisher>> mPublishers = {};
76};
77} // namespace Salsa
Node(std::string name="", std::string uuid="")
Definition Node.cc:5
virtual void print() const
Definition Node.cc:81
void name(std::string n)
Sets node name.
Definition Node.hh:44
void removeByUUID(std::string uuid)
Remove node by uuid.
Definition Node.cc:120
std::vector< std::shared_ptr< Publisher > > publishers() const
Returns publishers.
Definition Node.hh:67
void add(std::shared_ptr< Publisher > pPublisher)
Adds publisher to the node.
Definition Node.hh:65
void uuid(std::string uuid)
Sets node uuid.
Definition Node.hh:46
virtual ~Node()
Definition Node.cc:17
std::weak_ptr< Node > mpParent
Parent node.
Definition Node.hh:73
std::vector< std::shared_ptr< Node > > nodes() const
Returns nodes.
Definition Node.hh:41
NodeInfo * nodeInfo() const
Returns Node Info.
Definition Node.hh:69
void hostname(std::string h)
Sets node hostname.
Definition Node.hh:48
std::vector< std::shared_ptr< Node > > mChildNodes
List of nodes.
Definition Node.hh:74
std::weak_ptr< Node > parent() const
Returns parent node.
Definition Node.hh:39
void add(std::shared_ptr< Node > node)
Adds node to the list of nodes.
Definition Node.hh:53
virtual void publish()
Definition Node.cc:140
virtual void json(Json::Value &root)
Definition Node.cc:34
std::string uuid() const
Returns node UUID.
Definition Node.hh:35
std::shared_ptr< Node > find(std::string name) const
Find node by name.
Definition Node.cc:103
std::string hostname() const
Returns node hostname.
Definition Node.hh:37
NodeInfo * mpNodeInfo
Node Info.
Definition Node.hh:72
std::vector< std::shared_ptr< Publisher > > mPublishers
List of publishers.
Definition Node.hh:75
void parent(std::weak_ptr< Node > node)
Sets parent.
Definition Node.hh:50
std::string name() const
Returns node name.
Definition Node.hh:33