YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
module.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_MODULE_H
7#define YARP_MANAGER_MODULE_H
8
9
11#include <yarp/manager/node.h>
12#include <yarp/manager/data.h>
15#include <yarp/conf/api.h>
16
17namespace yarp::manager {
18
19
20class Author {
21public:
22 Author() {}
23 Author(const char* name, const char* email) {
24 if(name) { strName = name;}
25 if(email) { strEmail = email; }
26 }
28
29 void setName(const char* name) { if(name) { strName = name; } }
30 void setEmail(const char* email) { if(email) { strEmail = email; } }
31 const char* getName() { return strName.c_str(); }
32 const char* getEmail() { return strEmail.c_str(); }
33
34 bool operator==(const Author& alt) const {
35 return (strName == alt.strName);
36 }
37
38private:
39 std::string strName;
40 std::string strEmail;
41};
42
47
48public:
49 Argument(const char* szParam, bool required=false,
50 const char* szDesc=nullptr, bool _switch=false) {
51 if(szParam) { strParam = szParam; }
52 if(szDesc) { strDesc = szDesc; }
53 bRequired = required;
54 bSwitch = _switch;
55 if(bSwitch) { strDefault = "off"; }
56 strValue = strDefault;
57 }
58 virtual ~Argument(){}
59
60 void setParam(const char* szParam) { if(szParam) { strParam = szParam; } }
61 void setDefault(const char* szDefault) {if(szDefault) { strDefault = szDefault; } }
62 void setValue(const char* szValue) {if(szValue) { strValue = szValue; } }
63 const char* getDefault() { return strDefault.c_str(); }
64 const char* getParam() { return strParam.c_str(); }
65 const char* getValue() { return strValue.c_str(); }
66 const char* getDescription() { return strDesc.c_str(); }
67 bool isSwitch() { return bSwitch; }
68 bool isRequired() {return bRequired; }
69 bool operator==(const Argument& alt) const {
70 return (strParam == alt.strParam);
71 }
72
73protected:
74
75private:
76 std::string strParam;
77 std::string strDesc;
78 std::string strDefault;
79 std::string strValue;
80 bool bRequired;
81 bool bSwitch;
82};
83
84
85typedef std::vector<InputData> InputContainer;
86typedef std::vector<OutputData> OutputContainer;
87typedef std::vector<InputData>::iterator InputIterator;
88typedef std::vector<OutputData>::iterator OutputIterator;
89typedef std::vector<Author> AuthorContainer;
90typedef std::vector<Author>::iterator AuthorIterator;
91typedef std::vector<Argument> ArgumentContainer;
92typedef std::vector<Argument>::iterator ArgumentIterator;
93
94
95
99class Module : public Node{
100
101public:
102 Module();
103 Module(const char* szName);
104 Module(const Module &mod);
105 ~Module() override;
106 Node* clone() override;
107 Module& operator=(const Module& rhs);
108
109 void setName(const char* szName) { if(szName) { strName = szName; } }
110 void setRank(int rank) {iRank = rank;}
111 void setVersion(const char* szVersion) { if(szVersion) { strVersion = szVersion; } }
112 void setDescription(const char* szDesc) { if(szDesc) { strDescription = szDesc; } }
113 void setHost(const char* szHost) { if(szHost) { strHost = szHost; } }
114 void setForced(bool flag) { bForced = flag; }
115
116 bool setParam(const char* szParam);
117 void setXmlFile(const char* szFilename) { if(szFilename) { strXmlFile = szFilename;} }
118 void setWorkDir(const char* szWDir) { if(szWDir) { strWorkDir = szWDir; } }
119 void setStdio(const char* szStdio) { if(szStdio) { strStdio = szStdio; } }
120 void setBroker(const char* szBroker) { if(szBroker) { strBroker = szBroker; } }
121 void setPrefix(const char* szPrefix) { if(szPrefix) { strPrefix = szPrefix; } }
122 void setEnvironment(const char* szEnv) {if(szEnv) { strEnvironment = szEnv; } }
123 void setBasePrefix(const char* szPrefix) { if(szPrefix) { strBasePrefix = szPrefix; } }
124 void setNeedDeployer(bool need) { bNeedDeployer = need; }
125 void setDisplay(const char* szDisplay) {if(szDisplay) { strDisplay = szDisplay; } }
126
127 int getRank() { return iRank; }
128 const char* getName() { return strName.c_str(); }
129 const char* getVersion() { return strVersion.c_str(); }
130 const char* getDescription() { return strDescription.c_str(); }
131 const char* getHost() { return strHost.c_str(); }
132 bool getForced() { return bForced; }
133 bool getNeedDeployer() { return bNeedDeployer; }
134
135 const char* getParam() { return strParam.c_str(); }
136 const char* getXmlFile() { return strXmlFile.c_str(); }
137 const char* getWorkDir() { return strWorkDir.c_str(); }
138 const char* getStdio() { return strStdio.c_str(); }
139 const char* getBroker() { return strBroker.c_str(); }
140 const char* getPrefix() { return strPrefix.c_str(); }
141 const char* getEnvironment() { return strEnvironment.c_str(); }
142 const char* getBasePrefix() { return strBasePrefix.c_str(); }
143 const char* getDisplay() { return strDisplay.c_str(); }
144
145
146 int argumentCount() { return arguments.size(); }
147 Argument& getArgumentAt(int index){ return arguments[index]; }
148 int outputCount() { return outputs.size(); }
149 OutputData& getOutputAt(int index) { return outputs[index]; }
150 int inputCount() { return inputs.size(); }
151 InputData& getInputAt(int index) { return inputs[index]; }
152 int resourceCount() const { return resources.size(); }
153 GenericResource& getResourceAt(int index) const { return *(resources[index]); }
154
155 void addAuthor(Author& author) { authors.push_back(author); }
156 int authorCount() { return authors.size(); }
157 Author& getAuthorAt(int index) { return authors[index]; }
158 bool removeAuthor(Author& author);
159
160 bool addArgument(Argument& arg);
161 bool removeArgument(Argument& argument);
162 bool addOutput(OutputData& output);
163 bool removeOutput(OutputData& output);
164 bool addInput(InputData& input);
165 bool removeInput(InputData& input);
166 bool addResource(GenericResource& res);
168
169 void setPostExecWait(double t) { waitStart = t; }
170 double getPostExecWait() { return waitStart; }
171 void setPostStopWait(double t) { waitStop = t; }
172 double getPostStopWait() { return waitStop; }
173
174
175 void clearInputs() { inputs.clear(); }
176 void clearOutputs() { outputs.clear(); }
177 void clearResources() { resources.clear(); }
178
179 void setOwner(Node* owner) { modOwner = owner; }
180 Node* owner() { return modOwner; }
181
182 void clear();
183 // modelBased is used to keep the graphic and geometric
184 // information which is directly loaded from application
185 // description file.
186 GraphicModel& getModelBase() { return modelBase;}
187 void setModelBase(GraphicModel& mdl) { modelBase = mdl; };
188
189
190 friend class ModuleInterface;
191
192protected:
193
194private:
195 Node* modOwner;
196 std::string strName;
197 std::string strVersion;
198 std::string strDescription;
199 std::string strHost;
200 bool bForced;
201 int iRank;
202 ArgumentContainer arguments;
203 AuthorContainer authors;
204 OutputContainer outputs;
205 InputContainer inputs;
206 ResourcePContainer resources;
207
208 std::string strParam;
209 std::string strXmlFile;
210 std::string strWorkDir;
211 std::string strStdio;
212 std::string strBroker;
213 bool bNeedDeployer;
214 std::string strPrefix;
215 std::string strEnvironment;
216 std::string strBasePrefix;
217 double waitStart;
218 double waitStop;
219 std::string strDisplay;
220 GraphicModel modelBase;
221
222 ArgumentIterator findArgument(Argument& argument);
223 InputIterator findInput(InputData& input);
224 OutputIterator findOutput(OutputData& output);
225 ResourcePIterator findResource(GenericResource& output);
226 void swap(const Module &mod);
227 bool getParamValue(const char* key, bool bSwitch, std::string &param);
228};
229
230typedef std::vector<Module*> ModulePContainer;
231typedef std::vector<Module*>::iterator ModulePIterator;
232
233
234#define PRINT_MODULE(m)\
235 {\
236 std::cout<<"Name : "<<m->getName()<<'\n';\
237 std::cout<<"Desc : "<<m->getDescription()<<'\n';\
238 std::cout<<"Version : "<<m->getVersion()<<'\n';\
239 std::cout<<"Rank : "<<m->getRank()<<'\n';\
240 std::cout<<"Param : "<<'\n';\
241 for(int i=0; i<m->argumentCount(); i++)\
242 {\
243 std::cout<<" "<<m->getArgumentAt(i).getParam()<<" (";\
244 std::cout<<m->getArgumentAt(i).getDescription()<<")"<<'\n';\
245 }\
246 std::cout<<"Authors : "<<'\n';\
247 for(int i=0; i<m->authorCount(); i++)\
248 std::cout<<" "<<m->getAuthorAt(i).getName()<<" ("<<m->getAuthorAt(i).getEmail()<<")"<<'\n';\
249 /*std::cout<<"Platforms: "<<'\n';\
250 for(int i=0; i<m->platformCount(); i++)\
251 std::cout<<" "<<m->getPlatformAt(i).getOS()\
252 <<", "<<m->getPlatformAt(i).getDistribution()<<'\n';*/\
253 std::cout<<"Inputs : "<<'\n';\
254 for(int i=0; i<m->inputCount(); i++)\
255 {\
256 std::cout<<" "<<m->getInputAt(i).getName()\
257 <<", "<<m->getInputAt(i).getPort();\
258 if(m->getInputAt(i).isRequired())\
259 std::cout<<", [REQUIRED]";\
260 if(m->getInputAt(i).withPriority())\
261 std::cout<<", [PRIORITY]";\
262 std::cout<<'\n';\
263 }\
264 std::cout<<"Outputs : "<<'\n';\
265 for(int i=0; i<m->outputCount(); i++)\
266 std::cout<<" "<<m->getOutputAt(i).getName()\
267 <<", "<<m->getOutputAt(i).getPort()<<'\n';\
268 std::cout<<'\n';\
269 }
270
271} // namespace yarp::manager
272
273
274#endif // YARP_MANAGER_MODULE
float t
Class Argument.
Definition module.h:46
const char * getDefault()
Definition module.h:63
void setDefault(const char *szDefault)
Definition module.h:61
const char * getValue()
Definition module.h:65
virtual ~Argument()
Definition module.h:58
Argument(const char *szParam, bool required=false, const char *szDesc=nullptr, bool _switch=false)
Definition module.h:49
bool operator==(const Argument &alt) const
Definition module.h:69
void setValue(const char *szValue)
Definition module.h:62
void setParam(const char *szParam)
Definition module.h:60
const char * getDescription()
Definition module.h:66
const char * getParam()
Definition module.h:64
void setName(const char *name)
Definition module.h:29
bool operator==(const Author &alt) const
Definition module.h:34
const char * getName()
Definition module.h:31
const char * getEmail()
Definition module.h:32
Author(const char *name, const char *email)
Definition module.h:23
void setEmail(const char *email)
Definition module.h:30
Class InputData.
Definition data.h:21
Class ModuleInterface.
Class Module.
Definition module.h:99
bool removeInput(InputData &input)
Definition module.cpp:129
bool removeOutput(OutputData &output)
Definition module.cpp:108
void setStdio(const char *szStdio)
Definition module.h:119
bool removeResource(GenericResource &res)
Definition module.cpp:151
Argument & getArgumentAt(int index)
Definition module.h:147
GraphicModel & getModelBase()
Definition module.h:186
void setWorkDir(const char *szWDir)
Definition module.h:118
void setXmlFile(const char *szFilename)
Definition module.h:117
void setEnvironment(const char *szEnv)
Definition module.h:122
void setHost(const char *szHost)
Definition module.h:113
const char * getBroker()
Definition module.h:139
Node * clone() override
Definition module.cpp:75
bool removeAuthor(Author &author)
Definition module.cpp:162
void setNeedDeployer(bool need)
Definition module.h:124
const char * getBasePrefix()
Definition module.h:142
const char * getWorkDir()
Definition module.h:137
void setForced(bool flag)
Definition module.h:114
void setDescription(const char *szDesc)
Definition module.h:112
InputData & getInputAt(int index)
Definition module.h:151
void setPrefix(const char *szPrefix)
Definition module.h:121
int resourceCount() const
Definition module.h:152
void setModelBase(GraphicModel &mdl)
Definition module.h:187
void addAuthor(Author &author)
Definition module.h:155
const char * getDisplay()
Definition module.h:143
const char * getDescription()
Definition module.h:130
void setRank(int rank)
Definition module.h:110
bool removeArgument(Argument &argument)
Definition module.cpp:89
bool setParam(const char *szParam)
Definition module.cpp:254
void setPostStopWait(double t)
Definition module.h:171
void setName(const char *szName)
Definition module.h:109
const char * getPrefix()
Definition module.h:140
void setBasePrefix(const char *szPrefix)
Definition module.h:123
Author & getAuthorAt(int index)
Definition module.h:157
OutputData & getOutputAt(int index)
Definition module.h:149
const char * getParam()
Definition module.h:135
double getPostStopWait()
Definition module.h:172
void setBroker(const char *szBroker)
Definition module.h:120
const char * getHost()
Definition module.h:131
bool addArgument(Argument &arg)
Definition module.cpp:82
Module & operator=(const Module &rhs)
Definition module.cpp:31
const char * getXmlFile()
Definition module.h:136
const char * getStdio()
Definition module.h:138
double getPostExecWait()
Definition module.h:170
const char * getName()
Definition module.h:128
GenericResource & getResourceAt(int index) const
Definition module.h:153
bool addInput(InputData &input)
Definition module.cpp:121
void setOwner(Node *owner)
Definition module.h:179
const char * getEnvironment()
Definition module.h:141
bool addResource(GenericResource &res)
Definition module.cpp:142
const char * getVersion()
Definition module.h:129
void setPostExecWait(double t)
Definition module.h:169
bool addOutput(OutputData &output)
Definition module.cpp:100
void setVersion(const char *szVersion)
Definition module.h:111
void setDisplay(const char *szDisplay)
Definition module.h:125
a Node of a Graph
Definition node.h:64
std::vector< InputData > InputContainer
Definition module.h:85
std::vector< Author >::iterator AuthorIterator
Definition module.h:90
std::vector< GenericResource * >::iterator ResourcePIterator
Definition resource.h:59
std::vector< OutputData > OutputContainer
Definition module.h:86
std::vector< InputData >::iterator InputIterator
Definition module.h:87
std::vector< Module * > ModulePContainer
Definition module.h:230
std::vector< Argument > ArgumentContainer
Definition module.h:91
std::vector< Author > AuthorContainer
Definition module.h:89
std::vector< GenericResource * > ResourcePContainer
Definition resource.h:58
std::vector< OutputData >::iterator OutputIterator
Definition module.h:88
std::vector< Module * >::iterator ModulePIterator
Definition module.h:231
std::vector< Argument >::iterator ArgumentIterator
Definition module.h:92