YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
xmlclusterloader.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
8#include <dirent.h>
9#include <tinyxml.h>
10#include <yarp/os/Value.h>
11
12#include <algorithm>
13#include <cctype>
14#include <string>
15#include <fstream>
16#include <utility>
17#include <yarp/os/Network.h>
18
19
20
21using namespace yarp::manager;
22
26XmlClusterLoader::XmlClusterLoader(std::string szFileName) : confFile(std::move(szFileName))
27{
28}
29
30
32
34{
35 cluster.nodes.clear();
37 TiXmlDocument doc(confFile);
38 if (!doc.LoadFile())
39 {
40 OSTRINGSTREAM err;
41 err<<"XmlClusterLoader: unable to load "<<confFile;
42 logger->addError(err);
43 return false;
44 }
45
46 /* retrieving root element */
47 TiXmlElement *root = doc.RootElement();
48 if (!root)
49 {
50 logger->addError("XmlClusterLoader: unable to find root element");
51 return false;
52 }
53
54 if (root->ValueStr() != "cluster")
55 {
56 OSTRINGSTREAM err;
57 err<<"XmlClusterLoader:No tag cluster found in"<<confFile;
58 logger->addError(err);
59 return false;
60 }
61
62 if (root->Attribute("name"))
63 {
64 cluster.name = root->Attribute("name");
65 }
66
67 if (root->Attribute("user"))
68 {
69 cluster.user = root->Attribute("user");
70 }
71
72 TiXmlElement *nameserver = root->FirstChildElement("nameserver");
73 if (!nameserver)
74 {
75 OSTRINGSTREAM err;
76 err<<"XmlClusterLoader:No tag nameserver found in"<<confFile;
77 logger->addError(err);
78 return false;
79 }
80
81 if (nameserver->Attribute("namespace"))
82 {
83 cluster.nameSpace = nameserver->Attribute("namespace");
84
85 }
86
87 if (nameserver->Attribute("node"))
88 {
89 cluster.nsNode = nameserver->Attribute("node");
90
91 }
92
93 if (nameserver->Attribute("ssh-options"))
94 {
95 cluster.ssh_options = nameserver->Attribute("ssh-options");
96
97 }
98
99
100
101 for (TiXmlElement* node = root->FirstChildElement("node");
102 node != nullptr; node = node->NextSiblingElement("node"))
103 {
104 ClusterNode c_node;
105 if (node->GetText())
106 {
107 c_node.name = node->GetText();
108 }
109
110 if (node->Attribute("display"))
111 {
112 c_node.display = true;
113 c_node.displayValue = node->Attribute("display");
114 }
115
116 if (node->Attribute("user"))
117 {
118 c_node.user = node->Attribute("user");
119 }
120 else
121 {
122 c_node.user = cluster.user;
123 }
124
125 if (node->Attribute("ssh-options"))
126 {
127 c_node.ssh_options = node->Attribute("ssh-options");
128 }
129
130 if (node->Attribute("address"))
131 {
132 c_node.address = node->Attribute("address");
133 }
134 else
135 {
136 c_node.address = c_node.name;
137 }
138 cluster.nodes.push_back(c_node);
139
140
141 }
142 _cluster = cluster;
143 return true;
144
145}
Singleton class ErrorLogger.
Definition utility.h:58
void addError(const char *szError)
Definition utility.cpp:126
static ErrorLogger * Instance()
Singleton class ErrorLogger.
Definition utility.cpp:98
XmlClusterLoader(std::string szFileName)
load only one application indicated by its xml file name
bool parseXmlFile(Cluster &_cluster)
STL namespace.
std::stringstream OSTRINGSTREAM
Definition utility.h:50
std::vector< ClusterNode > nodes