YARP  2.3.68+272-20170522.1+git50f0ae7
Yet Another Robot Platform
yarp::os::NetworkBase Class Reference

Utilities for manipulating the YARP network, excluding initialization and shutdown. More...

#include <yarp/os/Network.h>

+ Inheritance diagram for yarp::os::NetworkBase:

Static Public Member Functions

static void initMinimum ()
 Basic system initialization, not including plugins. More...
 
static void autoInitMinimum ()
 Basic system initialization, not including plugins. More...
 
static void finiMinimum ()
 Deinitialization, excluding plugins. More...
 
static bool connect (const ConstString &src, const ConstString &dest, const ConstString &carrier="", bool quiet=true)
 Request that an output port connect to an input port. More...
 
static bool connect (const char *src, const char *dest, const char *carrier, bool quiet=true)
 
static bool connect (const ConstString &src, const ConstString &dest, const ContactStyle &style)
 Request that an output port connect to an input port. More...
 
static bool disconnect (const ConstString &src, const ConstString &dest, bool quiet=true)
 Request that an output port disconnect from an input port. More...
 
static bool disconnect (const ConstString &src, const ConstString &dest, const ContactStyle &style)
 Request that an output port disconnect from an input port. More...
 
static bool isConnected (const ConstString &src, const ConstString &dest, bool quiet=true)
 Check if a connection exists between two ports. More...
 
static bool isConnected (const ConstString &src, const ConstString &dest, const ContactStyle &style)
 Check if a connection exists between two ports. More...
 
static bool exists (const ConstString &port, bool quiet=true)
 Check for a port to be ready and responsive. More...
 
static bool exists (const ConstString &port, const ContactStyle &style)
 Check for a port to be ready and responsive. More...
 
static bool sync (const ConstString &port, bool quiet=true)
 Wait for a port to be ready and responsive. More...
 
static int main (int argc, char *argv[])
 The standard main method for the YARP companion utility. More...
 
static int runNameServer (int argc, char *argv[])
 Run a basic YARP name server. More...
 
static void assertion (bool shouldBeTrue)
 An assertion. More...
 
static Contact queryName (const ConstString &name)
 Find out information about a registered name. More...
 
static Contact registerName (const ConstString &name)
 Register a name with the name server. More...
 
static Contact registerContact (const Contact &contact)
 Register contact information with the name server. More...
 
static Contact unregisterName (const ConstString &name)
 Removes the registration for a name from the name server. More...
 
static Contact unregisterContact (const Contact &contact)
 Removes the registration for a contact from the name server. More...
 
static bool setProperty (const char *name, const char *key, const Value &value)
 Names registered with the nameserver can have arbitrary key->value properties associated with them. More...
 
static ValuegetProperty (const char *name, const char *key)
 Look up the value associated with a particular key for a named entry registered with the nameserver. More...
 
static ConstString getNameServerName ()
 Get the name of the port associated with the nameserver (usually "/root", but this can be overwritten by the "yarp namespace" command). More...
 
static Contact getNameServerContact ()
 Get the contact information for the port associated with the nameserver (usually "/root", but this can be overwritten by the "yarp namespace" command). More...
 
static bool setNameServerName (const ConstString &name)
 Set the name of the port associated with the nameserver (usually "/root", but this can be overwritten by the "yarp namespace" command). More...
 
static bool setLocalMode (bool flag)
 Chooses whether communication is process-local. More...
 
static bool getLocalMode ()
 Get current value of flag "localMode", see setLocalMode function. More...
 
static ConstString readString (bool *eof=YARP_NULLPTR)
 Read a line of arbitrary length from standard input. More...
 
static bool write (const Contact &contact, PortWriter &cmd, PortReader &reply, bool admin=false, bool quiet=false, double timeout=-1)
 Send a single command to a port and await a single response. More...
 
static bool write (const Contact &contact, PortWriter &cmd, PortReader &reply, const ContactStyle &style)
 Variant write method with options bundled into a yarp::os::ContactStyle (there was getting to be too many of them). More...
 
static bool writeToNameServer (PortWriter &cmd, PortReader &reply, const ContactStyle &style)
 Variant write method specialized to name server. More...
 
