OSVR-Core
Classes | Public Member Functions | Static Public Member Functions | List of all members
osvr::server::Server Class Reference

Class handling a run-loop with a registration context and connection. More...

#include <Server.h>

Inheritance diagram for osvr::server::Server:

Public Member Functions

 Server (connection::ConnectionPtr const &conn, boost::optional< std::string > const &host, boost::optional< int > const &port, private_constructor const &)
 Private server constructor. More...
 
OSVR_SERVER_EXPORT ~Server ()
 Destructor - stops the loop and blocks until it's done.
 
OSVR_SERVER_EXPORT void update ()
 If you aren't using a separate thread for the server, this method will run a single update of the server. More...
 
OSVR_SERVER_EXPORT void start ()
 Launch a thread running the server. More...
 
OSVR_SERVER_EXPORT void startAndAwaitShutdown ()
 Launch a thread running the server, and block until the server shuts down. More...
 
OSVR_SERVER_EXPORT void awaitShutdown ()
 Block until the server shuts down. More...
 
OSVR_SERVER_EXPORT void stop ()
 Signal the server to stop (if it is running), and block until it does so. More...
 
OSVR_SERVER_EXPORT void signalStop ()
 Signal the server to stop (if it is running) but return immediately. More...
 
OSVR_SERVER_EXPORT void loadPlugin (std::string const &plugin)
 Load plugin by name. More...
 
OSVR_SERVER_EXPORT void loadAutoPlugins ()
 Load all auto-loadable plugins.
 
OSVR_SERVER_EXPORT void setHardwareDetectOnConnection ()
 Adds the behavior that hardware detection should take place on client connection. More...
 
OSVR_SERVER_EXPORT void instantiateDriver (std::string const &plugin, std::string const &driver, std::string const &params=std::string())
 Instantiate the named driver with parameters. More...
 
OSVR_SERVER_EXPORT void triggerHardwareDetect ()
 Run all hardware detect callbacks. More...
 
OSVR_SERVER_EXPORT void registerMainloopMethod (MainloopMethod f)
 Register a method to run during every time through the main loop. More...
 
OSVR_SERVER_EXPORT bool addRoute (std::string const &routingDirective)
 Register a JSON string as a routing directive. More...
 
OSVR_SERVER_EXPORT bool addAlias (std::string const &path, std::string const &source, common::AliasPriority priority=common::ALIASPRIORITY_MANUAL)
 Add an alias entry to the tree. More...
 
OSVR_SERVER_EXPORT bool addString (std::string const &path, std::string const &value)
 Add a string entry to the tree. More...
 
OSVR_SERVER_EXPORT bool addAliases (Json::Value const &aliases, common::AliasPriority priority=common::ALIASPRIORITY_MANUAL)
 Add alias entries to the tree from JSON. More...
 
OSVR_SERVER_EXPORT void addExternalDevice (std::string const &path, std::string const &deviceName, std::string const &server, std::string const &descriptor)
 Add an external device entry manually to the tree. More...
 
OSVR_SERVER_EXPORT void setSleepTime (int microseconds)
 Sets the amount of time (in microseconds) that the server loop will sleep each loop when a client is connected (0 means no sleep) More...
 

Static Public Member Functions

static OSVR_SERVER_EXPORT ServerPtr createLocal ()
 Create a server object with a local-only (but still IP-based) connection. More...
 
static OSVR_SERVER_EXPORT ServerPtr create (connection::ConnectionPtr const &conn)
 Create a server object with a provided connection. More...
 
static OSVR_SERVER_EXPORT ServerPtr create (connection::ConnectionPtr const &conn, boost::optional< std::string > const &host, boost::optional< int > const &port)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Parameters left unspecified/as boost::none will be filled with default values. More...
 
static OSVR_SERVER_EXPORT ServerPtr createNonListening (connection::ConnectionPtr const &conn)
 Create a server object with a provided connection with a provided connection that has been asserted to not listen at all to outside processes. More...
 

Detailed Description

Class handling a run-loop with a registration context and connection.

Constructor & Destructor Documentation

§ Server()

osvr::server::Server::Server ( connection::ConnectionPtr const &  conn,
boost::optional< std::string > const &  host,
boost::optional< int > const &  port,
private_constructor const &   
)

Private server constructor.

The last argument is a dummy argument to enforce use of the factory methods.

Exceptions
std::logic_errorif a null connection is passed.

Member Function Documentation

§ addAlias()

bool osvr::server::Server::addAlias ( std::string const &  path,
std::string const &  source,
common::AliasPriority  priority = common::ALIASPRIORITY_MANUAL 
)

Add an alias entry to the tree.

If the server is running, this will trigger a re-transmission of the path tree to all clients.

