PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcommon/llprocesslauncher.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 90 lines | 38 code | 16 blank | 36 comment | 0 complexity | 9f61ecc170b1551b63d83d74b4b7e65c MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llprocesslauncher.h
  3. * @brief Utility class for launching, terminating, and tracking the state of processes.
  4. *
  5. * $LicenseInfo:firstyear=2008&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLPROCESSLAUNCHER_H
  27. #define LL_LLPROCESSLAUNCHER_H
  28. #if LL_WINDOWS
  29. #include <windows.h>
  30. #endif
  31. /*
  32. LLProcessLauncher handles launching external processes with specified command line arguments.
  33. It also keeps track of whether the process is still running, and can kill it if required.
  34. */
  35. class LL_COMMON_API LLProcessLauncher
  36. {
  37. LOG_CLASS(LLProcessLauncher);
  38. public:
  39. LLProcessLauncher();
  40. virtual ~LLProcessLauncher();
  41. void setExecutable(const std::string &executable);
  42. void setWorkingDirectory(const std::string &dir);
  43. const std::string& getExecutable() const;
  44. void clearArguments();
  45. void addArgument(const std::string &arg);
  46. void addArgument(const char *arg);
  47. int launch(void);
  48. bool isRunning(void);
  49. // Attempt to kill the process -- returns true if the process is no longer running when it returns.
  50. // Note that even if this returns false, the process may exit some time after it's called.
  51. bool kill(void);
  52. // Use this if you want the external process to continue execution after the LLProcessLauncher instance controlling it is deleted.
  53. // Normally, the destructor will attempt to kill the process and wait for termination.
  54. // This should only be used if the viewer is about to exit -- otherwise, the child process will become a zombie after it exits.
  55. void orphan(void);
  56. // This needs to be called periodically on Mac/Linux to clean up zombie processes.
  57. static void reap(void);
  58. // Accessors for platform-specific process ID
  59. #if LL_WINDOWS
  60. HANDLE getProcessHandle() { return mProcessHandle; };
  61. #else
  62. pid_t getProcessID() { return mProcessID; };
  63. #endif
  64. private:
  65. std::string mExecutable;
  66. std::string mWorkingDir;
  67. std::vector<std::string> mLaunchArguments;
  68. #if LL_WINDOWS
  69. HANDLE mProcessHandle;
  70. #else
  71. pid_t mProcessID;
  72. #endif
  73. };
  74. #endif // LL_LLPROCESSLAUNCHER_H