OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
osvr::server::Server Class Reference

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

#include <osvr/Server/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.
 
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.
 
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)
 
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.
 

Detailed Description

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

Definition at line 67 of file Server.h.

Constructor & Destructor Documentation

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.

Definition at line 139 of file Server.cpp.

Member Function Documentation

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.

Definition at line 49 of file Server.cpp.

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.

Definition at line 56 of file Server.cpp.

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

Launch a thread running the server.

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

Definition at line 75 of file Server.cpp.

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.

Definition at line 79 of file Server.cpp.

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

Block until the server shuts down.

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

Definition at line 77 of file Server.cpp.

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.

Definition at line 81 of file Server.cpp.

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

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

Safe to call from any thread.

Definition at line 83 of file Server.cpp.

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

Load plugin by name.

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

Definition at line 85 of file Server.cpp.

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.

Definition at line 91 of file Server.cpp.

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.

Definition at line 95 of file Server.cpp.

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

Run all hardware detect callbacks.

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

Definition at line 101 of file Server.cpp.

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.

Definition at line 103 of file Server.cpp.

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.

Definition at line 107 of file Server.cpp.

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.

Definition at line 111 of file Server.cpp.

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.

Definition at line 116 of file Server.cpp.

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.

Definition at line 120 of file Server.cpp.

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.

Definition at line 125 of file Server.cpp.

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.

Definition at line 132 of file Server.cpp.


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