25 #ifndef INCLUDED_ServerImpl_h_GUID_BA15589C_D1AD_4BBE_4F93_8AC87043A982 
   26 #define INCLUDED_ServerImpl_h_GUID_BA15589C_D1AD_4BBE_4F93_8AC87043A982 
   45 #include <boost/noncopyable.hpp> 
   46 #include <boost/optional.hpp> 
   47 #include <boost/thread.hpp> 
   49 #include <json/value.h> 
   50 #include <util/RunLoopManagerBoost.h> 
   51 #include <vrpn_Connection.h> 
   64                    boost::optional<std::string> 
const &host,
 
   65                    boost::optional<int> 
const &port);
 
   88         void loadPlugin(std::string 
const &pluginName);
 
  103         bool addRoute(std::string 
const &routingDirective);
 
  106         bool addAlias(std::string 
const &path, std::string 
const &source,
 
  107                       common::AliasPriority priority);
 
  111                         common::AliasPriority priority);
 
  115                                std::string 
const &deviceName,
 
  116                                std::string 
const &server,
 
  117                                std::string 
const &descriptor);
 
  120         bool addString(std::string 
const &path, std::string 
const &value);
 
  125         int getSleepTime() 
const;
 
  130                                std::string 
const &driver,
 
  131                                std::string 
const ¶ms);
 
  146         template <
typename Callable> 
void m_callControlled(Callable f);
 
  149         template <
typename Callable> 
void m_callControlled(Callable f) 
const;
 
  153         void m_orderedDestruction();
 
  156         void m_queueTreeSend();
 
  162         static int VRPN_CALLBACK m_handleUpdatedRoute(
void *userdata,
 
  163                                                       vrpn_HANDLERPARAM p);
 
  167         bool m_addRoute(std::string 
const &routingDirective);
 
  171         bool m_addAlias(std::string 
const &path, std::string 
const &source,
 
  172                         common::AliasPriority priority);
 
  176         bool m_addAliases(Json::Value 
const &aliases,
 
  177                           common::AliasPriority priority);
 
  180         void m_handleDeviceDescriptors();
 
  186         bool m_inServerThread() 
const;
 
  189         static int VRPN_CALLBACK m_exitIdle(
void *userdata, vrpn_HANDLERPARAM);
 
  191         static int VRPN_CALLBACK m_enterIdle(
void *userdata, vrpn_HANDLERPARAM);
 
  197         shared_ptr<pluginhost::RegistrationContext> m_ctx;
 
  200         std::vector<MainloopMethod> m_mainloopMethods;
 
  203         common::BaseDevicePtr m_systemDevice;
 
  213         bool m_triggeredDetect = 
false;
 
  220         mutable boost::mutex m_mainThreadMutex;
 
  224         mutable boost::mutex m_runControl;
 
  227         boost::thread m_thread;
 
  228         ::util::RunLoopManagerBoost m_run;
 
  229         bool m_running = 
false;
 
  230         bool m_everStarted = 
false;
 
  235         mutable boost::thread::id m_mainThreadId;
 
  245         static const int IDLE_SLEEP_TIME = 1000;
 
  249         int m_currentSleepTime = IDLE_SLEEP_TIME;
 
  258         util::log::LoggerPtr m_log;
 
  261         unique_ptr<common::LowLatency> m_lowLatency;
 
  269             : m_id(
id), m_origID(
id) {
 
  270             m_id = boost::this_thread::get_id();
 
  275         boost::thread::id &m_id;
 
  276         boost::thread::id m_origID;
 
  279     inline bool ServerImpl::m_inServerThread()
 const {
 
  280         boost::unique_lock<boost::mutex> lock(m_runControl);
 
  281         return !m_running || (boost::this_thread::get_id() == m_mainThreadId);
 
  284     template <
typename Callable>
 
  285     inline void ServerImpl::m_callControlled(Callable f) {
 
  286         boost::unique_lock<boost::mutex> lock(m_runControl);
 
  287         if (m_running && boost::this_thread::get_id() != m_thread.get_id()) {
 
  288             boost::unique_lock<boost::mutex> innerLock(m_mainThreadMutex);
 
  289             TemporaryThreadIDChanger changer(m_mainThreadId);
 
  296     template <
typename Callable>
 
  297     inline void ServerImpl::m_callControlled(Callable f)
 const {
 
  298         boost::unique_lock<boost::mutex> lock(m_runControl);
 
  299         if (m_running && boost::this_thread::get_id() != m_thread.get_id()) {
 
  300             boost::unique_lock<boost::mutex> innerLock(m_mainThreadMutex);
 
  301             TemporaryThreadIDChanger changer(m_mainThreadId);
 
  311 #endif // INCLUDED_ServerImpl_h_GUID_BA15589C_D1AD_4BBE_4F93_8AC87043A982 
Header forward declaring MessageType and specifying a smart pointer. 
Class to temporarily (in RAII style) change a thread ID variable to the current thread, then back again when we leave scope. 
void stop()
Signal the server to stop, and block until it does so. 
A tree representation, with path/url syntax, of the known OSVR system. 
bool addString(std::string const &path, std::string const &value)
Add a string entry to the tree. 
Header for an RAII object defining platform-specific actions to take to enter/exit a "low-latency" sy...
void setSleepTime(int microseconds)
Sets the amount of time (in microseconds) that the server loop will sleep each loop when a client is ...
void registerMainloopMethod(MainloopMethod f)
Register a method to run during every time through the main loop. 
bool addAlias(std::string const &path, std::string const &source, common::AliasPriority priority)
Add an alias entry to the tree. 
std::function< void()> MainloopMethod
A function that can be registered by the server app to run in each mainloop iteration. 
void update()
The method to just do the update stuff, not in a thread. 
shared_ptr< Connection > ConnectionPtr
How one must hold a Connection. 
Header to bring unique_ptr into the osvr namespace. 
BaseDevice component, for the VRPN built-in common messages. 
Header for basic internal log reference. To actually log to the produced loggers, include 
Header to bring shared_ptr into the osvr namespace. 
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. 
void loadAutoPlugins()
Load all auto-loadable plugins. 
Header declaring osvr::server::Server. 
void instantiateDriver(std::string const &plugin, std::string const &driver, std::string const ¶ms)
Instantiate the named driver with parameters. 
ServerImpl(connection::ConnectionPtr const &conn, boost::optional< std::string > const &host, boost::optional< int > const &port)
Constructor. 
Private implementation class for Server. 
void signalStop()
Signal the server to stop (if it is running) but return immediately. 
void startAndAwaitShutdown()
Launch a thread running the server, and block until the server shuts down. 
BaseDevice component, to be used only with the "OSVR" special device. 
~ServerImpl()
Destructor (stops the thread first) 
bool addAliases(Json::Value const &aliases, common::AliasPriority priority)
Add alias entries to the tree from JSON. 
bool addRoute(std::string const &routingDirective)
Register a JSON string as a routing directive. 
void awaitShutdown()
Block until the server shuts down. 
A class that lightly wraps a bool, in order to provide easier maintenance of a "dirty" flag...
void setHardwareDetectOnConnection()
Adds the behavior that hardware detection should take place on client connection. ...
Header forward-declaring RegistrationContext. 
Header forward-declaring Connection and specifying the smart pointer to hold a Connection in...
void triggerHardwareDetect()
Run all hardware detect callbacks. 
void start()
Launch a thread running the server. 
void loadPlugin(std::string const &pluginName)
Load named plugin.