YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches

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.
 
 Contact (const std::string &hostname, int port)
 Constructor by hostname and port.
 
 Contact (const std::string &carrier, const std::string &hostname, int port)
 Constructor by socket.
 
 Contact (const Contact &rhs)
 Copy constructor.
 
 Contact (Contact &&rhs) noexcept
 Move constructor.
 
Contactoperator= (const Contact &rhs)
 Copy assignment operator.
 
Contactoperator= (Contact &&rhs) noexcept
 Move assignment operator.
 
std::string getName () const
 Get the name associated with this Contact.
 
void setName (const std::string &name)
 Set the name associated with this Contact.
 
std::string getRegName () const
 Get the name associated with this Contact.
 
std::string getHost () const
 Get the host name associated with this Contact for socket communication.
 
void setHost (const std::string &hostname)
 Set the host name to be the input parameter.
 
int getPort () const
 Get the port number associated with this Contact for socket communication.
 
void setPort (int port)
 Set the port number to be the input parameter.
 
std::string getCarrier () const
 Get the carrier associated with this Contact for socket communication.
 
void setCarrier (const std::string &carrier)
 Set the carrier to use for this Contact.
 
const NestedContactgetNested () const
 Get the NestedContact containing extra information for this Contact.
 
void setNestedContact (const yarp::os::NestedContact &nestedContact)
 Sets the NestedContact containing extra information for this Contact.
 
bool hasTimeout () const
 Check if this Contact has a timeout.
 
float getTimeout () const
 Get timeout for this Address.
 
void setTimeout (float timeout)
 Set timeout for this Contact.
 
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.
 
bool isValid () const
 Checks if a Contact is tagged as valid.
 
std::string toString () const
 Get a textual representation of the Contact.
 
std::string toURI (bool includeCarrier=true) const
 Get a representation of the Contact as a URI.
 

Static Public Member Functions

static Contact fromConfig (const Searchable &config)
 Factory method.
 
static Contact fromString (const std::string &txt)
 Factory method.
 
static std::string convertHostToIp (const char *name)
 If the host is a machine name, convert it to a plausible IP address.
 

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 32 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 89 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 76 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 82 of file Contact.cpp.

◆ Contact() [4/5]

Contact::Contact ( const Contact rhs)

Copy constructor.

Parameters
rhsthe Contact to copy

Definition at line 97 of file Contact.cpp.

◆ Contact() [5/5]

Contact::Contact ( Contact &&  rhs)
noexcept

Move constructor.

Parameters
rhsthe Contact to be moved

Definition at line 102 of file Contact.cpp.

◆ ~Contact()

Contact::~Contact ( )
virtual

Destructor.

Definition at line 108 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 331 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 129 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 139 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 250 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 228 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 205 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 261 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 239 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 217 of file Contact.cpp.

◆ getTimeout()

float Contact::getTimeout ( ) const

Get timeout for this Address.

Returns
The timeout for this Address

Definition at line 277 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 272 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 298 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 113 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 121 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 255 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 233 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 222 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 266 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 244 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 288 of file Contact.cpp.

◆ setTimeout()

void Contact::setTimeout ( float  timeout)

Set timeout for this Contact.

Parameters
timeoutThe timeout to set.

Definition at line 282 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 303 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 313 of file Contact.cpp.


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