YARP  2.3.70
Yet Another Robot Platform
Module.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007 RobotCub Consortium
3  * Authors: Paul Fitzpatrick
4  * CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
5  */
6 
7 #ifndef YARP_OS_MODULE_H
8 #define YARP_OS_MODULE_H
9 
10 
11 #ifndef YARP_NO_DEPRECATED
12 
13 #include <yarp/os/IConfig.h>
14 #include <yarp/os/Bottle.h>
15 #include <yarp/os/Port.h>
16 #include <yarp/os/Time.h>
17 #include <yarp/os/BufferedPort.h>
18 #include <yarp/os/Property.h>
19 
20 
21 namespace yarp {
22  namespace os {
23  class Module;
24  }
25 }
26 
45 class YARP_OS_DEPRECATED_API yarp::os::Module : public IConfig {
46 protected:
47  // HACK Issue a deprecated warning in classes derived from yarp::os::Module
49  yarp__os__Module_is_deprecated_use_yarp__os__RFModule_instead issue_warning;
50 
51 public:
55  Module();
56 
60  virtual ~Module();
61 
62 
71  virtual double getPeriod();
72 
82  virtual bool updateModule();
83 
96  virtual bool interruptModule();
97 
108  virtual bool runModule();
109 
110 
128  virtual int runModule(int argc, char *argv[],
129  bool skipFirst = true);
130 
131 
146  virtual bool openFromCommand(int argc, char *argv[],
147  bool skipFirst = true);
148 
149 
159  virtual bool respond(const Bottle& command, Bottle& reply);
160 
166  virtual bool attach(Port& port);
167 
177  virtual bool attach(TypedReader<Bottle>& port, bool handleStream = false);
178 
184  virtual bool attachTerminal();
185 
190  bool isStopping();
191 
192 
198  ConstString getName(const char *subName = YARP_NULLPTR);
199 
204  void setName(const char *name);
205 
209 #ifndef DOXYGEN_SHOULD_SKIP_THIS
210  bool safeRespond(const Bottle& command, Bottle& reply);
211 #endif /*DOXYGEN_SHOULD_SKIP_THIS*/
212 
213 private:
214  Property& getState() { return state; }
215 
216  virtual bool basicRespond(const Bottle& command, Bottle& reply);
217 
219  Property state;
220  bool stopFlag;
221  ConstString name;
222 };
223 #endif // YARP_NO_DEPRECATED
224 
225 #endif // YARP_OS_MODULE_H
virtual bool updateModule()
Override this to do whatever your module needs to do.
virtual bool interruptModule()
Try to halt any ongoing operations by threads managed by the module.
bool isStopping()
Check if the module is shutting down.
virtual bool runModule()
Calls updateModule() until that returns false.
virtual bool respond(const Bottle &command, Bottle &reply)
Respond to a message.
Module()
Constructor.
void setName(const char *name)
Set the name of the module.
yarp__os__Module_is_deprecated_use_yarp__os__RFModule_instead issue_warning
Definition: Module.h:49
The main, catch-all namespace for YARP.
Property & getState()
Wrapper around respond() that is guaranteed to process system messages.
Definition: Module.h:214
bool stopFlag
Definition: Module.h:220
virtual bool attachTerminal()
Make any input from standard input (usually the keyboard) go to the respond() method.
virtual bool attach(Port &port)
Make any input from a Port object go to the respond() method.
virtual bool basicRespond(const Bottle &command, Bottle &reply)
virtual bool openFromCommand(int argc, char *argv[], bool skipFirst=true)
Calls open() with the result of interpreting a list of command line arguments.
virtual ~Module()
Destructor.
ConstString name
Definition: Module.h:221
ConstString getName(const char *subName=YARP_NULLPTR)
Return name of module, as set with –name flag or setName().
virtual double getPeriod()
You can override this to control the approximate periodicity at which updateModule() is called by run...
Property state
Definition: Module.h:219
void * implementation
Definition: Module.h:218