OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
BasicServer.cpp
Go to the documentation of this file.
1 
12 // Copyright 2014 Sensics, Inc.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "License");
15 // you may not use this file except in compliance with the License.
16 // You may obtain a copy of the License at
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 // See the License for the specific language governing permissions and
24 // limitations under the License.
25 
26 // Internal Includes
27 #include <osvr/Server/Server.h>
29 
30 // Library/third-party includes
31 // - none
32 
33 // Standard includes
34 #include <iostream>
35 #include <exception>
36 
37 using std::cout;
38 using std::cerr;
39 using std::endl;
40 
41 static osvr::server::ServerPtr server;
42 
45  cout << "Received shutdown signal..." << endl;
46  server->signalStop();
47 }
48 
49 int main(int argc, char *argv[]) {
50  if (argc < 2) {
51  cerr << "Must supply at least one plugin name to load." << endl;
52  return 1;
53  }
54  cout << "Creating server..." << endl;
55 
57 
58  cout << "Registering shutdown handler..." << endl;
59  osvr::server::registerShutdownHandler<&handleShutdown>();
60 
61  cout << "Loading plugins..." << endl;
62  for (int i = 1; i < argc; ++i) {
63  try {
64  cout << "Loading plugin '" << argv[i] << "'..." << endl;
65  server->loadPlugin(argv[i]);
66  cout << "Plugin '" << argv[i] << "' loaded!\n" << endl;
67  } catch (std::exception &e) {
68  std::cerr << "Caught exception tring to load " << argv[i] << ": "
69  << e.what() << std::endl;
70  return 1;
71  }
72  }
73 
74  cout << "Triggering a hardware detection..." << endl;
75  server->triggerHardwareDetect();
76 
77  cout << "Starting server mainloop..." << endl;
78  server->startAndAwaitShutdown();
79 
80  cout << "Server mainloop exited." << endl;
81 
82  return 0;
83 }
Header to register a handler for cross-platform shutdown/terminate signals. WARNING: includes windows...
void handleShutdown()
Shutdown handler function - forcing the server pointer to be global.
Definition: BasicServer.cpp:44
Header declaring osvr::server::Server.
shared_ptr< Server > ServerPtr
How one should hold a Server.
Definition: ServerPtr.h:39
static OSVR_SERVER_EXPORT ServerPtr createLocal()
Create a server object with a local-only (but still IP-based) connection.
Definition: Server.cpp:40