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