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* module);
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 //void setModule(Module* mod) { module = mod; }
215 //Module* getModule() { return module;}
216
217 GraphicModel& getModelBase() { return modelBase;}
218 void setModelBase(GraphicModel& mdl) { modelBase = mdl; };
219
220
221
222protected:
223
224private:
225 std::string strName;
226 std::string strHost;
227 std::string strParam;
228 std::string strWorkDir;
229 std::string strStdio;
230 std::string strBroker;
231 std::string strPrefix;
232 std::string strEnvironment;
233 std::string strDisplay;
234 int iRank;
235 ResourceContainer resources;
236 double waitStart;
237 double waitStop;
238 PortmapContainer portmaps;
239 PortmapIterator findPortmap(Portmap& portmap);
240 std::string strTag;
241 GraphicModel modelBase;
242};
243
244
245typedef std::vector<ModuleInterface> IModuleContainer;
246typedef std::vector<ModuleInterface>::iterator IModuleIterator;
247
248
253
254public:
255 ApplicationInterface(const char* szName) {
256 if(szName) { strName = szName; }
257 }
258 virtual ~ApplicationInterface() = default;
259 void setPrefix(const char* szPrefix) { if(szPrefix) { strPrefix = szPrefix; } }
260 const char* getName() { return strName.c_str(); }
261 const char* getPrefix() { return strPrefix.c_str(); }
262 bool operator==(const ApplicationInterface& alt) const {
263 return (strName == alt.strName);
264 }
265
266 // modelBased is used to keep the graphic and geometric
267 // information which is directly loaded from application
268 // description file.
269 GraphicModel& getModelBase() { return modelBase;}
270 void setModelBase(GraphicModel& mdl) { modelBase = mdl; };
271
272
273protected:
274
275private:
276 std::string strName;
277 std::string strPrefix;
278 GraphicModel modelBase;
279};
280
281
282typedef std::vector<ApplicationInterface> IApplicationContainer;
283typedef std::vector<ApplicationInterface>::iterator IApplicationIterator;
284
288class Application : public Node{
289
290public:
291 Application();
292 Application(const char* szName);
293 Application(const Application &app);
294 ~Application() override;
295 void setName(const char* szName) {
296 if(szName){
297 strName = szName;
298 }
299 }
300 void setVersion(const char* szVersion) { if(szVersion) { strVersion = szVersion; } }
301 void setDescription(const char* szDesc) { if(szDesc) { strDescription = szDesc; } }
302 const char* getName() { return strName.c_str(); }
303 size_t getNameLenght() {return strName.length(); }
304 const char* getVersion() { return strVersion.c_str(); }
305 const char* getDescription() { return strDescription.c_str(); }
306 Node* clone() override;
307
308 void addAuthor(Author& author) { authors.push_back(author); }
309 int authorCount() { return authors.size(); }
310 Author& getAuthorAt(int index) { return authors[index]; }
311 bool removeAuthor(Author& author);
312
313 int imoduleCount() { return Imodules.size(); }
314 ModuleInterface& getImoduleAt(int index){ return Imodules[index]; }
315 bool addImodule(ModuleInterface &imod);
316 bool removeImodule(ModuleInterface& imod);
317 void removeAllImodules() { Imodules.clear(); }
318
319 int iapplicationCount() { return Iapplications.size(); }
320 ApplicationInterface& getIapplicationAt(int index){ return Iapplications[index]; }
323 void removeAllIapplications() { Iapplications.clear(); }
324
325 int resourcesCount() { return resources.size(); }
326 ResYarpPort& getResourceAt(int index){ return resources[index]; }
327 bool addResource(ResYarpPort &res);
328 bool removeResource(ResYarpPort& res);
329
330 void setPrefix(const char* szPrefix) { if(szPrefix) { strPrefix = szPrefix; } }
331 const char* getPrefix() { return strPrefix.c_str(); }
332 void setBasePrefix(const char* szPrefix) { if(szPrefix) { strBasePrefix = szPrefix; } }
333 const char* getBasePrefix() { return strBasePrefix.c_str(); }
334
335
336 void setXmlFile(const char* szFilename) { if(szFilename) { strXmlFile = szFilename;} }
337 const char* getXmlFile() { return strXmlFile.c_str(); }
338
339 int connectionCount() { return connections.size(); }
340 Connection& getConnectionAt(int index){ return connections[index]; }
342 bool removeConnection(Connection& cnn);
343 //void updateConnectionPrefix();
344
345 int arbitratorCount() { return arbitrators.size(); }
346 Arbitrator& getArbitratorAt(int index){ return arbitrators[index]; }
348 bool removeArbitrator(Arbitrator& arb);
349
350 void setOwner(Node* owner){ appOwner = owner; }
351 Node* owner() { return appOwner; }
352
353
354 bool operator==(const Application& app) const {
355 return (strName == app.strName);
356 }
357
358 void clear() {
359 strName.clear();
360 strVersion.clear();
361 strDescription.clear();
362 strPrefix.clear();
363 strBasePrefix.clear();
364 authors.clear();
365 Imodules.clear();
366 connections.clear();
367 strXmlFile.clear();
368 Iapplications.clear();
369 resources.clear();
370 appOwner=nullptr;
371 }
372
373 GraphicModel& getModelBase() { return modelBase;}
374 void setModelBase(GraphicModel& mdl) { modelBase = mdl; };
375
376 std::map<std::string, int> modList;
377
378protected:
379
380private:
381 std::string strName;
382 std::string strVersion;
383 std::string strDescription;
384 AuthorContainer authors;
385 IModuleContainer Imodules;
386 IApplicationContainer Iapplications;
387 ResourceContainer resources;
388 CnnContainer connections;
389 ArbContainer arbitrators;
390 std::string strPrefix;
391 std::string strBasePrefix;
392 std::string strXmlFile;
393 Node* appOwner;
394
395 GraphicModel modelBase;
396
397 IModuleIterator findImodule(ModuleInterface& imod);
398 IApplicationIterator findIapplication(ApplicationInterface& iapp);
399 ResourceIterator findResource(ResYarpPort& res);
400 CnnIterator findConnection(Connection& cnn);
401 ArbIterator findArbitrator(Arbitrator& arb);
402
403};
404
405typedef std::vector<Application*> ApplicaitonPContainer;
406typedef std::vector<Application*>::iterator ApplicationPIterator;
407
408} // namespace yarp::manager
409
410
411#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