OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ServerAutoStartC.cpp
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 // Internal Includes
27 #include <osvr/Util/ProcessUtils.h>
31 #if defined(OSVR_ANDROID)
34 #endif
35 
36 // Library/third-party includes
37 // - none
38 
39 // Standard includes
40 #include <string>
41 #include <vector>
42 
43 // @todo use a thread-safe lazy-initialized singleton pattern
44 #if defined(OSVR_ANDROID)
45 static osvr::server::ServerPtr gServer;
46 #endif
47 
49 {
50  // @todo start the server.
51 #if defined(OSVR_ANDROID)
52  if(!gServer) {
53  OSVR_DEV_VERBOSE("Creating android auto-start server. Looking at config file paths:");
54  std::vector<std::string> configPaths = osvr::server::getDefaultConfigFilePaths();
55  for(size_t i = 0; i < configPaths.size(); i++) {
56  OSVR_DEV_VERBOSE(configPaths[i]);
57  }
58 
60  OSVR_DEV_VERBOSE("Android-auto-start server created. Starting server thread...");
61 
62  gServer->start();
63  OSVR_DEV_VERBOSE("Android server thread started...");
64  }
65 #else
66  auto server = osvr::client::getServerBinaryDirectoryPath();
67  if (server) {
68  OSVR_DEV_VERBOSE("Attempting to auto-start OSVR server from path " << *server);
69  auto exePath = osvr::client::getServerLauncherBinaryPath();
70  if (!exePath) {
71  OSVR_DEV_VERBOSE("No server launcher binary available.");
72  return;
73  }
74 
75  if (osvrStartProcess(exePath->c_str(), server->c_str()) == OSVR_RETURN_FAILURE) {
76  OSVR_DEV_VERBOSE("Could not auto-start server process.");
77  return;
78  }
79  } else {
80  OSVR_DEV_VERBOSE("The current server location is currently unknown. Assuming server is already running.");
81  }
82 #endif
83  return;
84 }
85 
87 {
88 #if defined(OSVR_ANDROID)
89  if(gServer) {
90  gServer->stop();
91  gServer = nullptr;
92  }
93 #else
94  // no-op. Leave the server running.
95 #endif
96  return;
97 }
Internal API to locate the current OSVR Server on the file system.
OSVR_ReturnCode osvrStartProcess(const char *executablePath, const char *workingDirectory)
INTERNAL ONLY - start a process in a platform agnostic way.
Definition: ProcessUtils.h:48
#define OSVR_RETURN_FAILURE
The "failure" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:47
void osvrClientAttemptServerAutoStart()
Ensures the OSVR server process/thread is running. Call once per process. The server may or may not a...
Platform agnostic process utilities.
Auto-configured header.
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.
Definition: ServerPtr.h:39
void osvrClientReleaseAutoStartedServer()
Ensures any OSVR server-related resources in the client are released. Call once per process...
API to attempt OSVR server auto-start.
OSVR_SERVER_EXPORT std::vector< std::string > getDefaultConfigFilePaths()
this returns a vector of default server configuration file paths.