|
| 1 | +/** @file |
| 2 | + @brief Platform agnostic process utilities. |
| 3 | +
|
| 4 | + @date 2016 |
| 5 | +
|
| 6 | + @author |
| 7 | + Sensics, Inc. |
| 8 | + <http://sensics.com/osvr> |
| 9 | +*/ |
| 10 | + |
| 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_ProcessUtils_h_GUID_6C3F7688_AF0D_4094_D629_AF8DBFDF2044 |
| 26 | +#define INCLUDED_ProcessUtils_h_GUID_6C3F7688_AF0D_4094_D629_AF8DBFDF2044 |
| 27 | + |
| 28 | + |
| 29 | +// Internal Includes |
| 30 | +#include <osvr/Util/APIBaseC.h> |
| 31 | +#include <osvr/Util/ReturnCodesC.h> |
| 32 | +#include <osvr/Util/PlatformConfig.h> |
| 33 | +#include <osvr/Util/Verbosity.h> |
| 34 | + |
| 35 | +// Library/third-party includes |
| 36 | +#if !defined(OSVR_ANDROID) |
| 37 | +#if defined(OSVR_WINDOWS) |
| 38 | +#include <windows.h> |
| 39 | +#else |
| 40 | +#include <unistd.h> |
| 41 | +#endif |
| 42 | +#endif |
| 43 | + |
| 44 | +// Standard includes |
| 45 | +// - none |
| 46 | + |
| 47 | +/** @brief INTERNAL ONLY - start a process in a platform agnostic way */ |
| 48 | +OSVR_INLINE OSVR_ReturnCode osvrStartProcess(const char* executablePath, const char* workingDirectory) |
| 49 | +{ |
| 50 | +#if defined(OSVR_ANDROID) |
| 51 | + // @todo: can we just use the *nix implementation for android? |
| 52 | + OSVR_DEV_VERBOSE("osvrStartProces not yet implemented for Android"); |
| 53 | + return OSVR_RETURN_FAILURE; |
| 54 | +#elif defined(OSVR_WINDOWS) |
| 55 | + STARTUPINFO startupInfo = { 0 }; |
| 56 | + PROCESS_INFORMATION processInfo = { 0 }; |
| 57 | + |
| 58 | + startupInfo.dwFlags |= STARTF_USESHOWWINDOW; |
| 59 | + startupInfo.wShowWindow = SW_SHOW; |
| 60 | + if (!CreateProcess(executablePath, nullptr, nullptr, nullptr, FALSE, CREATE_NEW_CONSOLE, nullptr, |
| 61 | + workingDirectory, &startupInfo, &processInfo)) { |
| 62 | + OSVR_DEV_VERBOSE("Could not start process."); |
| 63 | + return OSVR_RETURN_FAILURE; |
| 64 | + } |
| 65 | +#else |
| 66 | + OSVR_DEV_VERBOSE("osvrStartProcess not yet implemented for non-Windows platforms"); |
| 67 | + return OSVR_RETURN_FAILURE; |
| 68 | + // UNTESTED (or even compiled) |
| 69 | + //pid_t pid = fork(); |
| 70 | + //if (pid == -1) { |
| 71 | + // OSVR_DEV_VERBOSE("Could not fork the process."); |
| 72 | + // return OSVR_RETURN_FAILURE; |
| 73 | + //} else if (pid == 0) { |
| 74 | + // // @todo set the current working directory to workingDirectory here |
| 75 | + // execl(executablePath, NULL); |
| 76 | + // OSVR_DEV_VERBOSE("Could not execute the process."); |
| 77 | + // return OSVR_RETURN_FAILURE; |
| 78 | + //} else { |
| 79 | + // // @todo: is this too verbose? |
| 80 | + // //OSVR_DEV_VERBOSE("Started OSVR server process successfully."); |
| 81 | + // return OSVR_RETURN_SUCCESS; |
| 82 | + //} |
| 83 | +#endif |
| 84 | + return OSVR_RETURN_SUCCESS; |
| 85 | +} |
| 86 | + |
| 87 | +#endif // INCLUDED_ProcessUtils_h_GUID_6C3F7688_AF0D_4094_D629_AF8DBFDF2044 |
| 88 | + |
0 commit comments