OSVR-Core
LocateServer.h
Go to the documentation of this file.
1 
11 // Copyright 2016 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_LocateServer_h_GUID_7D10F12E_2A83_48BB_7581_ED7A7F5188AC
26 #define INCLUDED_LocateServer_h_GUID_7D10F12E_2A83_48BB_7581_ED7A7F5188AC
27 
28 
29 // Internal Includes
31 #include <osvr/Util/PlatformConfig.h>
32 
33 // Library/third-party includes
34 // - none
35 
36 // Standard includes
37 #include <string>
38 
39 namespace osvr {
40  namespace client {
41 
43  inline boost::optional<std::string> getServerBinaryDirectoryPath() {
44  auto server = osvr::util::getEnvironmentVariable("OSVR_SERVER_ROOT");
45  if (!server || server->empty()) {
46  return server;
47  }
48  const char lastChar = server->back();
49  if (lastChar == '/' || lastChar == '\\') {
50  server->pop_back();
51  }
52  return server;
53  }
54 
56  inline boost::optional<std::string> getServerBinaryPath() {
57  const auto binPath = getServerBinaryDirectoryPath();
58  if (binPath) {
59 #if defined(OSVR_WINDOWS)
60  static const std::string pathExtension = ".exe";
61  static const std::string pathSep = "\\";
62 #else
63  static const std::string pathExtension = "";
64  static const std::string pathSep = "/";
65 #endif
66  return *binPath + pathSep + "osvr_server" + pathExtension;
67  }
68  return boost::none;
69  }
70 
72  inline boost::optional<std::string> getServerLauncherBinaryPath() {
73  return getServerBinaryPath();
74  }
75  }
76 }
77 
78 #endif // INCLUDED_LocateServer_h_GUID_7D10F12E_2A83_48BB_7581_ED7A7F5188AC
79 
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
boost::optional< std::string > getServerBinaryPath()
INTERNAL ONLY - get the path to the server executable, if available.
Definition: LocateServer.h:56
boost::optional< std::string > getServerBinaryDirectoryPath()
INTERNAL ONLY - get the current server directory, if available.
Definition: LocateServer.h:43
boost::optional< std::string > getServerLauncherBinaryPath()
INTERNAL ONLY - get the path to the server launcher executable, if available.
Definition: LocateServer.h:72
OSVR_UTIL_EXPORT boost::optional< std::string > getEnvironmentVariable(std::string const &var)
Gets an environment variable&#39;s value.
Definition: GetEnvironmentVariable.cpp:52