YARP  2.3.70
Yet Another Robot Platform
yarp::os::Contact Class Reference

Represents how to reach a part of a YARP network. More...

#include <yarp/os/Contact.h>

Public Member Functions

 Contact (const ConstString &name=ConstString(), const ConstString &carrier=ConstString(), const ConstString &hostname=ConstString(), int port=-1)
 Constructor. More...
 
 Contact (const ConstString &hostname, int port)
 Constructor by hostname and port. More...
 
 Contact (const ConstString &carrier, const ConstString &hostname, int port)
 Constructor by socket. More...
 
 Contact (const Contact &rhs)
 Copy constructor. More...
 
virtual ~Contact ()
 Destructor. More...
 
Contactoperator= (const Contact &rhs)
 Copy assignment operator. More...
 
ConstString getName () const
 Get the name associated with this Contact. More...
 
void setName (const ConstString &name)
 Set the name associated with this Contact. More...
 
ConstString getRegName () const
 Get the name associated with this Contact. More...
 
ConstString getHost () const
 Get the host name associated with this Contact for socket communication. More...
 
void setHost (const ConstString &hostname)
 Set the host name to be the input parameter. More...
 
int getPort () const
 Get the port number associated with this Contact for socket communication. More...
 
void setPort (int port)
 Set the port number to be the input parameter. More...
 
ConstString getCarrier () const
 Get the carrier associated with this Contact for socket communication. More...
 
void setCarrier (const ConstString &carrier)
 Set the carrier to use for this Contact. More...
 
const NestedContactgetNested () const
 Get the NestedContact containing extra information for this Contact. More...
 
void setNestedContact (const yarp::os::NestedContact &nestedContact)
 Sets the NestedContact containing extra information for this Contact. More...
 
bool hasTimeout () const
 Check if this Contact has a timeout. More...
 
float getTimeout () const
 Get timeout for this Address. More...
 
void setTimeout (float timeout)
 Set timeout for this Contact. More...
 
void setSocket (const ConstString &carrier, const ConstString &hostname, int port)
 Set information to a Contact about how to reach it using socket communication. More...
 
bool isValid () const
 Checks if a Contact is tagged as valid. More...
 
ConstString toString () const
 Get a textual representation of the Contact. More...
 
ConstString toURI (bool includeCarrier=true) const
 Get a representation of the Contact as a URI. More...
 
Contact addName (const ConstString &name) const
 Copies a Contact and sets the name for the new one. More...
 
Contact addCarrier (const ConstString &carrier) const
 Copies a Contact and sets the carrier for the new one. More...
 
Contact addHost (const ConstString &hostname) const
 Copies a Contact and sets the hostname for the new one. More...
 
Contact addPort (int port) const
 Returns a new Contact with the previous information plus the updated port number. More...
 
Contact addNested (const NestedContact &nestedContact) const
 Copies a Contact and sets the NestedContact for the new one. More...
 
Contact addSocket (const ConstString &carrier, const ConstString &hostname, int port) const
 Add information to a Contact about how to reach it using socket communication. More...
 

Static Public Member Functions

static Contact fromConfig (const Searchable &config)
 Factory method. More...
 
static Contact fromString (const ConstString &txt)
 Factory method. More...
 
static ConstString convertHostToIp (const char *name)
 If the host is a machine name, convert it to a plausible IP address. More...
 
static Contact empty ()
 Factory method. More...
 
static Contact invalid ()
 Factory method. More...
 
static Contact byName (const ConstString &name)
 Factory method. More...
 
static Contact byCarrier (const ConstString &carrier)
 Factory method. More...
 
static Contact bySocket (const ConstString &carrier, const ConstString &hostname, int port)
 Factory method. More...
 
static Contact byConfig (Searchable &config)
 Factory method. More...
 

Detailed Description

Represents how to reach a part of a YARP network.

May contain complete or partial information about network parameters. Use the constructors or the factory methods (Contact::fromString, Contact::fromConfig) to create Contact objects.

Definition at line 33 of file Contact.h.

Constructor & Destructor Documentation

◆ Contact() [1/4]

Contact::Contact ( const ConstString name = ConstString(),
const ConstString carrier = ConstString(),
const ConstString hostname = ConstString(),
int  port = -1 
)

Constructor.

Parameters
namethe name
carrierthe carrier
hostnamethe hostname
portthe port number

Definition at line 84 of file Contact.cpp.

◆ Contact() [2/4]

Contact::Contact ( const ConstString hostname,
int  port 
)

Constructor by hostname and port.

Parameters
hostnamethe hostname
portthe port number

Definition at line 71 of file Contact.cpp.

◆ Contact() [3/4]

Contact::Contact ( const ConstString carrier,
const ConstString hostname,
int  port 
)

