From dc3706e8609b714f94db6450bfc63023175f4f63 Mon Sep 17 00:00:00 2001 From: David Ryskalczyk Date: Thu, 29 Oct 2015 22:53:43 -0400 Subject: [PATCH 1/8] First attempts --- apps/osvr_server.cpp | 10 +++--- inc/osvr/Server/ConfigureServerFromFile.h | 38 +++++++++++++++++++++-- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/apps/osvr_server.cpp b/apps/osvr_server.cpp index 3c6b9222b..b025fd45a 100644 --- a/apps/osvr_server.cpp +++ b/apps/osvr_server.cpp @@ -34,6 +34,7 @@ #include #include #include +#include using osvr::server::detail::out; using osvr::server::detail::err; @@ -48,15 +49,16 @@ void handleShutdown() { } int main(int argc, char *argv[]) { - std::string configName(osvr::server::getDefaultConfigFilename()); + std::vector configNames; if (argc > 1) { - configName = argv[1]; + configNames = {std::string(argv[1])}; } else { - out << "Using default config file - pass a filename on the command " + out << "Using default config files - pass a filename on the command " "line to use a different one." << endl; + configNames = osvr::server::getDefaultConfigFilenames(); } - server = osvr::server::configureServerFromFile(configName); + server = osvr::server::configureServerFromFirstFileInList(configNames); if (!server) { return -1; } diff --git a/inc/osvr/Server/ConfigureServerFromFile.h b/inc/osvr/Server/ConfigureServerFromFile.h index 2b52e2124..f9f74d45c 100644 --- a/inc/osvr/Server/ConfigureServerFromFile.h +++ b/inc/osvr/Server/ConfigureServerFromFile.h @@ -36,6 +36,7 @@ #include #include #include +#include namespace osvr { namespace server { @@ -57,13 +58,26 @@ namespace server { static detail::StreamPrefixer err("[OSVR Server] ", std::cerr); } // namespace detail - inline const char *getDefaultConfigFilename() { - return "osvr_server_config.json"; + inline std::vector getDefaultConfigFilenames() { + std::vector names; + names.push_back("HOME/.osvr/osvr_server_config.json"); + names.push_back("PREFIX/etc/osvr_server_config.json"); +#ifdef WINDOWS + names.push_back("osvr_server_config.json"); +#elif MAC + names.push_back("HOME/Library/Application Support/OSVR/osvr_server_config.json"); +#endif + for (auto i = names.begin(); i != names.end(); i++) { + std::cout << *i << std::endl; + } + + return names; } /// @brief This is the basic common code of a server app's setup, ripped out /// of the main server app to make alternate server-acting apps simpler to /// develop. + inline ServerPtr configureServerFromFile(std::string const &configName) { using detail::out; using detail::err; @@ -169,6 +183,26 @@ namespace server { return ret; } + + inline ServerPtr configureServerFromFirstFileInList(std::vector const &configNames) { + using detail::out; + using detail::err; + using std::endl; + for(const auto name: configNames) { + std::ifstream config(name); + if(config.good()) { + out << "Using config file '" << name << "'" << endl; + return configureServerFromFile(name); + } + } + err << "Could not open config file!" << endl; + err << "Attempted the following files:" << endl; + for (auto i = configNames.begin(); i != configNames.end(); i++) { + std::cout << *i << std::endl; + } + return nullptr; + } + } // namespace server } // namespace osvr From 15a7b8c4b62d49f33be6199d17728db6c5d98cfb Mon Sep 17 00:00:00 2001 From: David Ryskalczyk Date: Sat, 7 Nov 2015 14:06:04 -0500 Subject: [PATCH 2/8] Search predefined paths for config file, and automatically load an empty config if one is not found --- apps/osvr_server.cpp | 13 +- inc/osvr/Server/ConfigureServerFromFile.h | 149 +--------------- src/osvr/Server/CMakeLists.txt | 3 + src/osvr/Server/ConfigFilePaths.h.cmake_in | 55 ++++++ src/osvr/Server/ConfigureServerFromFile.cpp | 178 ++++++++++++++++++++ 5 files changed, 254 insertions(+), 144 deletions(-) create mode 100644 src/osvr/Server/ConfigFilePaths.h.cmake_in create mode 100644 src/osvr/Server/ConfigureServerFromFile.cpp diff --git a/apps/osvr_server.cpp b/apps/osvr_server.cpp index b025fd45a..12d848a68 100644 --- a/apps/osvr_server.cpp +++ b/apps/osvr_server.cpp @@ -26,6 +26,7 @@ // Internal Includes #include #include +#include // Library/third-party includes // - none @@ -49,16 +50,20 @@ void handleShutdown() { } int main(int argc, char *argv[]) { - std::vector configNames; + std::vector configPaths; if (argc > 1) { - configNames = {std::string(argv[1])}; + configPaths = {std::string(argv[1])}; } else { out << "Using default config files - pass a filename on the command " "line to use a different one." << endl; - configNames = osvr::server::getDefaultConfigFilenames(); + configPaths = osvr::server::getDefaultConfigFilePaths(); } - server = osvr::server::configureServerFromFirstFileInList(configNames); + server = osvr::server::configureServerFromFirstFileInList(configPaths); + if (!server) { + out << "Using default config data." << endl; + server = osvr::server::configureServerFromFile(""); + } if (!server) { return -1; } diff --git a/inc/osvr/Server/ConfigureServerFromFile.h b/inc/osvr/Server/ConfigureServerFromFile.h index f9f74d45c..f1d59a6f5 100644 --- a/inc/osvr/Server/ConfigureServerFromFile.h +++ b/inc/osvr/Server/ConfigureServerFromFile.h @@ -58,150 +58,19 @@ namespace server { static detail::StreamPrefixer err("[OSVR Server] ", std::cerr); } // namespace detail - inline std::vector getDefaultConfigFilenames() { - std::vector names; - names.push_back("HOME/.osvr/osvr_server_config.json"); - names.push_back("PREFIX/etc/osvr_server_config.json"); -#ifdef WINDOWS - names.push_back("osvr_server_config.json"); -#elif MAC - names.push_back("HOME/Library/Application Support/OSVR/osvr_server_config.json"); -#endif - for (auto i = names.begin(); i != names.end(); i++) { - std::cout << *i << std::endl; - } + /// @brief this returns a vector of default server configuration file paths. + std::vector getDefaultConfigFilePaths(); - return names; - } - - /// @brief This is the basic common code of a server app's setup, ripped out + /// @brief This uses a file name to attempt to configure the server with that config file. + /// Pass an empty string to use the default config. + /// This is the basic common code of a server app's setup, ripped out /// of the main server app to make alternate server-acting apps simpler to /// develop. + ServerPtr configureServerFromFile(std::string const &configName); - inline ServerPtr configureServerFromFile(std::string const &configName) { - using detail::out; - using detail::err; - using std::endl; - ServerPtr ret; - out << "Using config file '" << configName << "'" << endl; - std::ifstream config(configName); - if (!config.good()) { - err << "\n" - << "Could not open config file!" << endl; - err << "Searched in the current directory; file may be " - "misspelled, missing, or in a different directory." << endl; - return nullptr; - } - - osvr::server::ConfigureServer srvConfig; - out << "Constructing server as configured..." << endl; - try { - srvConfig.loadConfig(config); - ret = srvConfig.constructServer(); - } catch (std::exception &e) { - err << "Caught exception constructing server from JSON config " - "file: " << e.what() << endl; - return nullptr; - } - - { - out << "Loading auto-loadable plugins..." << endl; - srvConfig.loadAutoPlugins(); - } - - { - out << "Loading plugins..." << endl; - srvConfig.loadPlugins(); - if (!srvConfig.getSuccessfulPlugins().empty()) { - out << "Successful plugins:" << endl; - for (auto const &plugin : srvConfig.getSuccessfulPlugins()) { - out << " - " << plugin << endl; - } - out << "\n"; - } - if (!srvConfig.getFailedPlugins().empty()) { - out << "Failed plugins:" << endl; - for (auto const &pluginError : srvConfig.getFailedPlugins()) { - out << " - " << pluginError.first << "\t" - << pluginError.second << endl; - } - out << "\n"; - } - - out << "\n"; - } - - { - out << "Instantiating configured drivers..." << endl; - bool success = srvConfig.instantiateDrivers(); - if (!srvConfig.getSuccessfulInstantiations().empty()) { - out << "Successes:" << endl; - for (auto const &driver : - srvConfig.getSuccessfulInstantiations()) { - out << " - " << driver << endl; - } - out << "\n"; - } - if (!srvConfig.getFailedInstantiations().empty()) { - out << "Errors:" << endl; - for (auto const &error : srvConfig.getFailedInstantiations()) { - out << " - " << error.first << "\t" << error.second << endl; - } - out << "\n"; - } - out << "\n"; - } - - if (srvConfig.processExternalDevices()) { - out << "External devices found and parsed from config file." - << endl; - } - - if (srvConfig.processRoutes()) { - out << "Routes found and parsed from config file." << endl; - } - - if (srvConfig.processAliases()) { - out << "Aliases found and parsed from config file." << endl; - } - - if (srvConfig.processDisplay()) { - out << "Display descriptor found and parsed from config file" - << endl; - } else { - out << "No valid 'display' object found in config file - server " - "may use the OSVR HDK as a default." << endl; - } - - if (srvConfig.processRenderManagerParameters()) { - out << "RenderManager config found and parsed from the config file" - << endl; - } - - out << "Triggering a hardware detection..." << endl; - ret->triggerHardwareDetect(); - - return ret; - } - - inline ServerPtr configureServerFromFirstFileInList(std::vector const &configNames) { - using detail::out; - using detail::err; - using std::endl; - for(const auto name: configNames) { - std::ifstream config(name); - if(config.good()) { - out << "Using config file '" << name << "'" << endl; - return configureServerFromFile(name); - } - } - err << "Could not open config file!" << endl; - err << "Attempted the following files:" << endl; - for (auto i = configNames.begin(); i != configNames.end(); i++) { - std::cout << *i << std::endl; - } - return nullptr; - } + /// @brief This iterates over a vector that contains a list of potential + /// config files, and uses the first working one to create the server instance. + ServerPtr configureServerFromFirstFileInList(std::vector const &configNames); } // namespace server } // namespace osvr diff --git a/src/osvr/Server/CMakeLists.txt b/src/osvr/Server/CMakeLists.txt index bfb4b97b7..4fde89a88 100644 --- a/src/osvr/Server/CMakeLists.txt +++ b/src/osvr/Server/CMakeLists.txt @@ -11,6 +11,7 @@ set(API set(SOURCE ConfigureServer.cpp + ConfigureServerFromFile.cpp JSONResolvePossibleRef.h JSONResolvePossibleRef.cpp Server.cpp @@ -18,6 +19,8 @@ set(SOURCE ServerImpl.h "${CMAKE_CURRENT_BINARY_DIR}/display_json.h") +configure_file(ConfigFilePaths.h.cmake_in "${CMAKE_CURRENT_BINARY_DIR}/ConfigFilePaths.h") + # Fallback display descriptor set(DISPLAY_JSON ../../../apps/displays/OSVR_HDK_1_1.json) osvr_convert_json(display_json ${DISPLAY_JSON} "${CMAKE_CURRENT_BINARY_DIR}/display_json.h") diff --git a/src/osvr/Server/ConfigFilePaths.h.cmake_in b/src/osvr/Server/ConfigFilePaths.h.cmake_in new file mode 100644 index 000000000..3fd7ee603 --- /dev/null +++ b/src/osvr/Server/ConfigFilePaths.h.cmake_in @@ -0,0 +1,55 @@ +/** @file + @brief Auto-generated configuration header - do not edit! + + @date 2015 + + @author + Sensics, Inc. + +*/ + +// Copyright 2015 Sensics, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef INCLUDED_ConfigFilePaths_h_GUID_241E9C9C_0E0E_46B0_9DED_8F8059306192 +#define INCLUDED_ConfigFilePaths_h_GUID_241E9C9C_0E0E_46B0_9DED_8F8059306192 + +#include +namespace osvr { + namespace server { + + std::vector getDefaultConfigFilePaths() { + +#ifdef OSVR_WINDOWS + std::string appdata = std::getenv("APPDATA"); +#else + std::string home = std::getenv("HOME"); +#endif + + std::vector names; + names.push_back(home + "/.osvr/osvr_server_config.json"); + names.push_back("@CMAKE_INSTALL_FULL_SYSCONFDIR@/osvr_server_config.json"); + +#if defined(OSVR_WINDOWS) + names.push_back(appdata + "\\OSVR\\osvr_server_config.json"); + names.push_back("osvr_server_config.json"); +#elif defined(OSVR_MACOSX) + names.push_back(home + "/Library/Application Support/OSVR/osvr_server_config.json"); +#endif + + return names; + } + } +} +#endif // INCLUDED_ConfigFilePaths_h_GUID_241E9C9C_0E0E_46B0_9DED_8F8059306192 diff --git a/src/osvr/Server/ConfigureServerFromFile.cpp b/src/osvr/Server/ConfigureServerFromFile.cpp new file mode 100644 index 000000000..eb352387d --- /dev/null +++ b/src/osvr/Server/ConfigureServerFromFile.cpp @@ -0,0 +1,178 @@ +/** @file + @brief Header + + @date 2014 + + @author + Sensics, Inc. + +*/ + +// Copyright 2014 Sensics, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Internal Includes +#include +#include +#include +#include +#include + +// Library/third-party includes +// - none + +// Standard includes +#include +#include +#include +#include + +namespace osvr { +namespace server { + + + ServerPtr configureServerFromFile(std::string const &configName) { + using detail::out; + using detail::err; + using std::endl; + ServerPtr ret; + osvr::server::ConfigureServer srvConfig; + + if(!configName.empty()) { + out << "Using config file '" << configName << "'" << endl; + std::ifstream config(configName); + if (!config.good()) { + err << "\n" + << "Could not open config file!" << endl; + err << "Searched in the current directory; file may be " + "misspelled, missing, or in a different directory." << endl; + return nullptr; + } + try { + srvConfig.loadConfig(config); + } catch (std::exception &e) { + err << "Caught exception attempting to parse server JSON config file: " << e.what() << endl; + return nullptr; + } + } else { + srvConfig.loadConfig("{}"); + } + try { + ret = srvConfig.constructServer(); + } catch (std::exception &e) { + err << "Caught exception constructing server from JSON config " + "file: " << e.what() << endl; + return nullptr; + } + + { + out << "Loading auto-loadable plugins..." << endl; + srvConfig.loadAutoPlugins(); + } + + { + out << "Loading plugins..." << endl; + srvConfig.loadPlugins(); + if (!srvConfig.getSuccessfulPlugins().empty()) { + out << "Successful plugins:" << endl; + for (auto const &plugin : srvConfig.getSuccessfulPlugins()) { + out << " - " << plugin << endl; + } + out << "\n"; + } + if (!srvConfig.getFailedPlugins().empty()) { + out << "Failed plugins:" << endl; + for (auto const &pluginError : srvConfig.getFailedPlugins()) { + out << " - " << pluginError.first << "\t" + << pluginError.second << endl; + } + out << "\n"; + } + + out << "\n"; + } + + { + out << "Instantiating configured drivers..." << endl; + bool success = srvConfig.instantiateDrivers(); + if (!srvConfig.getSuccessfulInstantiations().empty()) { + out << "Successes:" << endl; + for (auto const &driver : + srvConfig.getSuccessfulInstantiations()) { + out << " - " << driver << endl; + } + out << "\n"; + } + if (!srvConfig.getFailedInstantiations().empty()) { + out << "Errors:" << endl; + for (auto const &error : srvConfig.getFailedInstantiations()) { + out << " - " << error.first << "\t" << error.second << endl; + } + out << "\n"; + } + out << "\n"; + } + + if (srvConfig.processExternalDevices()) { + out << "External devices found and parsed from config file." + << endl; + } + + if (srvConfig.processRoutes()) { + out << "Routes found and parsed from config file." << endl; + } + + if (srvConfig.processAliases()) { + out << "Aliases found and parsed from config file." << endl; + } + + if (srvConfig.processDisplay()) { + out << "Display descriptor found and parsed from config file" + << endl; + } else { + out << "No valid 'display' object found in config file - server " + "may use the OSVR HDK as a default." << endl; + } + + if (srvConfig.processRenderManagerParameters()) { + out << "RenderManager config found and parsed from the config file" + << endl; + } + + out << "Triggering a hardware detection..." << endl; + ret->triggerHardwareDetect(); + + return ret; + } + + ServerPtr configureServerFromFirstFileInList(std::vector const &configNames) { + using detail::out; + using detail::err; + using std::endl; + for(const auto name: configNames) { + std::ifstream config(name); + if(config.good()) { + return configureServerFromFile(name); + } + } + err << "Could not open config file!" << endl; + err << "Attempted the following files:" << endl; + for (auto i = configNames.begin(); i != configNames.end(); i++) { + std::cout << *i << std::endl; + } + return nullptr; + } + +} // namespace server +} // namespace osvr From ac1720a84d737cad173a8108b0d2f2583ce89727 Mon Sep 17 00:00:00 2001 From: David Ryskalczyk Date: Sat, 7 Nov 2015 15:55:28 -0500 Subject: [PATCH 3/8] Clean up formatting --- apps/osvr_server.cpp | 3 ++- inc/osvr/Server/ConfigureServerFromFile.h | 9 +++++--- src/osvr/Server/ConfigFilePaths.h.cmake_in | 10 +++++---- src/osvr/Server/ConfigureServerFromFile.cpp | 23 +++++++++++++-------- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/apps/osvr_server.cpp b/apps/osvr_server.cpp index 12d848a68..2d6a8a1e5 100644 --- a/apps/osvr_server.cpp +++ b/apps/osvr_server.cpp @@ -55,7 +55,8 @@ int main(int argc, char *argv[]) { configPaths = {std::string(argv[1])}; } else { out << "Using default config files - pass a filename on the command " - "line to use a different one." << endl; + "line to use a different one." + << endl; configPaths = osvr::server::getDefaultConfigFilePaths(); } diff --git a/inc/osvr/Server/ConfigureServerFromFile.h b/inc/osvr/Server/ConfigureServerFromFile.h index f1d59a6f5..28d0a718a 100644 --- a/inc/osvr/Server/ConfigureServerFromFile.h +++ b/inc/osvr/Server/ConfigureServerFromFile.h @@ -61,7 +61,8 @@ namespace server { /// @brief this returns a vector of default server configuration file paths. std::vector getDefaultConfigFilePaths(); - /// @brief This uses a file name to attempt to configure the server with that config file. + /// @brief This uses a file name to attempt to configure the server with + /// that config file. /// Pass an empty string to use the default config. /// This is the basic common code of a server app's setup, ripped out /// of the main server app to make alternate server-acting apps simpler to @@ -69,8 +70,10 @@ namespace server { ServerPtr configureServerFromFile(std::string const &configName); /// @brief This iterates over a vector that contains a list of potential - /// config files, and uses the first working one to create the server instance. - ServerPtr configureServerFromFirstFileInList(std::vector const &configNames); + /// config files, and uses the first working one to create the server + /// instance. + ServerPtr configureServerFromFirstFileInList( + std::vector const &configNames); } // namespace server } // namespace osvr diff --git a/src/osvr/Server/ConfigFilePaths.h.cmake_in b/src/osvr/Server/ConfigFilePaths.h.cmake_in index 3fd7ee603..7fc414483 100644 --- a/src/osvr/Server/ConfigFilePaths.h.cmake_in +++ b/src/osvr/Server/ConfigFilePaths.h.cmake_in @@ -27,7 +27,7 @@ #include namespace osvr { - namespace server { +namespace server { std::vector getDefaultConfigFilePaths() { @@ -39,17 +39,19 @@ namespace osvr { std::vector names; names.push_back(home + "/.osvr/osvr_server_config.json"); - names.push_back("@CMAKE_INSTALL_FULL_SYSCONFDIR@/osvr_server_config.json"); + names.push_back( + "@CMAKE_INSTALL_FULL_SYSCONFDIR@/osvr_server_config.json"); #if defined(OSVR_WINDOWS) names.push_back(appdata + "\\OSVR\\osvr_server_config.json"); names.push_back("osvr_server_config.json"); #elif defined(OSVR_MACOSX) - names.push_back(home + "/Library/Application Support/OSVR/osvr_server_config.json"); + names.push_back( + home + "/Library/Application Support/OSVR/osvr_server_config.json"); #endif return names; } - } +} } #endif // INCLUDED_ConfigFilePaths_h_GUID_241E9C9C_0E0E_46B0_9DED_8F8059306192 diff --git a/src/osvr/Server/ConfigureServerFromFile.cpp b/src/osvr/Server/ConfigureServerFromFile.cpp index eb352387d..f142e0342 100644 --- a/src/osvr/Server/ConfigureServerFromFile.cpp +++ b/src/osvr/Server/ConfigureServerFromFile.cpp @@ -41,7 +41,6 @@ namespace osvr { namespace server { - ServerPtr configureServerFromFile(std::string const &configName) { using detail::out; using detail::err; @@ -49,20 +48,23 @@ namespace server { ServerPtr ret; osvr::server::ConfigureServer srvConfig; - if(!configName.empty()) { + if (!configName.empty()) { out << "Using config file '" << configName << "'" << endl; std::ifstream config(configName); if (!config.good()) { err << "\n" << "Could not open config file!" << endl; err << "Searched in the current directory; file may be " - "misspelled, missing, or in a different directory." << endl; + "misspelled, missing, or in a different directory." + << endl; return nullptr; } try { srvConfig.loadConfig(config); } catch (std::exception &e) { - err << "Caught exception attempting to parse server JSON config file: " << e.what() << endl; + err << "Caught exception attempting to parse server JSON " + "config file: " + << e.what() << endl; return nullptr; } } else { @@ -72,7 +74,8 @@ namespace server { ret = srvConfig.constructServer(); } catch (std::exception &e) { err << "Caught exception constructing server from JSON config " - "file: " << e.what() << endl; + "file: " + << e.what() << endl; return nullptr; } @@ -142,7 +145,8 @@ namespace server { << endl; } else { out << "No valid 'display' object found in config file - server " - "may use the OSVR HDK as a default." << endl; + "may use the OSVR HDK as a default." + << endl; } if (srvConfig.processRenderManagerParameters()) { @@ -156,13 +160,14 @@ namespace server { return ret; } - ServerPtr configureServerFromFirstFileInList(std::vector const &configNames) { + ServerPtr configureServerFromFirstFileInList( + std::vector const &configNames) { using detail::out; using detail::err; using std::endl; - for(const auto name: configNames) { + for (const auto name : configNames) { std::ifstream config(name); - if(config.good()) { + if (config.good()) { return configureServerFromFile(name); } } From b5d020bf46506ca47de2c40d57cd9097f92ffe7c Mon Sep 17 00:00:00 2001 From: JeroMiya Date: Thu, 13 Apr 2017 17:48:24 -0400 Subject: [PATCH 4/8] Updated comment for accuracy. --- src/osvr/Server/ConfigFilePaths.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/osvr/Server/ConfigFilePaths.cpp b/src/osvr/Server/ConfigFilePaths.cpp index 6cf9840e8..d219984dd 100644 --- a/src/osvr/Server/ConfigFilePaths.cpp +++ b/src/osvr/Server/ConfigFilePaths.cpp @@ -21,13 +21,7 @@ namespace osvr { std::string configSubpath = "config"; #if defined(OSVR_LINUX) - // There's currently no great location for storing log files in the - // XDG system. (See the STATE proposal by Debian - // .) - // So for now, we'll store our log files in the $XDG_CACHE_HOME - // directory. - // - // $XDG_CACHE_HOME defines the base directory relative to which user + // $XDG_CONFIG_HOME defines the base directory relative to which user // specific non-essential data files should be stored. If // $XDG_CACHE_HOME is either not set or empty, a default equal to // $HOME/.cache should be used. From 7e0e545763a289549e9d51ba64a8617d3f1599ea Mon Sep 17 00:00:00 2001 From: JeroMiya Date: Mon, 17 Apr 2017 10:49:52 -0400 Subject: [PATCH 5/8] Fixes for PR review. --- apps/osvr_server.cpp | 5 ++--- inc/osvr/Server/ConfigFilePaths.h | 1 + inc/osvr/Server/ConfigureServerFromFile.h | 4 +--- src/osvr/Server/ConfigFilePaths.cpp | 4 ++-- src/osvr/Server/ConfigureServerFromFile.cpp | 12 +++--------- 5 files changed, 9 insertions(+), 17 deletions(-) diff --git a/apps/osvr_server.cpp b/apps/osvr_server.cpp index 2c4aa3a20..79cd71d8e 100644 --- a/apps/osvr_server.cpp +++ b/apps/osvr_server.cpp @@ -83,7 +83,7 @@ int main(int argc, char *argv[]) { } if (values.count("help")) { - std::cout << optionsVisible << std::endl; + log->info() << optionsVisible << std::endl; return 0; } @@ -111,10 +111,9 @@ int main(int argc, char *argv[]) { if (!server) { // only attempt to load the empty config if no arguments are passed. if (!values.count("config")) { - log->info() << "Could not find config file. Using default config object."; + log->info() << "Could not find a valid config file. Using default config object."; server = osvr::server::configureServerFromString("{ }"); } else { - log->error() << "Could not find specified config file."; return -1; } } diff --git a/inc/osvr/Server/ConfigFilePaths.h b/inc/osvr/Server/ConfigFilePaths.h index ca907b238..dc187a9a6 100644 --- a/inc/osvr/Server/ConfigFilePaths.h +++ b/inc/osvr/Server/ConfigFilePaths.h @@ -33,6 +33,7 @@ // Standard includes #include +#include namespace osvr { namespace server { diff --git a/inc/osvr/Server/ConfigureServerFromFile.h b/inc/osvr/Server/ConfigureServerFromFile.h index 63f483cc0..b4cbdc653 100644 --- a/inc/osvr/Server/ConfigureServerFromFile.h +++ b/inc/osvr/Server/ConfigureServerFromFile.h @@ -35,10 +35,8 @@ // - none // Standard includes -#include -#include -#include #include +#include namespace osvr { namespace server { diff --git a/src/osvr/Server/ConfigFilePaths.cpp b/src/osvr/Server/ConfigFilePaths.cpp index d219984dd..50cb459a9 100644 --- a/src/osvr/Server/ConfigFilePaths.cpp +++ b/src/osvr/Server/ConfigFilePaths.cpp @@ -23,8 +23,8 @@ namespace osvr { #if defined(OSVR_LINUX) // $XDG_CONFIG_HOME defines the base directory relative to which user // specific non-essential data files should be stored. If - // $XDG_CACHE_HOME is either not set or empty, a default equal to - // $HOME/.cache should be used. + // $XDG_CONFIG_HOME is either not set or empty, a default equal to + // $HOME/.config should be used. auto xdg_cache_dir = getEnvironmentVariable("XDG_CONFIG_HOME"); if (xdg_cache_dir) { configDir = *xdg_cache_dir; diff --git a/src/osvr/Server/ConfigureServerFromFile.cpp b/src/osvr/Server/ConfigureServerFromFile.cpp index cb4a3426b..a5d40c872 100644 --- a/src/osvr/Server/ConfigureServerFromFile.cpp +++ b/src/osvr/Server/ConfigureServerFromFile.cpp @@ -144,12 +144,10 @@ namespace server { ::osvr::util::log::make_logger(::osvr::util::log::OSVR_SERVER_LOG); ServerPtr ret; - log->info() << "Using config file '" << configName << "'."; + log->info() << "Attempting to load config file '" << configName << "'."; std::ifstream config(configName); if (!config.good()) { - log->error() << "Could not open config file!"; - log->error() << "Searched in the current directory; file may be " - "misspelled, missing, or in a different directory."; + log->error() << "Config file '" << configName << "' not found"; return nullptr; } @@ -169,11 +167,7 @@ namespace server { return configureServerFromFile(name); } } - log->error() << "Could not open config file!"; - log->error() << "Attempted the following files:"; - for (auto i = configNames.begin(); i != configNames.end(); i++) { - log->error() << *i; - } + log->error() << "Could not find a valid config file!"; return nullptr; } From 3513aba552edfaa7873c8d3d88ac3157de821c98 Mon Sep 17 00:00:00 2001 From: JeroMiya Date: Tue, 18 Apr 2017 10:12:30 -0400 Subject: [PATCH 6/8] Minor changes per review. --- apps/osvr_server.cpp | 3 ++- inc/osvr/Server/ConfigFilePaths.h | 4 ++-- src/osvr/Server/ConfigFilePaths.cpp | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/apps/osvr_server.cpp b/apps/osvr_server.cpp index 79cd71d8e..52d6116ae 100644 --- a/apps/osvr_server.cpp +++ b/apps/osvr_server.cpp @@ -36,6 +36,7 @@ // Standard includes #include +#include namespace opt = boost::program_options; @@ -83,7 +84,7 @@ int main(int argc, char *argv[]) { } if (values.count("help")) { - log->info() << optionsVisible << std::endl; + std::cout << optionsVisible << std::endl; return 0; } diff --git a/inc/osvr/Server/ConfigFilePaths.h b/inc/osvr/Server/ConfigFilePaths.h index dc187a9a6..c9e8e65e6 100644 --- a/inc/osvr/Server/ConfigFilePaths.h +++ b/inc/osvr/Server/ConfigFilePaths.h @@ -1,7 +1,7 @@ /** @file - @brief Auto-generated configuration header - do not edit! + @brief Platform specific search paths for osvr server config files. - @date 2015 + @date 2017 @author Sensics, Inc. diff --git a/src/osvr/Server/ConfigFilePaths.cpp b/src/osvr/Server/ConfigFilePaths.cpp index 50cb459a9..bf29dea95 100644 --- a/src/osvr/Server/ConfigFilePaths.cpp +++ b/src/osvr/Server/ConfigFilePaths.cpp @@ -1,3 +1,28 @@ +/** @file +@brief Platform dependent search paths for osvr server config files. + +@date 2017 + +@author +Sensics, Inc. + + +*/ + +// Copyright 2014 Sensics, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + // Internal Includes #include #include From 4ccd1b46f313310bdbe024c688314e84d6651f21 Mon Sep 17 00:00:00 2001 From: JeroMiya Date: Tue, 18 Apr 2017 15:51:55 -0400 Subject: [PATCH 7/8] Formatting, output message adjustment, and updated date in headers. --- apps/osvr_server.cpp | 4 ++-- inc/osvr/Server/ConfigFilePaths.h | 2 +- src/osvr/Server/ConfigFilePaths.cpp | 13 ++++++------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/apps/osvr_server.cpp b/apps/osvr_server.cpp index 52d6116ae..55e18997a 100644 --- a/apps/osvr_server.cpp +++ b/apps/osvr_server.cpp @@ -109,10 +109,10 @@ int main(int argc, char *argv[]) { } server = osvr::server::configureServerFromFirstFileInList(configPaths); - if (!server) { + if (!server) { // only attempt to load the empty config if no arguments are passed. if (!values.count("config")) { - log->info() << "Could not find a valid config file. Using default config object."; + log->info() << "Could not find a valid config file in the default search paths. Using default config object."; server = osvr::server::configureServerFromString("{ }"); } else { return -1; diff --git a/inc/osvr/Server/ConfigFilePaths.h b/inc/osvr/Server/ConfigFilePaths.h index c9e8e65e6..d0280f5a1 100644 --- a/inc/osvr/Server/ConfigFilePaths.h +++ b/inc/osvr/Server/ConfigFilePaths.h @@ -8,7 +8,7 @@ */ -// Copyright 2015 Sensics, Inc. +// Copyright 2017 Sensics, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/osvr/Server/ConfigFilePaths.cpp b/src/osvr/Server/ConfigFilePaths.cpp index bf29dea95..f5d245dd7 100644 --- a/src/osvr/Server/ConfigFilePaths.cpp +++ b/src/osvr/Server/ConfigFilePaths.cpp @@ -1,15 +1,14 @@ /** @file -@brief Platform dependent search paths for osvr server config files. + @brief Platform specific search paths for osvr server config files. -@date 2017 - -@author -Sensics, Inc. - + @date 2017 + @author + Sensics, Inc. + */ -// Copyright 2014 Sensics, Inc. +// Copyright 2017 Sensics, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. From 64961f0adec01656c68e7b8d2636b96660b444b7 Mon Sep 17 00:00:00 2001 From: JeroMiya Date: Mon, 1 May 2017 15:37:45 -0400 Subject: [PATCH 8/8] osvr-server log output text adjustment --- apps/osvr_server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/osvr_server.cpp b/apps/osvr_server.cpp index 55e18997a..f62f0f0fd 100644 --- a/apps/osvr_server.cpp +++ b/apps/osvr_server.cpp @@ -103,7 +103,7 @@ int main(int argc, char *argv[]) { log->info() << "Using config file " << configFileArgument << " from command line argument."; configPaths = { configFileArgument }; } else { - log->info() << "Using default config files - pass a filename on the command " + log->info() << "Using default config file - pass a filename on the command " "line to use a different one."; configPaths = osvr::server::getDefaultConfigFilePaths(); }