OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Server.cpp
Go to the documentation of this file.
1 
11 // Copyright 2014 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 // Internal Includes
26 #include <osvr/Server/Server.h>
28 #include <osvr/Util/PortFlags.h>
29 #include "ServerImpl.h"
30 
31 // Library/third-party includes
32 // - none
33 
34 // Standard includes
35 // - none
36 
37 namespace osvr {
38 namespace server {
39 
42  connection::Connection::createLocalConnection());
43  ServerPtr ret(std::make_shared<Server>(conn, boost::none, boost::none,
44  private_constructor{}));
45 
46  return ret;
47  }
48 
50  ServerPtr ret(std::make_shared<Server>(conn, boost::none, boost::none,
51  private_constructor{}));
52 
53  return ret;
54  }
55 
57  boost::optional<std::string> const &host,
58  boost::optional<int> const &port) {
59  ServerPtr ret(
60  std::make_shared<Server>(conn, host, port, private_constructor{}));
61  return ret;
62  }
63 
64  ServerPtr
66  ServerPtr ret(std::make_shared<Server>(
67  conn, boost::optional<std::string>{},
69  private_constructor{}));
70  return ret;
71  }
72 
73  void Server::update() { m_impl->update(); }
74 
75  void Server::start() { m_impl->start(); }
76 
77  void Server::awaitShutdown() { m_impl->awaitShutdown(); }
78 
79  void Server::startAndAwaitShutdown() { m_impl->startAndAwaitShutdown(); }
80 
81  void Server::stop() { m_impl->stop(); }
82 
83  void Server::signalStop() { m_impl->signalStop(); }
84 
85  void Server::loadPlugin(std::string const &plugin) {
86  m_impl->loadPlugin(plugin);
87  }
88 
89  void Server::loadAutoPlugins() { m_impl->loadAutoPlugins(); }
90 
92  m_impl->setHardwareDetectOnConnection();
93  }
94 
95  void Server::instantiateDriver(std::string const &plugin,
96  std::string const &driver,
97  std::string const &params) {
98  m_impl->instantiateDriver(plugin, driver, params);
99  }
100 
101  void Server::triggerHardwareDetect() { m_impl->triggerHardwareDetect(); }
102 
104  m_impl->registerMainloopMethod(f);
105  }
106 
107  bool Server::addRoute(std::string const &routingDirective) {
108  return m_impl->addRoute(routingDirective);
109  }
110 
111  bool Server::addAlias(std::string const &path, std::string const &source,
112  common::AliasPriority priority) {
113  return m_impl->addAlias(path, source, priority);
114  }
115 
116  bool Server::addString(std::string const &path, std::string const &value) {
117  return m_impl->addString(path, value);
118  }
119 
120  bool Server::addAliases(Json::Value const &aliases,
121  common::AliasPriority priority) {
122  return m_impl->addAliases(aliases, priority);
123  }
124 
125  void Server::addExternalDevice(std::string const &path,
126  std::string const &deviceName,
127  std::string const &server,
128  std::string const &descriptor) {
129  m_impl->addExternalDevice(path, deviceName, server, descriptor);
130  }
131 
132  void Server::setSleepTime(int microseconds) {
133  m_impl->setSleepTime(microseconds);
134  }
135 #if 0
136  int Server::getSleepTime() const { return m_impl->getSleepTime(); }
137 #endif
138 
140  boost::optional<std::string> const &host,
141  boost::optional<int> const &port,
142  private_constructor const &)
143  : m_impl(new ServerImpl(conn, host, port)) {}
144 
146 
147 } // namespace server
148 } // namespace osvr
Header.
OSVR_SERVER_EXPORT void startAndAwaitShutdown()
Launch a thread running the server, and block until the server shuts down.
Definition: Server.cpp:79
Header defining some special values that may be passed to some functions that request a port number t...
OSVR_SERVER_EXPORT bool addAliases(Json::Value const &aliases, common::AliasPriority priority=common::ALIASPRIORITY_MANUAL)
Add alias entries to the tree from JSON.
Definition: Server.cpp:120
OSVR_SERVER_EXPORT void start()
Launch a thread running the server.
Definition: Server.cpp:75
OSVR_SERVER_EXPORT void triggerHardwareDetect()
Run all hardware detect callbacks.
Definition: Server.cpp:101
OSVR_SERVER_EXPORT bool addString(std::string const &path, std::string const &value)
Add a string entry to the tree.
Definition: Server.cpp:116
std::function< void()> MainloopMethod
A function that can be registered by the server app to run in each mainloop iteration.
Definition: Server.h:52
shared_ptr< Connection > ConnectionPtr
How one must hold a Connection.
Definition: ConnectionPtr.h:40
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.
Definition: Server.cpp:125
OSVR_SERVER_EXPORT void loadPlugin(std::string const &plugin)
Load plugin by name.
Definition: Server.cpp:85
OSVR_SERVER_EXPORT void registerMainloopMethod(MainloopMethod f)
Register a method to run during every time through the main loop.
Definition: Server.cpp:103
OSVR_SERVER_EXPORT void stop()
Signal the server to stop (if it is running), and block until it does so.
Definition: Server.cpp:81
OSVR_SERVER_EXPORT ~Server()
Destructor - stops the loop and blocks until it's done.
Definition: Server.cpp:145
OSVR_SERVER_EXPORT void setHardwareDetectOnConnection()
Adds the behavior that hardware detection should take place on client connection. ...
Definition: Server.cpp:91
OSVR_SERVER_EXPORT void awaitShutdown()
Block until the server shuts down.
Definition: Server.cpp:77
OSVR_SERVER_EXPORT bool addRoute(std::string const &routingDirective)
Register a JSON string as a routing directive.
Definition: Server.cpp:107
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.
Definition: Server.cpp:111
Header declaring osvr::server::Server.
static OSVR_SERVER_EXPORT ServerPtr create(connection::ConnectionPtr const &conn)
Create a server object with a provided connection.
Definition: Server.cpp:49
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 t...
Definition: Server.cpp:65
Private implementation class for Server.
Definition: ServerImpl.h:60
Header.
Server(connection::ConnectionPtr const &conn, boost::optional< std::string > const &host, boost::optional< int > const &port, private_constructor const &)
Private server constructor.
Definition: Server.cpp:139
shared_ptr< Server > ServerPtr
How one should hold a Server.
Definition: ServerPtr.h:39
OSVR_SERVER_EXPORT void signalStop()
Signal the server to stop (if it is running) but return immediately.
Definition: Server.cpp:83
OSVR_SERVER_EXPORT void loadAutoPlugins()
Load all auto-loadable plugins.
Definition: Server.cpp:89
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 ser...
Definition: Server.cpp:73
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 ...
Definition: Server.cpp:132
static OSVR_SERVER_EXPORT ServerPtr createLocal()
Create a server object with a local-only (but still IP-based) connection.
Definition: Server.cpp:40
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.
Definition: Server.cpp:95