OSVR-Core
Server.h
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 #ifndef INCLUDED_Server_h_GUID_453158B3_45B7_478D_FB83_F2F694CA5367
26 #define INCLUDED_Server_h_GUID_453158B3_45B7_478D_FB83_F2F694CA5367
27 
28 // Internal Includes
29 #include <osvr/Server/Export.h>
30 #include <osvr/Server/ServerPtr.h>
33 #include <osvr/Util/UniquePtr.h>
34 
35 // Library/third-party includes
36 #include <boost/noncopyable.hpp>
37 #include <boost/optional.hpp>
38 
39 // Standard includes
40 #include <string>
41 #include <functional>
42 #include <stdexcept>
43 
44 namespace Json {
45 class Value;
46 }
47 
48 namespace osvr {
50 namespace server {
51  // Forward declaration for pimpl idiom.
52  class ServerImpl;
53 
56  typedef std::function<void()> MainloopMethod;
57 
58  struct ServerCreationFailure : std::runtime_error {
60  : std::runtime_error("Could not create server - there is probably "
61  "another instance of the server or a VRPN "
62  "server running already.") {}
63  };
64 
67  class Server : boost::noncopyable {
72  struct private_constructor {};
73 
74  public:
82  boost::optional<std::string> const &host,
83  boost::optional<int> const &port, private_constructor const &);
84 
86  OSVR_SERVER_EXPORT ~Server();
87 
90  OSVR_SERVER_EXPORT static ServerPtr createLocal();
91 
99  OSVR_SERVER_EXPORT static ServerPtr
100  create(connection::ConnectionPtr const &conn);
101 
106  OSVR_SERVER_EXPORT static ServerPtr
107  create(connection::ConnectionPtr const &conn,
108  boost::optional<std::string> const &host,
109  boost::optional<int> const &port);
110 
114  OSVR_SERVER_EXPORT static ServerPtr
115  createNonListening(connection::ConnectionPtr const &conn);
116 
119  OSVR_SERVER_EXPORT void update();
120 
124  OSVR_SERVER_EXPORT void start();
125 
130  OSVR_SERVER_EXPORT void startAndAwaitShutdown();
131 
135  OSVR_SERVER_EXPORT void awaitShutdown();
136 
142  OSVR_SERVER_EXPORT void stop();
143 
148  OSVR_SERVER_EXPORT void signalStop();
149 
153  OSVR_SERVER_EXPORT void loadPlugin(std::string const &plugin);
154 
156  OSVR_SERVER_EXPORT void loadAutoPlugins();
157 
163  OSVR_SERVER_EXPORT void setHardwareDetectOnConnection();
164 
173  OSVR_SERVER_EXPORT void
174  instantiateDriver(std::string const &plugin, std::string const &driver,
175  std::string const &params = std::string());
176 
180  OSVR_SERVER_EXPORT void triggerHardwareDetect();
181 
186  OSVR_SERVER_EXPORT void registerMainloopMethod(MainloopMethod f);
187 
197  OSVR_SERVER_EXPORT bool addRoute(std::string const &routingDirective);
198 
205  OSVR_SERVER_EXPORT bool
206  addAlias(std::string const &path, std::string const &source,
207  common::AliasPriority priority = common::ALIASPRIORITY_MANUAL);
208 
215  OSVR_SERVER_EXPORT bool addString(std::string const &path,
216  std::string const &value);
217 
224  OSVR_SERVER_EXPORT bool addAliases(
225  Json::Value const &aliases,
226  common::AliasPriority priority = common::ALIASPRIORITY_MANUAL);
227 
234  OSVR_SERVER_EXPORT void addExternalDevice(
235  std::string const &path, std::string const &deviceName,
236  std::string const &server, std::string const &descriptor);
237 
243  OSVR_SERVER_EXPORT void setSleepTime(int microseconds);
244 
245 #if 0
246  OSVR_SERVER_EXPORT int getSleepTime() const;
251 #endif
252  private:
253  unique_ptr<ServerImpl> m_impl;
254  };
255 } // namespace server
256 } // namespace osvr
257 
258 #endif // INCLUDED_Server_h_GUID_453158B3_45B7_478D_FB83_F2F694CA5367
Header.
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
std::function< void()> MainloopMethod
A function that can be registered by the server app to run in each mainloop iteration.
Definition: Server.h:52
Class handling a run-loop with a registration context and connection.
Definition: Server.h:67
shared_ptr< Connection > ConnectionPtr
How one must hold a Connection.
Definition: ConnectionPtr.h:40
Header to bring unique_ptr into the osvr namespace.
Private implementation class for Server.
Definition: ServerImpl.h:60
Definition: Server.h:44
bool addAlias(PathNode &node, std::string const &source, AliasPriority priority)
Definition: PathTree.cpp:117
shared_ptr< Server > ServerPtr
How one should hold a Server.
Definition: ServerPtr.h:39
Header forward-declaring the types in PathElementTypes.h and including the PathElement typedef...
Header forward-declaring Connection and specifying the smart pointer to hold a Connection in...