Constructor by socket.

Parameters
carrierthe carrier
hostnamethe hostname
portthe port number

Definition at line 77 of file Contact.cpp.

◆ Contact() [4/4]

Contact::Contact ( const Contact rhs)

Copy constructor.

Parameters
rhsthe Contact to copy

Definition at line 92 of file Contact.cpp.

◆ ~Contact()

Contact::~Contact ( )
virtual

Destructor.

Definition at line 104 of file Contact.cpp.

Member Function Documentation

◆ addCarrier()

Contact Contact::addCarrier ( const ConstString carrier) const

Copies a Contact and sets the carrier for the new one.

Parameters
carrierthe carrier
Returns
the new Contact
Deprecated:
since YARP 2.3.68

Definition at line 425 of file Contact.cpp.

◆ addHost()

Contact Contact::addHost ( const ConstString hostname) const

Copies a Contact and sets the hostname for the new one.

Parameters
hostnamethe hostname
Returns
the new Contact
Deprecated:
since YARP 2.3.68

Definition at line 433 of file Contact.cpp.

◆ addName()

Contact Contact::addName ( const ConstString name) const

Copies a Contact and sets the name for the new one.

Parameters
namethe name
Returns
the new Contact
Deprecated:
since YARP 2.3.68

Definition at line 459 of file Contact.cpp.

◆ addNested()

Contact Contact::addNested ( const NestedContact nestedContact) const

Copies a Contact and sets the NestedContact for the new one.

Parameters
nestedContactthe nested Contact
Returns
the new Contact
Deprecated:
since YARP 2.3.68

Definition at line 466 of file Contact.cpp.

◆ addPort()

Contact Contact::addPort ( int  port) const

Returns a new Contact with the previous information plus the updated port number.

Parameters
portport number
Returns
a new Contact the the port number updated
Deprecated:
since YARP 2.3.68

Definition at line 441 of file Contact.cpp.

◆ addSocket()

Contact Contact::addSocket ( const ConstString carrier,
const ConstString hostname,
int  port 
) const

Add information to a Contact about how to reach it using socket communication.

Parameters
carrierthe carrier (network protocol) to use
hostnamethe name of the host machine (usually expressed as an IP address)
portthe number of the socket port to use
Returns
the new Contact with socket communication parameters
Deprecated:
since YARP 2.3.68

Definition at line 448 of file Contact.cpp.

◆ byCarrier()

Contact Contact::byCarrier ( const ConstString carrier)
static

Factory method.

Returns an unnamed Contact, with information about which carrier/protocol to use to reach that Contact.

Parameters
carrierthe carrier to add ("tcp", "udp", ...)
Returns
the new Contact

Definition at line 403 of file Contact.cpp.

◆ byConfig()

Contact Contact::byConfig ( Searchable config)
static

Factory method.

Returns a Contact configured from the information in config.

Parameters
configa Property, Bottle, or other Searchable containing the Contact configuration. Key names include "name", "ip", "port_number", "carrier"
Returns
the new Contact
Deprecated:
since YARP 2.3.68

Definition at line 421 of file Contact.cpp.

◆ byName()

Contact Contact::byName ( const ConstString name)
static

Factory method.

Returns a named Contact, with no information about how to reach that Contact.

Parameters
namethe name for the Contact
Returns
a named Contact
Deprecated:
since YARP 2.3.68

Definition at line 396 of file Contact.cpp.

◆ bySocket()

Contact Contact::bySocket ( const ConstString carrier,
const ConstString hostname,
int  port 
)
static

Factory method.

Creates an unnamed Contact, with information about how to reach it using socket communication.

Parameters
carrierthe carrier (network protocol) to use
hostnamethe name of the host machine (usually expressed as an IP address)
portthe number of the socket port to use
Returns
the new Contact
Deprecated:
since YARP 2.3.68

Definition at line 410 of file Contact.cpp.

◆ convertHostToIp()

ConstString Contact::convertHostToIp ( const char *  name)
static

If the host is a machine name, convert it to a plausible IP address.

Parameters
namethe name to convert

Definition at line 340 of file Contact.cpp.

◆ empty()

Contact Contact::empty ( )
static

Factory method.

Returns a new, blank, unnamed, invalid Contact.

Returns
a blank Contact
Deprecated:
since YARP 2.3.68

Definition at line 388 of file Contact.cpp.

◆ fromConfig()

Contact Contact::fromConfig ( const Searchable config)
static

Factory method.

Returns a Contact configured from the information in config.

Parameters
configa Property, Bottle, or other Searchable containing the Contact configuration. Key names include "name", "ip", "port_number", "carrier"
Returns
the new Contact

Definition at line 127 of file Contact.cpp.

◆ fromString()

