SPAOP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | List of all members
lowrappers::Address Class Reference

A wrapper for Liblo's lo_address. More...

#include <Address.h>

Inheritance diagram for lowrappers::Address:
Inheritance graph
[legend]

Public Member Functions

 Address (const std::string &host, const std::string &port, int proto=LO_UDP)
 Constructor. More...
 
 Address (lo_address addr, bool isOwner=true)
 Constructor. More...
 
virtual ~Address ()
 Destructor. More...
 
 Address (const Address &other)
 Copy constructor. More...
 
bool setAddress (const std::string &newHost, const std::string &newPort)
 Updates this Address to send to a new destination. More...
 
int getTtl () const
 Returns the time-to-live value for this Address. More...
 
void setTtl (uint8_t ttl)
 Sets the time-to-live value for this Address. More...
 
std::string getIface () const
 Returns the name of the network interface that will be used for sending to this address. More...
 
void setIfaceByIp (const std::string &ip)
 Sets the network interface to use for sending to this address. More...
 
std::string url () const
 An URL describing this address. More...
 
std::string hostname () const
 The hostname of this adress. More...
 
std::string port () const
 The port/service name of this adress. More...
 
int send (const std::string &path, const std::string types,...) const
 Sends a OSC formatted message to this address. More...
 
int send (const std::string &path, const Message &msg) const
 Sends a OSC formatted message to this address. More...
 
int send (const std::string &path, const lo_message msg) const
 Sends a Liblo lo_message to this address. More...
 
int sendVAList (const std::string &path, const std::string &types, va_list args) const
 Sends a OSC formatted message to this address. More...
 
int sendFrom (const ServerThread &from, const std::string &path, const std::string types,...) const
 Sends a OSC formatted message to this address, from the same socket as the specified server. More...
 
int sendFrom (const ServerThread &from, const std::string &path, const Message &msg) const
 Sends a OSC formatted message to this address, from the same socket as the specified server. More...
 
int sendFrom (const ServerThread &from, const std::string &path, const lo_message msg) const
 Sends a Liblo lo_message to this address, from the same socket that a specified ServerThread is listening on. More...
 
int sendVAListFrom (const ServerThread &from, const std::string &path, const std::string &types, va_list args) const
 Sends a OSC formatted message to this address, from the same socket that a specified ServerThread is listening on. More...
 

Detailed Description

A wrapper for Liblo's lo_address.

Constructor & Destructor Documentation

lowrappers::Address::Address ( const std::string &  host,
const std::string &  port,
int  proto = LO_UDP 
)

Constructor.

Parameters
hostA valid hostname or IP string (see the Liblo documentation for what exactly is supported).
portA valid port number or service name (see the Liblo documentation for what exactly is supported).
protoThe protocol to use (LO_UDP, LO_TCP or LO_UNIX). See the Liblo documentation for details.
Exceptions
std::bad_allocin case memory allocation for the internal lo_address fails.
lowrappers::Address::Address ( lo_address  addr,
bool  isOwner = true 
)

Constructor.

Parameters
addrThe address to sent to.
isOwnerSpecifies who is responsible for freeing the lo_address addr (by calling lo_address_free). If set to true, this Address object will call lo_address_free on addr when it is destroyed or when a new Address is set. If set to false, the responsibility to call lo_address_free remains with the caller of this constructor.
lowrappers::Address::~Address ( )
virtual

Destructor.

Will call lo_address_delete on the lo_address stored internally if this Address object is the owner of the lo_address.

lowrappers::Address::Address ( const Address other)

Copy constructor.

Will create a new copy of the lo_address stored within other, so the new Address will be owner of its lo_address while other's ownership status will remain unchanged.

Parameters
otherThe Adress to be copied.

Member Function Documentation

std::string lowrappers::Address::getIface ( ) const

Returns the name of the network interface that will be used for sending to this address.

This is relevant for sending multicast messages.

Returns
The name of the network interface that will be used for sending to this address. Might be "(null)" if no interface has been set.
int lowrappers::Address::getTtl ( ) const

Returns the time-to-live value for this Address.

Returns
The time-to-live value for this Address.
std::string lowrappers::Address::hostname ( ) const

The hostname of this adress.

Returns
the hostname of this adress.
std::string lowrappers::Address::port ( ) const

The port/service name of this adress.

Returns
the port/service name of this adress.
int lowrappers::Address::send ( const std::string &  path,
const std::string  types,
  ... 
) const

Sends a OSC formatted message to this address.

Parameters
pathThe OSC path of the message.
typesThe types of the data items in the message.
...The data values to be transmitted. The types of the arguments passed here must agree with the types specified in the type parameter.

return -1 on failure.

int lowrappers::Address::send ( const std::string &  path,
const Message msg 
) const

Sends a OSC formatted message to this address.

Parameters
pathThe OSC path of the message.
msgThe Message to be sent.
Returns
-1 on failure.
int lowrappers::Address::send ( const std::string &  path,
const lo_message  msg 
) const

Sends a Liblo lo_message to this address.

Parameters
pathThe OSC path of the message.
msgThe Message to be sent.
Returns
-1 on failure.
int lowrappers::Address::sendFrom ( const ServerThread from,
const std::string &  path,
const std::string  types,
  ... 
) const

Sends a OSC formatted message to this address, from the same socket as the specified server.

Parameters
fromThe server to send the message from.
pathThe OSC path of the message.
typesThe types of the data items in the message.
...The data values to be transmitted. The types of the arguments passed here must agree with the types specified in the type parameter.
Returns
-1 on failure.
int lowrappers::Address::sendFrom ( const ServerThread from,
const std::string &  path,
const Message msg 
) const

Sends a OSC formatted message to this address, from the same socket as the specified server.

Parameters
fromThe server to send the message from.
pathThe OSC path of the message.
msgThe Message to be sent.
Returns
-1 on failure.
int lowrappers::Address::sendFrom ( const ServerThread from,
const std::string &  path,
const lo_message  msg 
) const

Sends a Liblo lo_message to this address, from the same socket that a specified ServerThread is listening on.

Parameters
fromThe server to send the message from.
pathThe OSC path of the message.
msgThe Message to be sent.
Returns
-1 on failure.
int lowrappers::Address::sendVAList ( const std::string &  path,
const std::string &  types,
va_list  args 
) const

Sends a OSC formatted message to this address.

Parameters are passed as a va_list. This allows other varargs methods to pass on their arguments.

Parameters
pathThe OSC path of the message.
typesThe types of the data items in the message.
argsThe data values to be transmitted. The types of the arguments passed here (and their length) must agree with the types specified in the type parameter.
Returns
-1 on failure.
int lowrappers::Address::sendVAListFrom ( const ServerThread from,
const std::string &  path,
const std::string &  types,
va_list  args 
) const

Sends a OSC formatted message to this address, from the same socket that a specified ServerThread is listening on.

Parameters are passed as a va_list. This allows other varargs methods to pass on their arguments.

Parameters
fromThe server to send the message from.
pathThe OSC path of the message.
typesThe types of the data items in the message.
argsThe data values to be transmitted. The types of the arguments passed here (and their length) must agree with the types specified in the type parameter.
Returns
-1 on failure.
bool lowrappers::Address::setAddress ( const std::string &  newHost,
const std::string &  newPort 
)

Updates this Address to send to a new destination.

(Internally, a new lo_adress is created, replacing the old one.)

Parameters
newHostA valid hostname or IP string (see the Liblo documentation for what exactly is supported).
newPortA valid port number or service name (see the Liblo documentation for what exactly is supported).
Returns
true if the address has been changed, false if it could not be changed due to a memory allocation failure.
Warning
This does not validate the given address parameters in any way, the return value only signals memory allocation problems.
void lowrappers::Address::setIfaceByIp ( const std::string &  ip)

Sets the network interface to use for sending to this address.

Parameters
ipThe IP of the local interface where the messages shall be sent from.
void lowrappers::Address::setTtl ( uint8_t  ttl)

Sets the time-to-live value for this Address.

This is required for sending UDP multicast messages.

Parameters
ttlThe time-to-live value for this Address (between 1 and 255).
std::string lowrappers::Address::url ( ) const

An URL describing this address.

Returns
An URL describing this address.