static bool write (const ConstString &port_name, PortWriter &cmd, PortReader &reply)
 Variant write method with port name specified directly. More...
 
static bool checkNetwork ()
 Check if the YARP Network is up and running. More...
 
static bool checkNetwork (double timeout)
 Check if a name server is running and responding. More...
 
static bool initialized ()
 Returns true if YARP has been fully initialized. More...
 
static void setVerbosity (int verbosity)
 Set level of verbosity of YARP messages. More...
 
static void queryBypass (NameStore *store)
 Redirect queries to another source. More...
 
static NameStoregetQueryBypass ()
 
static ConstString getEnvironment (const char *key, bool *found=YARP_NULLPTR)
 Read a variable from the environment. More...
 
static void setEnvironment (const ConstString &key, const ConstString &val)
 Set or change an environment variable. More...
 
static void unsetEnvironment (const ConstString &key)
 Remove an environment variable. More...
 
static ConstString getDirectorySeparator ()
 Get an OS-appropriate directory separator (e.g. More...
 
static ConstString getPathSeparator ()
 Get an OS-appropriate path separator (e.g. More...
 
static bool registerCarrier (const char *name, const char *dll)
 Register a carrier to make available at runtime. More...
 
static void lock ()
 Call wait() on a global mutual-exclusion semaphore allocated by YARP. More...
 
static void unlock ()
 Call post() on a global mutual-exclusion semaphore allocated by YARP. More...
 
static bool localNetworkAllocation ()
 Check where the name server in use expects processes to allocate their own network resources. More...
 
static Contact detectNameServer (bool useDetectedServer, bool &scanNeeded, bool &serverUsed)
 Scan for an available name server. More...
 
static bool setNameServerContact (Contact &nameServerContact)
 Set explicitly the nameserver information. More...
 
static ConstString getConfigFile (const char *fname)
 Search for a configuration file in YARP's standard config file path. More...
 
static int getDefaultPortRange ()
 Under normal operation, YARP has a name server that manages a pool of (socket) ports starting at a point specified by the YARP_PORT_RANGE environment variable (or 10000 if that is not set). More...
 
static bool setConnectionQos (const ConstString &src, const ConstString &dest, const QosStyle &srcStyle, const QosStyle &destStyle, bool quiet=true)
 Adjust the Qos preferences of a connection. More...
 
static bool setConnectionQos (const ConstString &src, const ConstString &dest, const QosStyle &style, bool quiet=true)
 Adjust the Qos preferences of a connection. More...
 
static bool getConnectionQos (const ConstString &src, const ConstString &dest, QosStyle &srcStyle, QosStyle &destStyle, bool quiet=true)
 Gets the Qos preferences of a connection. More...
 

Detailed Description

Utilities for manipulating the YARP network, excluding initialization and shutdown.

Definition at line 43 of file Network.h.

Member Function Documentation

◆ assertion()

void NetworkBase::assertion ( bool  shouldBeTrue)
static

An assertion.

Should be true. If false, this will be reported, and YARP will shut down. In general, this is an OS-specific process.

Parameters
shouldBeTruethe asserted truth value.

Definition at line 738 of file Network.cpp.

◆ autoInitMinimum()

void NetworkBase::autoInitMinimum ( )
static

Basic system initialization, not including plugins.

A matching finiMinimum() will be called automatically on program termination.

Definition at line 609 of file Network.cpp.

◆ checkNetwork() [1/2]

bool NetworkBase::checkNetwork ( )
static

Check if the YARP Network is up and running.

Basically, checks if a yarp name server is running and responding.

Returns
true if the YARP Network is active.

Definition at line 1021 of file Network.cpp.

◆ checkNetwork() [2/2]

bool NetworkBase::checkNetwork ( double  timeout)
static

Check if a name server is running and responding.

Parameters
timeouttime in seconds to wait for a response from a name server.
Returns
true if the name server responds within the given time.

Definition at line 1026 of file Network.cpp.

◆ connect() [1/3]

bool NetworkBase::connect ( const ConstString src,
const ConstString dest,
const ConstString carrier = "",
bool  quiet = true 
)
static

Request that an output port connect to an input port.

Parameters
srcthe name of an output port
destthe name of an input port
carrierthe name of the protocol to use (tcp/udp/mcast)
quietsuppress messages displayed upon success/failure
Returns
true on success, false on failure
Examples:
carrier/carrier_stub.cpp, framerate/main.cpp, os/buffered_port.cpp, os/simple_receiver.cpp, port_power/ex0002_connector.cpp, port_power/ex0502_raw_target_connector.cpp, and portaudio/sound_receiver.cpp.

Definition at line 521 of file Network.cpp.

◆ connect() [2/3]

static bool yarp::os::NetworkBase::connect ( const char *  src,
const char *  dest,
const char *  carrier,
bool  quiet = true 
)
inlinestatic

Definition at line 77 of file Network.h.

◆ connect() [3/3]

bool NetworkBase::connect ( const ConstString src,
const ConstString dest,
const ContactStyle style 
)
static

Request that an output port connect to an input port.

Parameters
srcthe name of an output port
destthe name of an input port
styleoptions for connection
Returns
true on success, false on failure

Definition at line 532 of file Network.cpp.

◆ detectNameServer()

Contact NetworkBase::detectNameServer ( bool  useDetectedServer,
bool &  scanNeeded,
bool &  serverUsed 
)
static

Scan for an available name server.

Parameters
useDetectedServerIf a name server is found, use it.
scanNeededTrue if a network scan was done to find server.
serverUsedTrue if a server was found and configured for use.
Returns
address of name server.

Definition at line 1429 of file Network.cpp.

◆ disconnect() [1/2]

bool NetworkBase::disconnect ( const ConstString src,
const ConstString dest,
bool  quiet = true 
)
static

Request that an output port disconnect from an input port.

Parameters
srcthe name of an output port
destthe name of an input port
quietsuppress messages displayed upon success/failure
Returns
true on success, false on failure

Definition at line 539 of file Network.cpp.

◆ disconnect() [2/2]

bool NetworkBase::disconnect ( const ConstString src,
const ConstString dest,
const ContactStyle style 
)
static

Request that an output port disconnect from an input port.

Parameters
srcthe name of an output port
destthe name of an input port
styleoptions for network communication related to disconnection
Returns
true on success, false on failure

Definition at line 547 of file Network.cpp.

◆ exists() [1/2]

bool NetworkBase::exists ( const ConstString port,
bool  quiet = true 
)
static

Check for a port to be ready and responsive.

Parameters
portthe name of a port
quietsuppress messages displayed during check
Returns
true on success, false on failure

Definition at line 562 of file Network.cpp.

◆ exists() [2/2]

bool NetworkBase::exists ( const ConstString port,
const ContactStyle style 
)
static

Check for a port to be ready and responsive.

Parameters
portthe name of a port
styleoptions for network communication
Returns
true on success, false on failure

Definition at line 568 of file Network.cpp.

◆ finiMinimum()

void NetworkBase::finiMinimum ( )
static

Deinitialization, excluding plugins.

Definition at line 664 of file Network.cpp.

◆ getConfigFile()

ConstString NetworkBase::getConfigFile ( const char *  fname)
static

Search for a configuration file in YARP's standard config file path.

Return full name of file including path. File not guaranteed to exist.

Returns
full name of file including path

Definition at line 1462 of file Network.cpp.

◆ getConnectionQos()

bool NetworkBase::getConnectionQos ( const ConstString src,
const ConstString dest,
QosStyle srcStyle,
QosStyle destStyle,
bool  quiet = true 
)
static

Gets the Qos preferences of a connection.

Parameters
srcthe name of an output port
destthe name of an input port
srcStylethe Qos preference of the output port
destStylethe Qos preference of the input port
Returns
true if the Qos preferences are gotten correctly

Definition at line 860 of file Network.cpp.

◆ getDefaultPortRange()

int NetworkBase::getDefaultPortRange ( )
static

Under normal operation, YARP has a name server that manages a pool of (socket) ports starting at a point specified by the YARP_PORT_RANGE environment variable (or 10000 if that is not set).

Returns
the beginning of YARP's port range, as specified by the environment variable YARP_PORT_RANGE (or 10000 if not set)

Definition at line 1467 of file Network.cpp.

◆ getDirectorySeparator()

ConstString NetworkBase::getDirectorySeparator ( )
static

Get an OS-appropriate directory separator (e.g.

"/" on linux)

Definition at line 1078 of file Network.cpp.

◆ getEnvironment()

ConstString NetworkBase::getEnvironment ( const char *  key,
bool *  found = YARP_NULLPTR 
)
static

Read a variable from the environment.

Parameters
keythe variable to read
foundan optional variable to set to true iff variable is found
Returns
the value of the environment variable, or "" if not found

Definition at line 1050 of file Network.cpp.

◆ getLocalMode()

bool NetworkBase::getLocalMode ( )
static

Get current value of flag "localMode", see setLocalMode function.

Returns
state of the flag.

Definition at line 733 of file Network.cpp.

◆ getNameServerContact()

Contact NetworkBase::getNameServerContact ( )
static

Get the contact information for the port associated with the nameserver (usually "/root", but this can be overwritten by the "yarp namespace" command).

Returns
contact informatoin for the port associated with the nameserver

Definition at line 1005 of file Network.cpp.

◆ getNameServerName()

ConstString NetworkBase::getNameServerName ( )
static

Get the name of the port associated with the nameserver (usually "/root", but this can be overwritten by the "yarp namespace" command).

Returns
name of the port associated with the nameserver

Definition at line 998 of file Network.cpp.

◆ getPathSeparator()

ConstString NetworkBase::getPathSeparator ( )
static

Get an OS-appropriate path separator (e.g.

":" on linux)

Definition at line 1088 of file Network.cpp.

◆ getProperty()

Value * NetworkBase::getProperty ( const char *  name,
const char *  key 
)
static

Look up the value associated with a particular key for a named entry registered with the nameserver.

Parameters
nameThe name registered with the nameserver (typically a port).
keyThe key to provide a value for.
Returns
the value associated with the given key.

Definition at line 724 of file Network.cpp.

◆ getQueryBypass()

NameStore * NetworkBase::getQueryBypass ( )
static

Definition at line 1044 of file Network.cpp.

◆ initialized()

bool NetworkBase::initialized ( )
static

Returns true if YARP has been fully initialized.

Returns
true if YARP has been initialized (by creating a yarp::os::Network object or calling yarp::os::Network::init).

Definition at line 1031 of file Network.cpp.

◆ initMinimum()

void NetworkBase::initMinimum ( )
static

Basic system initialization, not including plugins.

Must eventually make a matching call to finiMinimum().

Definition at line 616 of file Network.cpp.

◆ isConnected() [1/2]

bool NetworkBase::isConnected ( const ConstString src,
const ConstString dest,
bool  quiet = true 
)
static

Check if a connection exists between two ports.

Parameters
srcthe name of an output port
destthe name of an input port
quietsuppress messages displayed upon success/failure
Returns
true if there is a connection

Definition at line 554 of file Network.cpp.

◆ isConnected() [2/2]

bool NetworkBase::isConnected ( const ConstString src,
const ConstString dest,
const ContactStyle style 
)
static

Check if a connection exists between two ports.

Parameters
srcthe name of an output port
destthe name of an input port
styleoptions for network communication
Returns
true if there is a connection

Definition at line 985 of file Network.cpp.

◆ localNetworkAllocation()

bool NetworkBase::localNetworkAllocation ( )
static

Check where the name server in use expects processes to allocate their own network resources.

Returns
true if local network resource allocation is expected.

Definition at line 1423 of file Network.cpp.

◆ lock()

void NetworkBase::lock ( )
static

Call wait() on a global mutual-exclusion semaphore allocated by YARP.

Definition at line 1098 of file Network.cpp.

◆ main()

int NetworkBase::main ( int  argc,
char *  argv[] 
)
static

The standard main method for the YARP companion utility.

This method is not thread-safe; it initializes and shuts down YARP, the effect of which varies between operating systems. Do not call this method if there are other threads using YARP.

Parameters
argcargument count
argvcommand line arguments
Returns
0 on success, non-zero on failure

Definition at line 596 of file Network.cpp.

◆ queryBypass()

void NetworkBase::queryBypass ( NameStore store)
static

Redirect queries to another source.

Definition at line 1040 of file Network.cpp.

◆ queryName()

Contact NetworkBase::queryName ( const ConstString name)
static

Find out information about a registered name.

This communicates with the name server to find out what is known about how to contact the entity with the given name (if one exists).

Parameters
namethe name to query
Returns
full contact information for the name. If nothing is known about the name, the returned contact is invalid (Contact::isValid returns false)

Definition at line 681 of file Network.cpp.

◆ readString()

ConstString NetworkBase::readString ( bool *  eof = YARP_NULLPTR)
static

Read a line of arbitrary length from standard input.

Parameters
eofIf non-null, this is set to true if standard input has closed. Note that some heuristics are used to guess if someone on windows has hit the equivalent of ctrl-D, the key to close a stream on unix. These heuristics will lead to false detects in some cases if the user hits strange keys.
Returns
A string from standard input, without newline or linefeed characters.

Definition at line 745 of file Network.cpp.

◆ registerCarrier()

bool NetworkBase::registerCarrier ( const char *  name,
const char *  dll 
)
static

Register a carrier to make available at runtime.

Parameters
namename of carrier
dllname of shared library carrier is implemented in
Returns
true if carrier was registered

Definition at line 1396 of file Network.cpp.

◆ registerContact()

Contact NetworkBase::registerContact ( const Contact contact)
static

Register contact information with the name server.

The name server will fill in any extra information needed to make the contact information complete..

Parameters
contactthe proposed contact information (may be incomplete)
Returns
the contact information now associated with a name (in other words, what Contact::queryName would now return)

Definition at line 701 of file Network.cpp.

◆ registerName()

Contact NetworkBase::registerName ( const ConstString name)
static

Register a name with the name server.

The name server will allocate a way to contact that name. It is up to you to make sure that this works.

Parameters
namethe name to register
Returns
the contact information now associated with that name (in other words, what Contact::queryName would now return)

Definition at line 695 of file Network.cpp.

◆ runNameServer()

int NetworkBase::runNameServer ( int  argc,
char *  argv[] 
)
static

Run a basic YARP name server.

Parameters
argcargument count
argvcommand line arguments
Returns
0 on success, non-zero on failure

Definition at line 600 of file Network.cpp.

◆ setConnectionQos() [1/2]

bool NetworkBase::setConnectionQos ( const ConstString src,
const ConstString dest,
const QosStyle srcStyle,
const QosStyle destStyle,
bool  quiet = true 
)
static

Adjust the Qos preferences of a connection.

Parameters
srcthe name of an output port
destthe name of an input port
srcStylethe Qos preference of the output port
destStylethe Qos preference of the input port
Returns
true if the Qos preferences are set correctly

Definition at line 754 of file Network.cpp.

◆ setConnectionQos() [2/2]

bool NetworkBase::setConnectionQos ( const ConstString src,
const ConstString dest,
const QosStyle style,
bool  quiet = true 
)
static

Adjust the Qos preferences of a connection.

Parameters
srcthe name of an output port
destthe name of an input port
stylethe Qos preference of both input and output ports
Returns
true if the Qos preferences are set correctly

Definition at line 749 of file Network.cpp.

◆ setEnvironment()

void NetworkBase::setEnvironment ( const ConstString key,
const ConstString val 
)
static

Set or change an environment variable.

Parameters
keythe variable to set or change
valthe target value

Definition at line 1062 of file Network.cpp.

◆ setLocalMode()

bool NetworkBase::setLocalMode ( bool  flag)
static

Chooses whether communication is process-local.

Call this with flag=true to avoid ever consulting an external nameserver.

Parameters
flagtrue if communication should be local to the calling process.
Returns
prior state of this flag.
Examples:
os/buffered_port.cpp.

Definition at line 729 of file Network.cpp.

◆ setNameServerContact()

bool NetworkBase::setNameServerContact ( Contact nameServerContact)
static

Set explicitly the nameserver information.

Parameters
nameServerContactthe NameServer contact information (e.g. IP, port)
Returns
true if succeed. False otherwise

Definition at line 1437 of file Network.cpp.

◆ setNameServerName()

bool NetworkBase::setNameServerName ( const ConstString name)
static

Set the name of the port associated with the nameserver (usually "/root", but this can be overwritten by the "yarp namespace" command).

This method is not thread-safe. Do not call this command while ports are being registered/unregistered or connections are being made/broken in another thread.

Returns
true on success

Definition at line 1011 of file Network.cpp.

◆ setProperty()

bool NetworkBase::setProperty ( const char *  name,
const char *  key,
const Value value 
)
static

Names registered with the nameserver can have arbitrary key->value properties associated with them.

This method sets a value associated with a particular key for a named entry (typically a port name).

Parameters
nameThe name registered with the nameserver (typically a port).
keyThe key to provide a value for.
valueThe value associated with the key for the named entry.
Returns
true on success.

Definition at line 717 of file Network.cpp.

◆ setVerbosity()

void NetworkBase::setVerbosity ( int  verbosity)
static

Set level of verbosity of YARP messages.

Parameters
verbosity-1 inhibits messages, 0 is normal, 1 is verbose

Definition at line 1036 of file Network.cpp.

◆ sync()

bool NetworkBase::sync ( const ConstString port,
bool  quiet = true 
)
static

Wait for a port to be ready and responsive.

Parameters
portthe name of a port
quietsuppress messages displayed during wait
Returns
true on success, false on failure

Definition at line 588 of file Network.cpp.

◆ unlock()

void NetworkBase::unlock ( )
static

Call post() on a global mutual-exclusion semaphore allocated by YARP.

Definition at line 1103 of file Network.cpp.

◆ unregisterContact()

Contact NetworkBase::unregisterContact ( const Contact contact)
static

Removes the registration for a contact from the name server.

Parameters
contactthe contact to unregister
Returns
the contact information now associated with its former name (in other words, what Contact::queryName would now return). This will be the invalid contact (Contact::isValid is false).

Definition at line 712 of file Network.cpp.

◆ unregisterName()

Contact NetworkBase::unregisterName ( const ConstString name)
static

Removes the registration for a name from the name server.

Parameters
namethe name to unregister
Returns
the contact information now associated with that name (in other words, what Contact::queryName would now return). This will be the invalid contact (Contact::isValid is false).

Definition at line 707 of file Network.cpp.

◆ unsetEnvironment()

void NetworkBase::unsetEnvironment ( const ConstString key)
static

Remove an environment variable.

Parameters
keythe variable to remove

Definition at line 1070 of file Network.cpp.

◆ write() [1/3]

bool NetworkBase::write ( const Contact contact,
PortWriter cmd,
PortReader reply,
bool  admin = false,
bool  quiet = false,
double  timeout = -1 
)
static

Send a single command to a port and await a single response.

Similar to the "yarp rpc" command line utility. If you want to send several such commands, you'd be better off making a port and using its methods for writing with replies.

Parameters
contactthe target to communicate with
cmdthe message to send
replythe response is read here
admintrue for administrative message, false for regular data
quiettrue to suppress error messages
timeoutactivity timeout in seconds
Returns
true on success

Definition at line 870 of file Network.cpp.

◆ write() [2/3]

bool NetworkBase::write ( const Contact contact,
PortWriter cmd,
PortReader reply,
const ContactStyle style 
)
static

Variant write method with options bundled into a yarp::os::ContactStyle (there was getting to be too many of them).

Parameters
contactthe target to communicate with
cmdthe message to send
replythe response if any is read here
styleoptions for the connection
Returns
true on success

Definition at line 884 of file Network.cpp.

◆ write() [3/3]

bool NetworkBase::write ( const ConstString port_name,
PortWriter cmd,
PortReader reply 
)
static

Variant write method with port name specified directly.

Parameters
port_namethe target to communicate with
cmdthe message to send
replythe response is read here
Returns
true on success

Definition at line 979 of file Network.cpp.

◆ writeToNameServer()

bool NetworkBase::writeToNameServer ( PortWriter cmd,
PortReader reply,
const ContactStyle style 
)
static

Variant write method specialized to name server.

Parameters
cmdthe message to send
replythe response if any is read here
styleoptions for the connection
Returns
true on success

Definition at line 1450 of file Network.cpp.


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