Contact Contact::fromString ( const ConstString txt)
static

Factory method.

Parse a textual representation of a Contact.

Parameters
txtthe text to parse
Returns
the new Contact

Definition at line 137 of file Contact.cpp.

◆ getCarrier()

ConstString Contact::getCarrier ( ) const

Get the carrier associated with this Contact for socket communication.

Returns
The carrier associated with this Contact, or the empty string if no carrier is set

Definition at line 255 of file Contact.cpp.

◆ getHost()

ConstString Contact::getHost ( ) const

Get the host name associated with this Contact for socket communication.

Returns
The host name associated with this Contact, or the empty string if no host name is set

Definition at line 231 of file Contact.cpp.

◆ getName()

ConstString Contact::getName ( ) const

Get the name associated with this Contact.

If the name is not set, it is generated from hostname and port.

Returns
The name associated with this Contact, or the empty string if no name is set.

Definition at line 206 of file Contact.cpp.

◆ getNested()

const NestedContact & Contact::getNested ( ) const

Get the NestedContact containing extra information for this Contact.

Returns
the nested contact

Definition at line 267 of file Contact.cpp.

◆ getPort()

int Contact::getPort ( ) const

Get the port number associated with this Contact for socket communication.

Returns
The port number associated with this Contact, or <= 0 if no port number is set

Definition at line 243 of file Contact.cpp.

◆ getRegName()

ConstString Contact::getRegName ( ) const

Get the name associated with this Contact.

The regName is not generated and is set only using setName, or one of the factory methods (byName, byConfig, and fromString).

Returns
The regName associated with this Contact

Definition at line 219 of file Contact.cpp.

◆ getTimeout()

float Contact::getTimeout ( ) const

Get timeout for this Address.

Returns
The timeout for this Address

Definition at line 284 of file Contact.cpp.

◆ hasTimeout()

bool Contact::hasTimeout ( ) const

Check if this Contact has a timeout.

Returns
true iff this Contact has a timeout.

Definition at line 279 of file Contact.cpp.

◆ invalid()

Contact Contact::invalid ( )
static

Factory method.

Returns a new, invalid Contact.

Returns
an invalid Contact
Deprecated:
since YARP 2.3.68

Definition at line 392 of file Contact.cpp.

◆ isValid()

bool Contact::isValid ( ) const

Checks if a Contact is tagged as valid.

Returns
true iff Contact is tagged as valid. All Contact objects are valid except the one created by Contact::invalid.

Definition at line 307 of file Contact.cpp.

◆ operator=()

Contact & Contact::operator= ( const Contact rhs)

Copy assignment operator.

Parameters
rhsthe Contact to copy
Returns
this object

Definition at line 109 of file Contact.cpp.

◆ setCarrier()

void Contact::setCarrier ( const ConstString carrier)

Set the carrier to use for this Contact.

Parameters
carrierthe new carrier

Definition at line 260 of file Contact.cpp.

◆ setHost()

void Contact::setHost ( const ConstString hostname)

Set the host name to be the input parameter.

Parameters
hostnamethe new host name

Definition at line 236 of file Contact.cpp.

◆ setName()

void Contact::setName ( const ConstString name)

Set the name associated with this Contact.

Parameters
namethe new name

Definition at line 224 of file Contact.cpp.

◆ setNestedContact()

void Contact::setNestedContact ( const yarp::os::NestedContact nestedContact)

Sets the NestedContact containing extra information for this Contact.

Parameters
nestedContactthe nested Contact

Definition at line 272 of file Contact.cpp.

◆ setPort()

void Contact::setPort ( int  port)

Set the port number to be the input parameter.

Parameters
portthe new port number

Definition at line 248 of file Contact.cpp.

◆ setSocket()

void Contact::setSocket ( const ConstString carrier,
const ConstString hostname,
int  port 
)

Set information to a Contact about how to reach it using socket communication.

Parameters
carrierthe carrier (network protocol) to use
hostnamethe name of the host machine (usually expressed as an IP address)
portthe number of the socket port to use

Definition at line 296 of file Contact.cpp.

◆ setTimeout()

void Contact::setTimeout ( float  timeout)

Set timeout for this Contact.

Parameters
timeoutThe timeout to set.

Definition at line 289 of file Contact.cpp.

◆ toString()

ConstString Contact::toString ( ) const

Get a textual representation of the Contact.

Returns
a textual representation of the Contact

Definition at line 312 of file Contact.cpp.

◆ toURI()

ConstString Contact::toURI ( bool  includeCarrier = true) const

Get a representation of the Contact as a URI.

Parameters
includeCarrierif false do not include the carrier in the URI
Returns
a URI representation of the Contact

Definition at line 322 of file Contact.cpp.


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