YARP  2.3.70.2
Yet Another Robot Platform
yarp Class Reference

A base-class for standard Yarp modules. More...

#include <yarp/os/Module.h>

+ Inheritance diagram for yarp:

Classes

class  yarp__os__Module_is_deprecated_use_yarp__os__RFModule_instead
 

Public Member Functions

 Module ()
 Constructor. More...
 
virtual ~Module ()
 Destructor. More...
 
virtual double getPeriod ()
 You can override this to control the approximate periodicity at which updateModule() is called by runModule(). More...
 
virtual bool updateModule ()
 Override this to do whatever your module needs to do. More...
 
virtual bool interruptModule ()
 Try to halt any ongoing operations by threads managed by the module. More...
 
virtual bool runModule ()
 Calls updateModule() until that returns false. More...
 
virtual int runModule (int argc, char *argv[], bool skipFirst=true)
 Simple helper method to call openFromCommand(), then runModule(). More...
 
virtual bool openFromCommand (int argc, char *argv[], bool skipFirst=true)
 Calls open() with the result of interpreting a list of command line arguments. More...
 
virtual bool respond (const Bottle &command, Bottle &reply)
 Respond to a message. More...
 
virtual bool attach (Port &port)
 Make any input from a Port object go to the respond() method. More...
 
virtual bool attach (TypedReader< Bottle > &port, bool handleStream=false)
 Make any input from a BufferedPort or PortReaderBuffer object go to the respond() method. More...
 
virtual bool attachTerminal ()
 Make any input from standard input (usually the keyboard) go to the respond() method. More...
 
bool isStopping ()
 Check if the module is shutting down. More...
 
ConstString getName (const char *subName=YARP_NULLPTR)
 Return name of module, as set with –name flag or setName(). More...
 
void setName (const char *name)
 Set the name of the module. More...
 
 TcpRosStream (TwoWayStream *delegate, bool sender, bool reply, bool service, int raw, const char *kind)
 
virtual ~TcpRosStream ()
 
virtual yarp::os::InputStreamgetInputStream () override
 
virtual yarp::os::OutputStreamgetOutputStream () override
 
virtual const yarp::os::ContactgetLocalAddress () override
 
virtual const yarp::os::ContactgetRemoteAddress () override
 
virtual bool isOk () override
 
virtual void reset () override
 
virtual void close () override
 
virtual void beginPacket () override
 
virtual void endPacket () override
 
virtual void write (const Bytes &b) override
 
virtual YARP_SSIZE_T read (const Bytes &b) override
 
virtual void interrupt () override
 
void updateKind (const char *kind, bool sender, bool reply)
 

Static Public Member Functions

static std::map< std::string, std::string > rosToKind ()
 
static std::string rosToKind (const char *rosname)
 
static bool configureTwiddler (WireTwiddler &twiddler, const char *txt, const char *prompt, bool sender, bool reply)
 

Protected Attributes

yarp__os__Module_is_deprecated_use_yarp__os__RFModule_instead issue_warning
 

Private Member Functions

Property & getState ()
 Wrapper around respond() that is guaranteed to process system messages. More...
 
virtual bool basicRespond (const Bottle &command, Bottle &reply)
 

Private Attributes

void * implementation
 
Property state
 
bool stopFlag
 
ConstString name
 
TwoWayStream * delegate
 
int raw
 
BlobNetworkHeader header
 
ManagedBytes scan
 
char * cursor
 
int remaining
 
int phase
 
bool expectTwiddle
 
WireTwiddler twiddler
 
yarp::os::ConstString kind
 
WireTwiddlerReader twiddlerReader
 
bool initiative
 
bool setInitiative
 

Detailed Description

A base-class for standard Yarp modules.

If you're building a large system and want to regularize how parts of your system are configured and run, this class may be helpful to you. Modules are expected to be configurable via IConfig::open() – in other words, their configuration can be passed in from the command line, from configuration files, the network, or GUIs. Typically, modules will create a set of ports for communicating with other modules. We encourage, when possible, that at least one of those ports be hooked up to the respond() method with attach(). For non graphical applications, it is also convenient to hook up standard input/output to the respond() method as well using attachTerminal().

Deprecated:
Since 2.3.65. Use yarp::os::RFModule instead.

Definition at line 45 of file Module.h.

Constructor & Destructor Documentation

◆ ~Module()

virtual yarp::~Module ( )
virtual

Destructor.

◆ ~TcpRosStream()

virtual yarp::~TcpRosStream ( )
inlinevirtual

Definition at line 68 of file TcpRosStream.h.

Member Function Documentation

