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

A server thread with Liblo-style callback capabilities. More...

#include <ServerThread.h>

Inheritance diagram for lowrappers::ServerThread:
Inheritance graph
[legend]
Collaboration diagram for lowrappers::ServerThread:
Collaboration graph
[legend]

Classes

class  Listener
 A listener interface for listeners to be called by the ServerThread when incoming OSC messages are received. More...
 

Public Member Functions

 ServerThread (lo_err_handler err_h)
 Constructor. More...
 
 ServerThread (const std::string &port, lo_err_handler err_h)
 Constructor. More...
 
 ServerThread (const std::string &group, const std::string &port, lo_err_handler err_h)
 Constructor. More...
 
 ServerThread (const std::string &group, const std::string &port, const std::string &ifaceIp, lo_err_handler err_h)
 Constructor. More...
 
virtual ~ServerThread ()
 Destructor. More...
 
bool isValid () const
 Checks if initialization was successfull. More...
 
std::string url () const
 An URL describing the address of the server thread. More...
 
int port () const
 The port number that the server thread has bound to. More...
 
bool addMethod (const char *path, const char *typespec, lo_method_handler h, void *user_data)
 Adds a lo_method_handler to this server thread. More...
 
bool addListener (const char *path, const char *typespec, Listener *listener)
 Adds a Listener to this server thread. More...
 
void delMethod (const char *path, const char *typespec)
 Delete a method from this server thread. More...
 
- Public Member Functions inherited from thread::Thread
 Thread ()
 Constructor. More...
 
virtual ~Thread ()
 Destructor. More...
 
void start ()
 Starts the Thread. More...
 
void stop ()
 Sets the internal flag stopped_ to true. More...
 
void join ()
 Joins the thread. More...
 

Friends

class Address
 Address is friend class so it can access the internal lo_server for sending messages from its port. More...
 

Additional Inherited Members

- Protected Member Functions inherited from thread::Thread
bool isStopped () const
 Returns true if the thread was stopped. More...
 

Detailed Description

A server thread with Liblo-style callback capabilities.

This is NOT a wrapper for Liblo's lo_server_thread because the lo_server_thread relies on the pthread library. For better compability with Windows, this class uses the thread::Thread that relies on std::thread (the tradeoff for this is: C++11 is now required).

Warning
Differently from the lo_server_thread where a call to lo_server_thread will automatically join the thread, stop() and join() both need to be called for a clean shutdown.

Constructor & Destructor Documentation

lowrappers::ServerThread::ServerThread ( lo_err_handler  err_h)

Constructor.

An unused port will be chosen by the system, its number may be retrieved with ServerThread::port so it can be passed to clients.

Parameters
err_hA function that will be called in the event of an error being raised. The function prototype is defined in lo_types.h
lowrappers::ServerThread::ServerThread ( const std::string &  port,
lo_err_handler  err_h 
)

Constructor.

Parameters
portA decimal port number, service name or UNIX domain socket path may be passed.
err_hA function that will be called in the event of an error being raised. The function prototype is defined in lo_types.h
lowrappers::ServerThread::ServerThread ( const std::string &  group,
const std::string &  port,
lo_err_handler  err_h 
)

Constructor.

Creates a ServerThread that joins a specified multicast group.

Parameters
groupThe multicast group to join.
portA decimal port number, service name or UNIX domain socket path may be passed.
err_hA function that will be called in the event of an error being raised. The function prototype is defined in lo_types.h
lowrappers::ServerThread::ServerThread ( const std::string &  group,
const std::string &  port,
const std::string &  ifaceIp,
lo_err_handler  err_h 
)

Constructor.

Creates a ServerThread that joins a specified multicast group, listening on a specified interface.

Parameters
groupThe multicast group to join.
portA decimal port number, service name or UNIX domain socket path may be passed. Note that differently from lo_server_tread_new, passing NULL is not allowed.
ifaceIpA string specifying the network interface to use by its IP.
err_hA function that will be called in the event of an error being raised. The function prototype is defined in lo_types.h
lowrappers::ServerThread::~ServerThread ( )
virtual

Destructor.

Member Function Documentation

bool lowrappers::ServerThread::addListener ( const char *  path,
const char *  typespec,
Listener listener 
)

Adds a Listener to this server thread.

(Note that there is a functor class GenericServerThreadListener so any object's method that matches the signature of ServerThread::Listener::callback can be passed.)

Parameters
pathThe OSC path to register the method to. If NULL is passed the method will match all paths.
typespecThe typespec the method accepts. Incoming messages with similar typespecs (e.g. ones with numerical types in the same position) will be coerced to the typespec given here.
listenerThe Listener whose callback() method will be called if a matching message is received.
Returns
true, if the method Listener was added successfully, false otherwise.
bool lowrappers::ServerThread::addMethod ( const char *  path,
const char *  typespec,
lo_method_handler  h,
void *  user_data 
)

Adds a lo_method_handler to this server thread.

See the Liblo documentation for details about lo_method_handlers. For an object-oriented alternative, see addListener.

Parameters
pathThe OSC path to register the method to. If NULL is passed the method will match all paths.
typespecThe typespec the method accepts. Incoming messages with similar typespecs (e.g. ones with numerical types in the same position) will be coerced to the typespec given here.
hThe lo_method_handler callback function that will be called if a matching message is received.
user_dataA value that will be passed to the callback function, h, when its invoked matching from this method.
Returns
true, if the method handler was added successfully, false otherwise.
void lowrappers::ServerThread::delMethod ( const char *  path,
const char *  typespec 
)

Delete a method from this server thread.

This may aso be used to delete Listener callback methods.

Parameters
pathThe OSC path of the method to delete.
typespecThe typespec the method accepts.
bool lowrappers::ServerThread::isValid ( ) const

Checks if initialization was successfull.

Returns
true, if this is a valid ServerThread.
int lowrappers::ServerThread::port ( ) const

The port number that the server thread has bound to.

Returns
The port number that the server thread has bound to.
std::string lowrappers::ServerThread::url ( ) const

An URL describing the address of the server thread.

Returns
An URL describing the address of the server thread.

Friends And Related Function Documentation

friend class Address
friend

Address is friend class so it can access the internal lo_server for sending messages from its port.