35 #include <boost/program_options.hpp>
41 namespace opt = boost::program_options;
44 using ::osvr::util::log::OSVR_SERVER_LOG;
48 auto log = ::osvr::util::log::make_logger(OSVR_SERVER_LOG);
49 log->info() <<
"Received shutdown signal...";
53 int main(
int argc,
char *argv[]) {
54 auto log = ::osvr::util::log::make_logger(OSVR_SERVER_LOG);
56 std::vector<std::string> configPaths;
58 opt::options_description optionsAll(
"All Options");
59 opt::options_description optionsVisible(
"Command Line Options");
60 opt::positional_options_description optionsPositional;
62 optionsPositional.add(
"config", -1);
63 optionsVisible.add_options()
64 (
"config",
"server configuration filename")
65 (
"help",
"display this help message")
66 (
"verbose,v",
"enable verbose logging")
67 (
"debug,d",
"enable debug logging");
68 optionsAll.add(optionsVisible);
70 opt::variables_map values;
72 opt::store(opt::command_line_parser(argc, argv)
74 .positional(optionsPositional)
78 }
catch (opt::invalid_command_line_syntax &e) {
79 log->error() << e.what();
81 }
catch (opt::unknown_option &e) {
82 log->error() << e.what();
86 if (values.count(
"help")) {
87 std::cout << optionsVisible << std::endl;
91 if (values.count(
"debug")) {
92 osvr::util::log::LogRegistry::instance().
setLevel(osvr::util::log::LogLevel::trace);
93 osvr::util::log::LogRegistry::instance().
setConsoleLevel(osvr::util::log::LogLevel::trace);
94 log->trace(
"Debug logging enabled.");
95 }
else if (values.count(
"verbose")) {
96 osvr::util::log::LogRegistry::instance().
setLevel(osvr::util::log::LogLevel::debug);
97 osvr::util::log::LogRegistry::instance().
setConsoleLevel(osvr::util::log::LogLevel::debug);
98 log->debug(
"Verbose logging enabled.");
101 if (values.count(
"config")) {
102 std::string configFileArgument = values[
"config"].as<std::string>();
103 log->info() <<
"Using config file " << configFileArgument <<
" from command line argument.";
104 configPaths = { configFileArgument };
106 log->info() <<
"Using default config file - pass a filename on the command "
107 "line to use a different one.";
114 if (!values.count(
"config")) {
115 log->info() <<
"Could not find a valid config file in the default search paths. Using default config object.";
116 server = osvr::server::configureServerFromString(
"{ }");
123 log->error() <<
"Unknown error while creating server.";
127 log->info() <<
"Registering shutdown handler...";
128 osvr::server::registerShutdownHandler<&handleShutdown>();
130 log->info() <<
"Starting server mainloop: OSVR Server is ready to go!";
131 server->startAndAwaitShutdown();
133 log->info() <<
"OSVR Server exited.";
void handleShutdown()
Shutdown handler function - forcing the server pointer to be global.
Header to register a handler for cross-platform shutdown/terminate signals. WARNING: includes windows...
void setConsoleLevel(LogLevel severity)
Sets the minimum level of messages to be logged to the console.
Regstry to maintain instantiated loggers and global settings.
Platform specific search paths for osvr server config files.
OSVR_SERVER_EXPORT ServerPtr configureServerFromFirstFileInList(std::vector< std::string > const &configNames)
This iterates over a vector that contains a list of potential config files, and uses the first workin...
shared_ptr< Server > ServerPtr
How one should hold a Server.
Header to include for OSVR-internal usage of the logging mechanism: provides the needed definition of...
void setLevel(LogLevel severity)
Sets the minimum level of messages to be logged on all registered loggers.
OSVR_SERVER_EXPORT std::vector< std::string > getDefaultConfigFilePaths()
this returns a vector of default server configuration file paths.