Safe to call from any thread, even when server is running.

§ addAliases()

bool osvr::server::Server::addAliases ( Json::Value const &  aliases,
common::AliasPriority  priority = common::ALIASPRIORITY_MANUAL 
)

Add alias entries to the tree from JSON.

If the server is running, this will trigger a re-transmission of the path tree to all clients.

Safe to call from any thread, even when server is running.

§ addExternalDevice()

void osvr::server::Server::addExternalDevice ( std::string const &  path,
std::string const &  deviceName,
std::string const &  server,
std::string const &  descriptor 
)

Add an external device entry manually to the tree.

If the server is running, this will trigger a re-transmission of the path tree to all clients.

Safe to call from any thread, even when server is running.

§ addRoute()

bool osvr::server::Server::addRoute ( std::string const &  routingDirective)

Register a JSON string as a routing directive.

If the server is running, this will trigger a re-transmission of the path tree to all clients.

Returns
true if the route was new, or false if it replaced an existing route for that destination.

Safe to call from any thread, even when server is running.

§ addString()

bool osvr::server::Server::addString ( std::string const &  path,
std::string const &  value 
)

Add a string entry to the tree.

If the server is running, this will trigger a re-transmission of the path tree to all clients.

Safe to call from any thread, even when server is running.

§ awaitShutdown()

void osvr::server::Server::awaitShutdown ( )

Block until the server shuts down.

Do not call from within the server thread itself, of course.

§ create() [1/2]

ServerPtr osvr::server::Server::create ( connection::ConnectionPtr const &  conn)
static

Create a server object with a provided connection.

Parameters
connA non-null connection pointer. Since an osvr::connection::ConnectionPtr is a shared pointer, the server takes shared ownership of the connection passed.
Exceptions
std::logic_errorif a null connection is passed.

§ create() [2/2]

ServerPtr osvr::server::Server::create ( connection::ConnectionPtr const &  conn,
boost::optional< std::string > const &  host,
boost::optional< int > const &  port 
)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Parameters left unspecified/as boost::none will be filled with default values.

§ createLocal()

ServerPtr osvr::server::Server::createLocal ( )
static

Create a server object with a local-only (but still IP-based) connection.

§ createNonListening()

ServerPtr osvr::server::Server::createNonListening ( connection::ConnectionPtr const &  conn)
static

Create a server object with a provided connection with a provided connection that has been asserted to not listen at all to outside processes.

§ instantiateDriver()

void osvr::server::Server::instantiateDriver ( std::string const &  plugin,
std::string const &  driver,
std::string const &  params = std::string() 
)

Instantiate the named driver with parameters.

Parameters
pluginThe name of a plugin.
driverThe name of a driver registered by the plugin for creation in this way.
paramsA string containing parameters. Format is between you and the plugin, but JSON is recommended.

Call only before starting the server or from within server thread.

§ loadPlugin()

void osvr::server::Server::loadPlugin ( std::string const &  plugin)

Load plugin by name.

Safe to call from any thread, even when server is running.

§ registerMainloopMethod()

void osvr::server::Server::registerMainloopMethod ( MainloopMethod  f)

Register a method to run during every time through the main loop.

Safe to call from any thread, even when server is running.

§ setHardwareDetectOnConnection()

void osvr::server::Server::setHardwareDetectOnConnection ( )

Adds the behavior that hardware detection should take place on client connection.

Safe to call from any thread, even when server is running, though it makes the most sense as a startup option.

§ setSleepTime()

void osvr::server::Server::setSleepTime ( int  microseconds)

Sets the amount of time (in microseconds) that the server loop will sleep each loop when a client is connected (0 means no sleep)

Call only before starting the server or from within server thread.

§ signalStop()

void osvr::server::Server::signalStop ( )

Signal the server to stop (if it is running) but return immediately.

Safe to call from any thread.

§ start()

void osvr::server::Server::start ( )

Launch a thread running the server.

Exceptions
std::logic_errorif called after the server has stopped.

§ startAndAwaitShutdown()

void osvr::server::Server::startAndAwaitShutdown ( )

Launch a thread running the server, and block until the server shuts down.

Exceptions
std::logic_errorif called after the server has stopped.

§ stop()

void osvr::server::Server::stop ( )

Signal the server to stop (if it is running), and block until it does so.

Safe to call from any non-server thread, do not call from within the server thread itself, of course.

§ triggerHardwareDetect()

void osvr::server::Server::triggerHardwareDetect ( )

Run all hardware detect callbacks.

Safe to call from any thread, even when server is running.

§ update()

void osvr::server::Server::update ( )

If you aren't using a separate thread for the server, this method will run a single update of the server.


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