YARP
Yet Another Robot Platform
application.h
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 
9 #ifndef YARP_MANAGER_APPLICATION
10 #define YARP_MANAGER_APPLICATION
11 
12 #include <map>
13 
14 #include <yarp/manager/ymm-types.h>
15 #include <yarp/manager/node.h>
16 #include <yarp/manager/module.h>
17 #include <yarp/manager/utility.h>
21 
22 
23 namespace yarp {
24 namespace manager {
25 
26 
30 class Portmap{
31 
32 public:
33  Portmap(const char* szOld, const char* szNew) {
34  if(szOld) { strOld = szOld; }
35  if(szNew) { strNew = szNew; }
36  }
37  virtual ~Portmap() = default;
38  const char* oldPort() { return strOld.c_str(); }
39  const char* newPort() { return strNew.c_str(); }
40  bool operator==(const Portmap& alt) const {
41  return ((strOld == alt.strOld) && (strNew == alt.strNew));
42  }
43 
44 protected:
45 
46 private:
47  std::string strOld;
48  std::string strNew;
49 };
50 
51 typedef std::vector<Portmap> PortmapContainer;
52 typedef std::vector<Portmap>::iterator PortmapIterator;
53 
54 
55 
60 {
61 public:
62  Connection() { Connection(nullptr, nullptr); }
63  Connection(const char* szFrom, const char* szTo, const char* szCr=nullptr) {
64  if(szFrom) { strFrom = szFrom; }
65  if(szTo) { strTo = szTo; }
66  if(szCr) { strCarrier = szCr; }
67  bWithPriority = false;
68  appOwner = nullptr;
69  bExternalFrom = false;
70  bExternalTo = false;
71  existsFrom = false;
72  existsTo = false;
73  bPersist = false;
74  input = nullptr;
75  output = nullptr;
76  model = nullptr;
77  }
78  virtual ~Connection() = default;
79  const char* from() { return strFrom.c_str();}
80  const char* to() { return strTo.c_str();}
81  const char* carrier() { return strCarrier.c_str(); }
82  const char* qosFrom() { return strQosFrom.c_str(); }
83  const char* qosTo() { return strQosTo.c_str(); }
84  void setFrom(const char* szFrom) { if(szFrom) { strFrom = szFrom; } }
85  void setTo(const char* szTo) { if(szTo) { strTo = szTo; } }
86  void setCarrier(const char* szCr) { if(szCr) { strCarrier = szCr; } }
87  void setFromExternal(bool ext) { bExternalFrom = ext;}
88  void setToExternal(bool ext) { bExternalTo = ext; }
89  void setFromExists(bool exists) { existsFrom = exists;}
90  void setToExists(bool exists) { existsTo = exists; }
91  bool getFromExists() const { return existsFrom; }
92  bool getToExists() const { return existsTo; }
93  void setPersistent(bool per) { bPersist = per; }
94  void setQosFrom(const char* szQos) { if(szQos) { strQosFrom = szQos; } }
95  void setQosTo(const char* szQos) { if(szQos) { strQosTo = szQos; } }
96  bool isExternalFrom() { return bExternalFrom; }
97  bool isExternalTo() { return bExternalTo; }
98  bool isPersistent() { return bPersist; }
99 
100 
101  void setId(const char* id) { if(id) { strId = id; } }
102  const char* getId() { return strId.c_str(); }
103 
104  void setOwner(Node* owner){ appOwner = owner; }
105  Node* owner() { return appOwner; }
106 
107  void setCorInputData(InputData* in) { input = in;}
108  InputData* getCorInputData() { return input;}
109  void setCorOutputData(OutputData* out) { output = out;}
110  OutputData* getCorOutputData() { return output;}
111 
112  void setPriority(bool withprio) { bWithPriority = withprio; }
113  bool withPriority() { return bWithPriority; }
114 
115  GraphicModel* getModel() { return model;}
116  void setModel(GraphicModel* mdl) { model = mdl; }
117 
118  // modelBased is used to keep the graphic and geometric
119  // information which is directly loaded from application
120  // description file.
121  GraphicModel& getModelBase() { return modelBase;}
122  void setModelBase(GraphicModel& mdl) { modelBase = mdl; }
123 
124 
125  bool operator==(const Connection& alt) const {
126  return ((strFrom == alt.strFrom) && (strTo == alt.strTo));
127  }
128 
129 protected:
130 
131 private:
132  std::string strFrom;
133  std::string strTo;
134  std::string strId;
135  bool bExternalTo;
136  bool bExternalFrom;
137  bool existsFrom;
138  bool existsTo;
139  std::string strCarrier;
140  std::string strQosFrom;
141  std::string strQosTo;
142  bool bPersist;
143  Node* appOwner;
144  bool bWithPriority;
145  InputData* input;
146  OutputData* output;
147  GraphicModel* model;
148  GraphicModel modelBase;
149 
150 };
151 
152 
153 typedef std::vector<Connection> CnnContainer;
154 typedef std::vector<Connection>::iterator CnnIterator;
155 
156 typedef std::vector<ResYarpPort> ResourceContainer;
157 typedef std::vector<ResYarpPort>::iterator ResourceIterator;
158 
159 
160 
165 
166 public:
167  ModuleInterface( const char* szName) {
168  if(szName) { strName = szName; }
169  iRank = -1;
170  waitStart = waitStop = 0.0;
171  }
172 
174 
175  virtual ~ModuleInterface() = default;
176 
177  void setHost(const char* szHost) { if(szHost) { strHost = szHost; } }
178  void setParam(const char* szParam) { if(szParam) { strParam = szParam; } }
179  void setRank(int irank) { iRank = irank; }
180  void setWorkDir(const char* szWDir) { if(szWDir) { strWorkDir = szWDir; } }
181  void setStdio(const char* szStdio) { if(szStdio) { strStdio = szStdio; } }
182  void setBroker(const char* szBroker) { if(szBroker) { strBroker = szBroker; } }
183  void setPrefix(const char* szPrefix) {if(szPrefix) { strPrefix = szPrefix; } }
184  void setEnvironment(const char* szEnv) {if(szEnv) { strEnvironment = szEnv; } }
185  void setTag(const char* szTag) {if(szTag) { strTag = szTag; } }
186  void setDisplay(const char* szDisplay) {if(szDisplay) { strDisplay = szDisplay; } }
187 
188  const char* getName() { return strName.c_str(); }
189  const char* getHost() { return strHost.c_str(); }
190  const char* getParam() { return strParam.c_str(); }
191  int getRank() { return iRank; }
192  const char* getWorkDir() { return strWorkDir.c_str(); }
193  const char* getStdio() { return strStdio.c_str(); }
194  const char* getBroker() { return strBroker.c_str(); }
195  const char* getPrefix() { return strPrefix.c_str(); }
196  const char* getEnvironment() { return strEnvironment.c_str(); }
197  const char* getTag() { return strTag.c_str(); }
198  const char* getDisplay() { return strDisplay.c_str(); }
199 
200  bool operator==(const ModuleInterface& modint) const {
201  return (strName == modint.strName);
202  }
203 
204  void addResource(ResYarpPort &res) { resources.push_back(res); }
205  ResourceContainer& getResources() { return resources; }
206 
207  void setPostExecWait(double t) { waitStart = t; }
208  double getPostExecWait() { return waitStart; }
209  void setPostStopWait(double t) { waitStop = t; }
210  double getPostStopWait() { return waitStop; }
211 
212 
213  int portmapCount() { return portmaps.size(); }
214  Portmap& getPortmapAt(int index){ return portmaps[index]; }
215  bool addPortmap(Portmap &portmap);
216  bool removePortmap(Portmap& portmap);
217 
218  //void setModule(Module* mod) { module = mod; }
219  //Module* getModule() { return module;}
220 
221  GraphicModel& getModelBase() { return modelBase;}
222  void setModelBase(GraphicModel& mdl) { modelBase = mdl; };
223 
224 
225 
226 protected:
227 
228 private:
229  std::string strName;
230  std::string strHost;
231  std::string strParam;
232  std::string strWorkDir;
233  std::string strStdio;
234  std::string strBroker;
235  std::string strPrefix;
236  std::string strEnvironment;
237  std::string strDisplay;
238  int iRank;
239  ResourceContainer resources;
240  double waitStart;
241  double waitStop;
242  PortmapContainer portmaps;
243  PortmapIterator findPortmap(Portmap& portmap);
244  std::string strTag;
245  GraphicModel modelBase;
246 };
247 
248 
249 typedef std::vector<ModuleInterface> IModuleContainer;
250 typedef std::vector<ModuleInterface>::iterator IModuleIterator;
251 
252 
257 
258 public:
259  ApplicationInterface(const char* szName) {
260  if(szName) { strName = szName; }
261  }
262  virtual ~ApplicationInterface() = default;
263  void setPrefix(const char* szPrefix) { if(szPrefix) { strPrefix = szPrefix; } }
264  const char* getName() { return strName.c_str(); }
265  const char* getPrefix() { return strPrefix.c_str(); }
266  bool operator==(const ApplicationInterface& alt) const {
267  return (strName == alt.strName);
268  }
269 
270  // modelBased is used to keep the graphic and geometric
271  // information which is directly loaded from application
272  // description file.
273  GraphicModel& getModelBase() { return modelBase;}
274  void setModelBase(GraphicModel& mdl) { modelBase = mdl; };
275 
276 
277 protected:
278 
279 private:
280  std::string strName;
281  std::string strPrefix;
282  GraphicModel modelBase;
283 };
284 
285 
286 typedef std::vector<ApplicationInterface> IApplicationContainer;
287 typedef std::vector<ApplicationInterface>::iterator IApplicationIterator;
288 
292 class Application : public Node{
293 
294 public:
295  Application();
296  Application(const char* szName);
297  Application(const Application &app);
298  ~Application() override;
299  void setName(const char* szName) {
300  if(szName){
301  strName = szName;
302  }
303  }
304  void setVersion(const char* szVersion) { if(szVersion) { strVersion = szVersion; } }
305  void setDescription(const char* szDesc) { if(szDesc) { strDescription = szDesc; } }
306  const char* getName() { return strName.c_str(); }
307  size_t getNameLenght() {return strName.length(); }
308  const char* getVersion() { return strVersion.c_str(); }
309  const char* getDescription() { return strDescription.c_str(); }
310  Node* clone() override;
311 
312  void addAuthor(Author& author) { authors.push_back(author); }
313  int authorCount() { return authors.size(); }
314  Author& getAuthorAt(int index) { return authors[index]; }
315  bool removeAuthor(Author& author);
316 
317  int imoduleCount() { return Imodules.size(); }
318  ModuleInterface& getImoduleAt(int index){ return Imodules[index]; }
319  bool addImodule(ModuleInterface &imod);
320  bool removeImodule(ModuleInterface& imod);
321  void removeAllImodules() { Imodules.clear(); }
322 
323  int iapplicationCount() { return Iapplications.size(); }
324  ApplicationInterface& getIapplicationAt(int index){ return Iapplications[index]; }
327  void removeAllIapplications() { Iapplications.clear(); }
328 
329  int resourcesCount() { return resources.size(); }
330  ResYarpPort& getResourceAt(int index){ return resources[index]; }
331  bool addResource(ResYarpPort &res);
332  bool removeResource(ResYarpPort& res);
333 
334  void setPrefix(const char* szPrefix) { if(szPrefix) { strPrefix = szPrefix; } }
335  const char* getPrefix() { return strPrefix.c_str(); }
336  void setBasePrefix(const char* szPrefix) { if(szPrefix) { strBasePrefix = szPrefix; } }
337  const char* getBasePrefix() { return strBasePrefix.c_str(); }
338 
339 
340  void setXmlFile(const char* szFilename) { if(szFilename) { strXmlFile = szFilename;} }
341  const char* getXmlFile() { return strXmlFile.c_str(); }
342 
343  int connectionCount() { return connections.size(); }
344  Connection& getConnectionAt(int index){ return connections[index]; }
346  bool removeConnection(Connection& cnn);
347  //void updateConnectionPrefix();
348 
349  int arbitratorCount() { return arbitrators.size(); }
350  Arbitrator& getArbitratorAt(int index){ return arbitrators[index]; }
352  bool removeArbitrator(Arbitrator& arb);
353 
354  void setOwner(Node* owner){ appOwner = owner; }
355  Node* owner() { return appOwner; }
356 
357 
358  bool operator==(const Application& app) const {
359  return (strName == app.strName);
360  }
361 
362  void clear() {
363  strName.clear();
364  strVersion.clear();
365  strDescription.clear();
366  strPrefix.clear();
367  strBasePrefix.clear();
368  authors.clear();
369  Imodules.clear();
370  connections.clear();
371  strXmlFile.clear();
372  Iapplications.clear();
373  resources.clear();
374  appOwner=nullptr;
375  }
376 
377  GraphicModel& getModelBase() { return modelBase;}
378  void setModelBase(GraphicModel& mdl) { modelBase = mdl; };
379 
380  std::map<std::string, int> modList;
381 
382 protected:
383 
384 private:
385  std::string strName;
386  std::string strVersion;
387  std::string strDescription;
388  AuthorContainer authors;
389  IModuleContainer Imodules;
390  IApplicationContainer Iapplications;
391  ResourceContainer resources;
392  CnnContainer connections;
393  ArbContainer arbitrators;
394  std::string strPrefix;
395  std::string strBasePrefix;
396  std::string strXmlFile;
397  Node* appOwner;
398 
399  GraphicModel modelBase;
400 
401  IModuleIterator findImodule(ModuleInterface& imod);
402  IApplicationIterator findIapplication(ApplicationInterface& iapp);
403  ResourceIterator findResource(ResYarpPort& res);
404  CnnIterator findConnection(Connection& cnn);
405  ArbIterator findArbitrator(Arbitrator& arb);
406 
407 };
408 
409 typedef std::vector<Application*> ApplicaitonPContainer;
410 typedef std::vector<Application*>::iterator ApplicationPIterator;
411 
412 } // namespace yarp
413 } // namespace manager
414 
415 
416 #endif // __YARP_MANAGER_APPLICATION__
float t
static RFModule * module
Definition: RFModule.cpp:234
Class ApplicationInterface.
Definition: application.h:256
bool operator==(const ApplicationInterface &alt) const
Definition: application.h:266
void setModelBase(GraphicModel &mdl)
Definition: application.h:274
void setPrefix(const char *szPrefix)
Definition: application.h:263
ApplicationInterface(const char *szName)
Definition: application.h:259
virtual ~ApplicationInterface()=default
Class Application.
Definition: application.h:292
std::map< std::string, int > modList
Definition: application.h:378
bool removeAuthor(Author &author)
Connection & getConnectionAt(int index)
Definition: application.h:344
ResYarpPort & getResourceAt(int index)
Definition: application.h:330
const char * getPrefix()
Definition: application.h:335
void setName(const char *szName)
Definition: application.h:299
bool operator==(const Application &app) const
Definition: application.h:358
Arbitrator & addArbitrator(Arbitrator &arb)
bool addIapplication(ApplicationInterface &iapp)
Node * clone() override
void setBasePrefix(const char *szPrefix)
Definition: application.h:336
const char * getBasePrefix()
Definition: application.h:337
bool removeImodule(ModuleInterface &imod)
bool removeConnection(Connection &cnn)
const char * getVersion()
Definition: application.h:308
void addAuthor(Author &author)
Definition: application.h:312
void setXmlFile(const char *szFilename)
Definition: application.h:340
bool removeResource(ResYarpPort &res)
void setModelBase(GraphicModel &mdl)
Definition: application.h:378
void setVersion(const char *szVersion)
Definition: application.h:304
ApplicationInterface & getIapplicationAt(int index)
Definition: application.h:324
void setDescription(const char *szDesc)
Definition: application.h:305
Connection & addConnection(Connection &cnn)
ModuleInterface & getImoduleAt(int index)
Definition: application.h:318
void setOwner(Node *owner)
Definition: application.h:354
const char * getDescription()
Definition: application.h:309
GraphicModel & getModelBase()
Definition: application.h:377
Arbitrator & getArbitratorAt(int index)
Definition: application.h:350
bool removeArbitrator(Arbitrator &arb)
bool addResource(ResYarpPort &res)
bool removeIapplication(ApplicationInterface &iapp)
bool addImodule(ModuleInterface &imod)
Author & getAuthorAt(int index)
Definition: application.h:314
const char * getXmlFile()
Definition: application.h:341
void setPrefix(const char *szPrefix)
Definition: application.h:334
Application()
Class Application.
Definition: application.cpp:75
Class port Arbitrator.
Definition: arbitrator.h:28
Class Connection.
Definition: application.h:60
void setPriority(bool withprio)
Definition: application.h:112
void setTo(const char *szTo)
Definition: application.h:85
bool operator==(const Connection &alt) const
Definition: application.h:125
const char * qosFrom()
Definition: application.h:82
bool getFromExists() const
Definition: application.h:91
GraphicModel * getModel()
Definition: application.h:115
void setFromExternal(bool ext)
Definition: application.h:87
void setCarrier(const char *szCr)
Definition: application.h:86
void setToExists(bool exists)
Definition: application.h:90
void setToExternal(bool ext)
Definition: application.h:88
void setPersistent(bool per)
Definition: application.h:93
void setQosFrom(const char *szQos)
Definition: application.h:94
void setOwner(Node *owner)
Definition: application.h:104
OutputData * getCorOutputData()
Definition: application.h:110
void setCorOutputData(OutputData *out)
Definition: application.h:109
GraphicModel & getModelBase()
Definition: application.h:121
bool getToExists() const
Definition: application.h:92
void setFromExists(bool exists)
Definition: application.h:89
void setModelBase(GraphicModel &mdl)
Definition: application.h:122
void setId(const char *id)
Definition: application.h:101
void setFrom(const char *szFrom)
Definition: application.h:84
void setModel(GraphicModel *mdl)
Definition: application.h:116
InputData * getCorInputData()
Definition: application.h:108
void setQosTo(const char *szQos)
Definition: application.h:95
const char * qosTo()
Definition: application.h:83
Connection(const char *szFrom, const char *szTo, const char *szCr=nullptr)
Definition: application.h:63
virtual ~Connection()=default
const char * carrier()
Definition: application.h:81
void setCorInputData(InputData *in)
Definition: application.h:107
Class InputData.
Definition: data.h:25
Class ModuleInterface.
Definition: application.h:164
GraphicModel & getModelBase()
Definition: application.h:221
bool removePortmap(Portmap &portmap)
Definition: application.cpp:52
void setDisplay(const char *szDisplay)
Definition: application.h:186
void setHost(const char *szHost)
Definition: application.h:177
void setWorkDir(const char *szWDir)
Definition: application.h:180
virtual ~ModuleInterface()=default
bool addPortmap(Portmap &portmap)
Definition: application.cpp:45
void setParam(const char *szParam)
Definition: application.h:178
void setStdio(const char *szStdio)
Definition: application.h:181
void setTag(const char *szTag)
Definition: application.h:185
void setPrefix(const char *szPrefix)
Definition: application.h:183
Portmap & getPortmapAt(int index)
Definition: application.h:214
void addResource(ResYarpPort &res)
Definition: application.h:204
ModuleInterface(const char *szName)
Definition: application.h:167
ResourceContainer & getResources()
Definition: application.h:205
bool operator==(const ModuleInterface &modint) const
Definition: application.h:200
void setEnvironment(const char *szEnv)
Definition: application.h:184
void setBroker(const char *szBroker)
Definition: application.h:182
void setModelBase(GraphicModel &mdl)
Definition: application.h:222
Class Module.
Definition: module.h:103
a Node of a Graph
Definition: node.h:68
Class Portmap.
Definition: application.h:30
const char * newPort()
Definition: application.h:39
bool operator==(const Portmap &alt) const
Definition: application.h:40
const char * oldPort()
Definition: application.h:38
virtual ~Portmap()=default
Portmap(const char *szOld, const char *szNew)
Definition: application.h:33
std::vector< Portmap >::iterator PortmapIterator
Definition: application.h:52
std::vector< Application * >::iterator ApplicationPIterator
Definition: application.h:410
std::vector< Arbitrator > ArbContainer
Definition: arbitrator.h:94
std::vector< ResYarpPort > ResourceContainer
Definition: application.h:156
std::vector< ResYarpPort >::iterator ResourceIterator
Definition: application.h:157
std::vector< Portmap > PortmapContainer
Definition: application.h:51
std::vector< ModuleInterface >::iterator IModuleIterator
Definition: application.h:250
std::vector< Arbitrator >::iterator ArbIterator
Definition: arbitrator.h:95
std::vector< ApplicationInterface >::iterator IApplicationIterator
Definition: application.h:287
std::vector< Connection >::iterator CnnIterator
Definition: application.h:154
std::vector< ModuleInterface > IModuleContainer
Definition: application.h:249
std::vector< Author > AuthorContainer
Definition: module.h:93
std::vector< Application * > ApplicaitonPContainer
Definition: application.h:409
std::vector< Connection > CnnContainer
Definition: application.h:153
std::vector< ApplicationInterface > IApplicationContainer
Definition: application.h:286
The main, catch-all namespace for YARP.
Definition: environment.h:18