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