◆ attach() [1/2]

virtual bool yarp::attach ( Port &  port)
virtual

Make any input from a Port object go to the respond() method.

Parameters
portthe port to attach
Returns
true if port was attached correctly.
Examples:
os/image_process_module.cpp.

◆ attach() [2/2]

virtual bool yarp::attach ( TypedReader< Bottle > &  port,
bool  handleStream = false 
)
virtual

Make any input from a BufferedPort or PortReaderBuffer object go to the respond() method.

Parameters
portthe port or buffer to attach
handleStreamcontrol whether streaming messages (messages that don't expect replies) are also sent to respond(). If they are, replies will be discarded.
Returns
true if port was attached correctly.

◆ attachTerminal()

virtual bool yarp::attachTerminal ( )
virtual

Make any input from standard input (usually the keyboard) go to the respond() method.

The reply will be send to standard output.

Returns
true on success.

◆ basicRespond()

virtual bool yarp::basicRespond ( const Bottle &  command,
Bottle &  reply 
)
privatevirtual

◆ beginPacket()

virtual void yarp::beginPacket ( )
inlineoverridevirtual

Definition at line 99 of file TcpRosStream.h.

◆ close()

virtual void yarp::close ( void  )
inlineoverridevirtual
Examples:
dev/fake_motor.cpp.

Definition at line 95 of file TcpRosStream.h.

◆ configureTwiddler()

static bool yarp::configureTwiddler ( WireTwiddler &  twiddler,
const char *  txt,
const char *  prompt,
bool  sender,
bool  reply 
)
static

◆ endPacket()

virtual void yarp::endPacket ( )
inlineoverridevirtual

Definition at line 104 of file TcpRosStream.h.

◆ getInputStream()

virtual yarp::os::InputStream& yarp::getInputStream ( )
inlineoverridevirtual

Definition at line 75 of file TcpRosStream.h.

◆ getLocalAddress()

virtual const yarp::os::Contact& yarp::getLocalAddress ( )
inlineoverridevirtual

Definition at line 79 of file TcpRosStream.h.

◆ getName()

ConstString yarp::getName ( const char *  subName = YARP_NULLPTR)

Return name of module, as set with –name flag or setName().

Parameters
subNameget nested name with this at the end
Returns
the name of the module
Examples:
os/image_process_module.cpp.

◆ getOutputStream()

virtual yarp::os::OutputStream& yarp::getOutputStream ( )
inlineoverridevirtual

Definition at line 76 of file TcpRosStream.h.

◆ getPeriod()

virtual double yarp::getPeriod ( )
virtual

You can override this to control the approximate periodicity at which updateModule() is called by runModule().

By default, it returns 0 (no delay).

Returns
the desired period between successive calls to updateModule()

◆ getRemoteAddress()

virtual const yarp::os::Contact& yarp::getRemoteAddress ( )
inlineoverridevirtual

Definition at line 83 of file TcpRosStream.h.

◆ getState()

Property& yarp::getState ( )
inlineprivate

Wrapper around respond() that is guaranteed to process system messages.

Definition at line 214 of file Module.h.

◆ interrupt()

virtual void yarp::interrupt ( )
inlineoverridevirtual

Definition at line 114 of file TcpRosStream.h.

◆ interruptModule()

virtual bool yarp::interruptModule ( )
virtual

Try to halt any ongoing operations by threads managed by the module.

By default it does nothing - you may want to override this. If you have created any ports, and have any threads that are might be blocked on reading data from those ports, this is a good place to add calls to BufferedPort::interrupt() or Port::interrupt(). Don't assume this method will always be called on shutdown, or if called will complete before shutdown.

Returns
true if there was no catastrophic failure
Examples:
os/image_process_module.cpp.

◆ isOk()

virtual bool yarp::isOk ( )
inlineoverridevirtual

Definition at line 87 of file TcpRosStream.h.

◆ isStopping()

bool yarp::isStopping ( )

Check if the module is shutting down.

Returns
true if the module is shutting down.
Examples:
os/threads.cpp.

◆ Module()

yarp::Module ( )

Constructor.

◆ openFromCommand()

virtual bool yarp::openFromCommand ( int  argc,
char *  argv[],
bool  skipFirst = true 
)
virtual

Calls open() with the result of interpreting a list of command line arguments.

Also calls attachTerminal(). If the command line is "--file filename.ini" it will read the desired configuration from the named file. The configuration file should be or the form needed for yarp::os::Property::fromConfigFile.

Parameters
argcthe number of arguments
argvthe list of arguments
skipFirstset to true if the first argument should be skipped (which is the right thing to do for arguments passed to main())
Returns
true/false upon success/failure

◆ read()

virtual YARP_SSIZE_T yarp::read ( const Bytes &  b)
overridevirtual

◆ reset()

virtual void yarp::reset ( )
inlineoverridevirtual

Definition at line 91 of file TcpRosStream.h.

◆ respond()

virtual bool yarp::respond ( const Bottle &  command,
Bottle &  reply 
)
virtual

Respond to a message.

You can override this to respond to messages in your own way. It is useful, if your module doesn't know what to do with a message, to call Module::respond() for any default responses.

Parameters
commandthe message received
replythe response you wish to make
Returns
true if there was no critical failure

◆ rosToKind() [1/2]

static std::map<std::string, std::string> yarp::rosToKind ( )
static

◆ rosToKind() [2/2]

static std::string yarp::rosToKind ( const char *  rosname)
static

◆ runModule() [1/2]

virtual bool yarp::runModule ( )
virtual

Calls updateModule() until that returns false.

updateModule() is called every getPeriod() seconds. Be aware that the the respond() command could be asycnhronously at any time, if there is input from the standard input or a port connected via attach().

Returns
true on success

◆ runModule() [2/2]

virtual int yarp::runModule ( int  argc,
char *  argv[],
bool  skipFirst = true 
)
virtual

Simple helper method to call openFromCommand(), then runModule().

Most modules that run as a single executable will want to do this. Their main() method would be something like:

int main(int argc, char *argv[]) {
Network yarp;
YourModule module;
return module.runModule(argc, argv);
}
Parameters
argcthe number of arguments
argvthe list of arguments
skipFirstset to true if the first argument should be skipped (which is the right thing to do for arguments passed to main())
Returns
0 upon success, non-zero upon failure

◆ setName()

void yarp::setName ( const char *  name)

Set the name of the module.

Parameters
namethe desired name of the module

◆ TcpRosStream()

yarp::TcpRosStream ( TwoWayStream *  delegate,
bool  sender,
bool  reply,
bool  service,
int  raw,
const char *  kind 
)
inline

Definition at line 50 of file TcpRosStream.h.

◆ updateKind()

void yarp::updateKind ( const char *  kind,
bool  sender,
bool  reply 
)

◆ updateModule()

virtual bool yarp::updateModule ( )
virtual

Override this to do whatever your module needs to do.

When your module wants to stop, return false. The module's actual work could be done during this call, or it could just check the state of a thread running in the background.

Returns
true iff module should continue
Examples:
os/image_process_module.cpp.

◆ write()

virtual void yarp::write ( const Bytes &  b)
overridevirtual
Examples:
cuda/cuda_gpu.cpp.

Member Data Documentation

◆ cursor

char* yarp::cursor
private

Definition at line 40 of file TcpRosStream.h.

◆ delegate

TwoWayStream* yarp::delegate
private

Definition at line 36 of file TcpRosStream.h.

◆ expectTwiddle

bool yarp::expectTwiddle
private

Definition at line 43 of file TcpRosStream.h.

◆ header

BlobNetworkHeader yarp::header
private

Definition at line 38 of file TcpRosStream.h.

◆ implementation

void* yarp::implementation
private

Definition at line 218 of file Module.h.

◆ initiative

bool yarp::initiative
private

Definition at line 47 of file TcpRosStream.h.

◆ issue_warning

Definition at line 49 of file Module.h.

◆ kind

yarp::os::ConstString yarp::kind
private

Definition at line 45 of file TcpRosStream.h.

◆ name

ConstString yarp::name
private

Definition at line 221 of file Module.h.

◆ phase

int yarp::phase
private

Definition at line 42 of file TcpRosStream.h.

◆ raw

int yarp::raw
private

Definition at line 37 of file TcpRosStream.h.

◆ remaining

int yarp::remaining
private

Definition at line 41 of file TcpRosStream.h.

◆ scan

ManagedBytes yarp::scan
private

Definition at line 39 of file TcpRosStream.h.

◆ setInitiative

bool yarp::setInitiative
private

Definition at line 48 of file TcpRosStream.h.

◆ state

Property yarp::state
private
Examples:
os/database.cpp.

Definition at line 219 of file Module.h.

◆ stopFlag

bool yarp::stopFlag
private

Definition at line 220 of file Module.h.

◆ twiddler

WireTwiddler yarp::twiddler
private

Definition at line 44 of file TcpRosStream.h.

◆ twiddlerReader

WireTwiddlerReader yarp::twiddlerReader
private

Definition at line 46 of file TcpRosStream.h.


The documentation for this class was generated from the following files: