YARP
Yet Another Robot Platform

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

#include <yarp/os/Contact.h>

Public Member Functions

 Contact (const std::string &name=std::string(), const std::string &carrier=std::string(), const std::string &hostname=std::string(), int port=-1)
 Constructor. More...
 
 Contact (const std::string &hostname, int port)
 Constructor by hostname and port. More...
 
 Contact (const std::string &carrier, const std::string &hostname, int port)
 Constructor by socket. More...
 
 Contact (const Contact &rhs)
 Copy constructor. More...
 
 Contact (Contact &&rhs) noexcept
 Move constructor. More...
 
virtual ~Contact ()
 Destructor. More...
 
Contactoperator= (const Contact &rhs)
 Copy assignment operator. More...
 
Contactoperator= (Contact &&rhs) noexcept
 Move assignment operator. More...
 
std::string getName () const
 Get the name associated with this Contact. More...
 
void setName (const std::string &name)
 Set the name associated with this Contact. More...
 
std::string getRegName () const
 Get the name associated with this Contact. More...
 
std::string getHost () const
 Get the host name associated with this Contact for socket communication. More...
 
void setHost (const std::string &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...
 
std::string getCarrier () const
 Get the carrier associated with this Contact for socket communication. More...
 
void setCarrier (const std::string &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 std::string &carrier, const std::string &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...
 
std::string toString () const
 Get a textual representation of the Contact. More...
 
std::string toURI (bool includeCarrier=true) const
 Get a representation of the Contact as a URI. More...
 

Static Public Member Functions

static Contact fromConfig (const Searchable &config)
 Factory method. More...
 
static Contact fromString (const std::string &txt)
 Factory method. More...
 
static std::string convertHostToIp (const char *name)
 If the host is a machine name, convert it to a plausible IP address. 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 38 of file Contact.h.

Constructor & Destructor Documentation

◆ Contact() [1/5]

Contact::Contact ( const std::string &  name = std::string(),
const std::string &  carrier = std::string(),
const std::string &  hostname = std::string(),
int  port = -1 
)

Constructor.

Parameters
namethe name
carrierthe carrier
hostnamethe hostname
portthe port number

Definition at line 92 of file Contact.cpp.

◆ Contact() [2/5]

Contact::Contact ( const std::string &  hostname,
int  port 
)

Constructor by hostname and port.

Parameters
hostnamethe hostname
portthe port number

Definition at line 79 of file Contact.cpp.

◆ Contact() [3/5]

Contact::Contact ( const std::string &  carrier,
const std::string &  hostname,
int  port 
)

Constructor by socket.

Parameters
carrierthe carrier
hostnamethe hostname
portthe port number

Definition at line 85 of file Contact.cpp.

◆ Contact() [4/5]

Contact::Contact ( const Contact rhs)

Copy constructor.

Parameters
rhsthe Contact to copy

Definition at line 100 of file Contact.cpp.

◆ Contact() [5/5]

Contact::Contact ( Contact &&  rhs)
noexcept

Move constructor.

Parameters
rhsthe Contact to be moved

Definition at line 105 of file Contact.cpp.

◆ ~Contact()

Contact::~Contact ( )
virtual

Destructor.

Definition at line 111 of file Contact.cpp.

Member Function Documentation

◆ convertHostToIp()

std::string 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 334 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 132 of file Contact.cpp.

◆ fromString()

Contact Contact::fromString ( const std::string &  txt)
static

Factory method.

Parse a textual representation of a Contact.

Parameters
txtthe text to parse
Returns
the new Contact

Definition at line 142 of file Contact.cpp.

◆ getCarrier()

std::string 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 253 of file Contact.cpp.

◆ getHost()

std::string 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()

std::string 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 208 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 264 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 242 of file Contact.cpp.

◆ getRegName()

std::string 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 220 of file Contact.cpp.

◆ getTimeout()

float Contact::getTimeout ( ) const

Get timeout for this Address.

Returns
The timeout for this Address

Definition at line 280 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 275 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 301 of file Contact.cpp.

◆ operator=() [1/2]

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

Copy assignment operator.

Parameters
rhsthe Contact to copy
Returns
this object

Definition at line 116 of file Contact.cpp.

◆ operator=() [2/2]

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

Move assignment operator.

Parameters
rhsthe Contact to be moved
Returns
this object

Definition at line 124 of file Contact.cpp.

◆ setCarrier()

void Contact::setCarrier ( const std::string &  carrier)

Set the carrier to use for this Contact.

Parameters
carrierthe new carrier

Definition at line 258 of file Contact.cpp.

◆ setHost()

void Contact::setHost ( const std::string &  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 std::string &  name)

Set the name associated with this Contact.

Parameters
namethe new name

Definition at line 225 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 269 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 247 of file Contact.cpp.

◆ setSocket()

void Contact::setSocket ( const std::string &  carrier,
const std::string &  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 291 of file Contact.cpp.

◆ setTimeout()

void Contact::setTimeout ( float  timeout)

Set timeout for this Contact.

Parameters
timeoutThe timeout to set.

Definition at line 285 of file Contact.cpp.

◆ toString()

std::string Contact::toString ( ) const

Get a textual representation of the Contact.

Returns
a textual representation of the Contact

Definition at line 306 of file Contact.cpp.

◆ toURI()

std::string 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 316 of file Contact.cpp.


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