-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User directory config files #534
Changes from 4 commits
dc3706e
15a7b8c
ac1720a
afe5262
5848e89
b5d020b
7e0e545
3513aba
4ccd1b4
64961f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** @file | ||
@brief Auto-generated configuration header - do not edit! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This header file isn't auto-generated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated the comment |
||
|
||
@date 2015 | ||
|
||
@author | ||
Sensics, Inc. | ||
<http://sensics.com/osvr> | ||
*/ | ||
|
||
// Copyright 2015 Sensics, Inc. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this 2015 code? |
||
// | ||
// 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 | ||
|
||
// Internal Includes | ||
#include <osvr/Server/Export.h> | ||
|
||
// Library/third-party includes | ||
// - none | ||
|
||
// Standard includes | ||
#include <vector> | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't forget There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
namespace osvr { | ||
namespace server { | ||
|
||
/// @brief this returns a vector of default server configuration file paths. | ||
OSVR_SERVER_EXPORT std::vector<std::string> getDefaultConfigFilePaths(); | ||
} | ||
} | ||
#endif // INCLUDED_ConfigFilePaths_h_GUID_241E9C9C_0E0E_46B0_9DED_8F8059306192 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,118 +38,28 @@ | |
#include <exception> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need |
||
namespace osvr { | ||
namespace server { | ||
|
||
inline const char *getDefaultConfigFilename() { | ||
return "osvr_server_config.json"; | ||
} | ||
|
||
/// @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. | ||
inline ServerPtr configureServerFromFile(std::string const &configName) { | ||
auto log = | ||
::osvr::util::log::make_logger(::osvr::util::log::OSVR_SERVER_LOG); | ||
|
||
ServerPtr ret; | ||
log->info() << "Using 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."; | ||
return nullptr; | ||
} | ||
|
||
osvr::server::ConfigureServer srvConfig; | ||
log->info() << "Constructing server as configured..."; | ||
try { | ||
srvConfig.loadConfig(config); | ||
ret = srvConfig.constructServer(); | ||
} catch (std::exception &e) { | ||
log->error() | ||
<< "Caught exception constructing server from JSON config " | ||
"file: " | ||
<< e.what(); | ||
return nullptr; | ||
} | ||
|
||
{ | ||
log->info() << "Loading auto-loadable plugins..."; | ||
srvConfig.loadAutoPlugins(); | ||
} | ||
|
||
{ | ||
log->info() << "Loading plugins..."; | ||
srvConfig.loadPlugins(); | ||
if (!srvConfig.getSuccessfulPlugins().empty()) { | ||
log->info() << "Successfully loaded the following plugins:"; | ||
for (auto const &plugin : srvConfig.getSuccessfulPlugins()) { | ||
log->info() << " - " << plugin; | ||
} | ||
} | ||
if (!srvConfig.getFailedPlugins().empty()) { | ||
log->warn() << "Failed to load the following plugins:"; | ||
for (auto const &pluginError : srvConfig.getFailedPlugins()) { | ||
log->warn() << " - " << pluginError.first << "\t" | ||
<< pluginError.second; | ||
} | ||
} | ||
} | ||
|
||
{ | ||
log->info() << "Instantiating configured drivers..."; | ||
bool success = srvConfig.instantiateDrivers(); | ||
if (!srvConfig.getSuccessfulInstantiations().empty()) { | ||
log->info() << "Successes:"; | ||
for (auto const &driver : | ||
srvConfig.getSuccessfulInstantiations()) { | ||
log->info() << " - " << driver; | ||
} | ||
} | ||
if (!srvConfig.getFailedInstantiations().empty()) { | ||
log->error() << "Errors:"; | ||
for (auto const &error : srvConfig.getFailedInstantiations()) { | ||
log->error() << " - " << error.first << "\t" | ||
<< error.second; | ||
} | ||
} | ||
} | ||
|
||
if (srvConfig.processExternalDevices()) { | ||
log->info() | ||
<< "External devices found and parsed from config file."; | ||
} | ||
OSVR_SERVER_EXPORT ServerPtr configureServerFromFile(std::string const &configName); | ||
|
||
if (srvConfig.processRoutes()) { | ||
log->info() << "Routes found and parsed from config file."; | ||
} | ||
|
||
if (srvConfig.processAliases()) { | ||
log->info() << "Aliases found and parsed from config file."; | ||
} | ||
|
||
if (srvConfig.processDisplay()) { | ||
log->info() | ||
<< "Display descriptor found and parsed from config file."; | ||
} else { | ||
log->info() | ||
<< "Using OSVR HDK for display configuration. " | ||
"Did not find an alternate valid 'display' object in config " | ||
"file."; | ||
} | ||
|
||
if (srvConfig.processRenderManagerParameters()) { | ||
log->info() << "RenderManager config found and parsed from the " | ||
"config file."; | ||
} | ||
|
||
log->info() << "Triggering automatic hardware detection..."; | ||
ret->triggerHardwareDetect(); | ||
|
||
return ret; | ||
} | ||
/// @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. | ||
OSVR_SERVER_EXPORT ServerPtr configureServerFromFirstFileInList( | ||
std::vector<std::string> const &configNames); | ||
|
||
} // namespace server | ||
} // namespace osvr | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Internal Includes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add standard copyright header. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. date and indentation don't match but... |
||
#include <osvr/Util/PlatformConfig.h> | ||
#include <osvr/Server/ConfigFilePaths.h> | ||
#include <osvr/Server/ConfigureServerFromFile.h> | ||
#include <osvr/Util/GetEnvironmentVariable.h> | ||
|
||
// Library/third-party includes | ||
#include <boost/filesystem.hpp> | ||
|
||
// Standard includes | ||
#include <vector> | ||
|
||
namespace osvr { | ||
namespace server { | ||
|
||
inline std::string getUserConfigDirectory() { | ||
namespace fs = boost::filesystem; | ||
using osvr::util::getEnvironmentVariable; | ||
|
||
fs::path configDir; | ||
std::string configSubpath = "config"; | ||
|
||
#if defined(OSVR_LINUX) | ||
// There's currently no great location for storing log files in the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can delete the first paragraph of the comment and update the second para to reflect There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
// XDG system. (See the STATE proposal by Debian | ||
// <https://wiki.debian.org/XDGBaseDirectorySpecification#Proposal:_STATE_directory>.) | ||
// 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 | ||
// specific non-essential data files should be stored. If | ||
// $XDG_CACHE_HOME is either not set or empty, a default equal to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
// $HOME/.cache should be used. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
auto xdg_cache_dir = getEnvironmentVariable("XDG_CONFIG_HOME"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Linux, if you're searching for an existing configuration file (as opposed to determining where to write a new one), then you will want to check the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to put this as a TODO for now. The function this is in currently only returns one directory, and this change would require it to return multiple directories. |
||
if (xdg_cache_dir) { | ||
configDir = *xdg_cache_dir; | ||
} | ||
else { | ||
auto home_dir = getEnvironmentVariable("HOME"); | ||
configDir = fs::path(*home_dir) / ".config"; | ||
} | ||
configDir /= fs::path("osvr"); | ||
#elif defined(OSVR_MACOSX) | ||
auto home_dir = getEnvironmentVariable("HOME"); | ||
if (home_dir) { | ||
configDir = *home_dir; | ||
} | ||
configDir /= "Library" / fs::path("Application Support") / fs::path("OSVR") / configSubpath; | ||
#elif defined(OSVR_WINDOWS) | ||
/// @todo there's actually a win32 api call to get localappdata | ||
/// that's preferred to the env var. | ||
auto local_app_dir = getEnvironmentVariable("LocalAppData"); | ||
if (local_app_dir) { | ||
configDir = *local_app_dir; | ||
} | ||
else { | ||
configDir = "c:/"; | ||
} | ||
configDir /= fs::path("OSVR") / configSubpath; | ||
#endif | ||
|
||
return configDir.string(); | ||
} | ||
|
||
std::vector<std::string> getDefaultConfigFilePaths() { | ||
namespace fs = boost::filesystem; | ||
std::vector<std::string> names; | ||
std::string configFileName = getDefaultConfigFilename(); | ||
|
||
fs::path userConfigDirectory(getUserConfigDirectory()); | ||
auto userConfig = userConfigDirectory / configFileName; | ||
|
||
names.push_back(userConfig.string()); | ||
names.push_back(configFileName); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are more places worth checking, too. On Linux:
On macOS:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to new issue: #537 |
||
return names; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,23 +47,6 @@ | |
|
||
namespace osvr { | ||
namespace server { | ||
namespace detail { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, wow! This is ancient. I thought we killed it ages ago. |
||
class StreamPrefixer { | ||
public: | ||
StreamPrefixer(const char *prefix, std::ostream &os) | ||
: m_prefix(prefix), m_os(&os) {} | ||
template <typename T> std::ostream &operator<<(T val) { | ||
return (*m_os) << m_prefix << val; | ||
} | ||
|
||
private: | ||
const char *m_prefix; | ||
std::ostream *m_os; | ||
}; | ||
|
||
static detail::StreamPrefixer out("[OSVR Server] ", std::cout); | ||
static detail::StreamPrefixer err("[OSVR Server] ", std::cerr); | ||
} // namespace detail | ||
|
||
inline void | ||
printJsonReferenceResolutionAttempts(ResolveRefResult const &refReturn) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the word "files" here a typo?