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