YARP
Yet Another Robot Platform
application.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 
7 
8 using namespace yarp::manager;
9 
14  iRank(0),
15  waitStart(0.0),
16  waitStop(0.0)
17 {
18  if (!module) {
19  return;
20  }
21 
22  strName = module->strName;
23  strHost = module->strHost;
24  strParam = module->strParam;
25  strWorkDir = module->strWorkDir;
26  strStdio = module->strStdio;
27  strBroker = module->strBroker;
28  strPrefix = module->strPrefix;
29  strEnvironment = module->strEnvironment;
30  iRank = module->iRank;
31  strTag = module->getLabel();
32  strDisplay = module->getDisplay();
33  waitStart = module->getPostExecWait();
34  waitStop = module->getPostStopWait();
35  if (module->getModel()) {
36  modelBase = *module->getModel();
37  } else {
38  modelBase = module->getModelBase();
39  }
40 
41  //TODO: resources should be added too
42 }
43 
45 {
46  portmaps.push_back(portmap);
47  return true;
48 }
49 
50 
52 {
53  auto itr = findPortmap(portmap);
54  if (itr == portmaps.end()) {
55  return true;
56  }
57  portmaps.erase(itr);
58  return true;
59 }
60 
61 
62 PortmapIterator ModuleInterface::findPortmap(Portmap& portmap)
63 {
64  PortmapIterator itr;
65  for (itr = portmaps.begin(); itr < portmaps.end(); itr++) {
66  if ((*itr) == portmap) {
67  return itr;
68  }
69  }
70  return portmaps.end();
71 }
72 
73 
78 {
79  clear();
80 }
81 
82 
84 {
85  clear();
86  setName(szName);
87 }
88 
89 
91 {
92  strName = app.strName;
93  strVersion = app.strVersion;
94  strDescription = app.strDescription;
95  authors = app.authors;
96  Imodules = app.Imodules;
97  connections = app.connections;
98  arbitrators = app.arbitrators;
99  Iapplications = app.Iapplications;
100  resources = app.resources;
101  strXmlFile = app.strXmlFile;
102  strPrefix = app.strPrefix;
103  strBasePrefix = app.strBasePrefix;
104  appOwner = app.appOwner;
105 }
106 
107 
108 Application::~Application() = default;
109 
110 
112 {
113  auto* app = new Application(*this);
114  return app;
115 }
116 
117 
119 {
120  Imodules.push_back(imod);
121  return true;
122 }
123 
124 
126 {
127  auto itr = findImodule(imod);
128  if (itr == Imodules.end()) {
129  return true;
130  }
131  Imodules.erase(itr);
132  return true;
133 }
134 
135 
137 {
138  connections.push_back(cnn);
139  auto itr = findConnection(cnn);
140  return (*itr);
141 }
142 
143 
145 {
146  auto itr = findConnection(cnn);
147  if (itr == connections.end()) {
148  return true;
149  }
150  connections.erase(itr);
151  return true;
152 
153 }
154 
156 {
157  arbitrators.push_back(arb);
158  auto itr = findArbitrator(arb);
159  return(*itr);
160 }
161 
163 {
164  auto itr = findArbitrator(arb);
165  if (itr == arbitrators.end()) {
166  return true;
167  }
168  arbitrators.erase(itr);
169  return true;
170 }
171 
172 
173 /*
174 void Application::updateConnectionPrefix()
175 {
176  CnnIterator itr;
177  for(itr=connections.begin(); itr<connections.end(); itr++)
178  {
179  string strPort;
180  if(!((*itr).isExternalFrom()))
181  {
182  strPort = strPrefix + string((*itr).from());
183  (*itr).setFrom(strPort.c_str());
184  }
185 
186  if(!((*itr).isExternalTo()))
187  {
188  strPort = strPrefix + string((*itr).to());
189  (*itr).setTo(strPort.c_str());
190  }
191  }
192 }
193 */
194 
196 {
197  Iapplications.push_back(iapp);
198  return true;
199 }
200 
201 
203 {
204  auto itr = findIapplication(iapp);
205  if (itr == Iapplications.end()) {
206  return true;
207  }
208  Iapplications.erase(itr);
209  return true;
210 }
211 
213 {
214  resources.push_back(res);
215  return true;
216 }
217 
218 
220 {
221  auto itr = findResource(res);
222  if (itr == resources.end()) {
223  return true;
224  }
225  resources.erase(itr);
226  return true;
227 }
228 
230 {
231  AuthorIterator itr;
232  for (itr = authors.begin(); itr < authors.end(); itr++) {
233  if((*itr) == author)
234  {
235  authors.erase(itr);
236  return true;
237  }
238  }
239  return true;
240 }
241 
242 
243 IModuleIterator Application::findImodule(ModuleInterface& imod)
244 {
245  IModuleIterator itr;
246  for (itr = Imodules.begin(); itr < Imodules.end(); itr++) {
247  if ((*itr) == imod) {
248  return itr;
249  }
250  }
251  return Imodules.end();
252 }
253 
254 
255 CnnIterator Application::findConnection(Connection& cnn)
256 {
257  CnnIterator itr;
258  for (itr = connections.begin(); itr < connections.end(); itr++) {
259  if ((*itr) == cnn) {
260  return itr;
261  }
262  }
263  return connections.end();
264 }
265 
266 ArbIterator Application::findArbitrator(Arbitrator& arb)
267 {
268  ArbIterator itr;
269  for (itr = arbitrators.begin(); itr < arbitrators.end(); itr++) {
270  if ((*itr) == arb) {
271  return itr;
272  }
273  }
274  return arbitrators.end();
275 }
276 
277 
278 IApplicationIterator Application::findIapplication(ApplicationInterface& iapp)
279 {
281  for (itr = Iapplications.begin(); itr < Iapplications.end(); itr++) {
282  if ((*itr) == iapp) {
283  return itr;
284  }
285  }
286  return Iapplications.end();
287 }
288 
289 ResourceIterator Application::findResource(ResYarpPort& res)
290 {
291  ResourceIterator itr;
292  for (itr = resources.begin(); itr < resources.end(); itr++) {
293  if ((*itr) == res) {
294  return itr;
295  }
296  }
297  return resources.end();
298 }
static RFModule * module
Definition: RFModule.cpp:231
Class ApplicationInterface.
Definition: application.h:253
Class Application.
Definition: application.h:289
bool removeAuthor(Author &author)
void setName(const char *szName)
Definition: application.h:296
Arbitrator & addArbitrator(Arbitrator &arb)
bool addIapplication(ApplicationInterface &iapp)
Node * clone() override
bool removeImodule(ModuleInterface &imod)
bool removeConnection(Connection &cnn)
bool removeResource(ResYarpPort &res)
Connection & addConnection(Connection &cnn)
bool removeArbitrator(Arbitrator &arb)
bool addResource(ResYarpPort &res)
bool removeIapplication(ApplicationInterface &iapp)
bool addImodule(ModuleInterface &imod)
Application()
Class Application.
Definition: application.cpp:77
Class port Arbitrator.
Definition: arbitrator.h:25
Class Connection.
Definition: application.h:57
Class ModuleInterface.
Definition: application.h:161
bool removePortmap(Portmap &portmap)
Definition: application.cpp:51
bool addPortmap(Portmap &portmap)
Definition: application.cpp:44
ModuleInterface(const char *szName)
Definition: application.h:164
Class Module.
Definition: module.h:100
a Node of a Graph
Definition: node.h:65
Class Portmap.
Definition: application.h:27
std::vector< Portmap >::iterator PortmapIterator
Definition: application.h:49
std::vector< ResYarpPort >::iterator ResourceIterator
Definition: application.h:154
std::vector< ModuleInterface >::iterator IModuleIterator
Definition: application.h:247
std::vector< Arbitrator >::iterator ArbIterator
Definition: arbitrator.h:92
std::vector< Author >::iterator AuthorIterator
Definition: module.h:91
std::vector< ApplicationInterface >::iterator IApplicationIterator
Definition: application.h:284
std::vector< Connection >::iterator CnnIterator
Definition: application.h:151