AGX Dynamics  2.38.0.2
ExternalProcess.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXOSG_EXTERNALPROCESS_H
18 #define AGXOSG_EXTERNALPROCESS_H
19 
20 #include <agxOSG/export.h>
21 #include <agx/Referenced.h>
22 #include <thread>
23 #include <memory>
24 #include <atomic>
25 #include <agx/String.h>
26 
28 namespace detail
29 {
30  class Process;
31 }
33 
34 namespace agxOSG
35 {
41  {
42  public:
44  ExternalProcess(const agx::String& processTag = "");
45 
46  /*
47  Launch an external process with a shell command.
48  \param command The shell command to be executed
49  \param workingDir The working directory where the process will be executed
50  \param waitForStartupMs The wait time in ms after the process has started
51  before returning the process status in the function.
52  \return True if process is still running.
53  */
54  bool startProcess(const agx::StringVector& commandVector,
55  const agx::String& workingDir,
56  agx::UInt startupWaitTimeMs=50);
57 
62  int waitUntilExit();
63 
68  int closeAndWaitForExit();
69 
71  void killProcess();
72 
74  bool isRunning() const;
75 
76  ExternalProcess(const ExternalProcess&) = delete;
77  protected:
78  virtual ~ExternalProcess();
79 
80  bool startProcess(const agx::String& command,
81  const agx::String& workingDir,
82  agx::UInt startupWaitTimeMs=50);
83 
84  private:
85  const agx::String m_processTag;
86  std::unique_ptr<detail::Process> m_externalProcess;
87  std::thread m_processThread;
88  std::atomic_bool m_processIsRunning;
89  int m_exitStatus;
90  };
91 }
92 
93 #endif
agx::UInt
uint64_t UInt
Definition: Integer.h:27
Referenced.h
agx::Vector< AgXString< std::string > >
agxOSG
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:119
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
agxOSG::ExternalProcess
Cross-platform utility class for wrapping and launching external processes.
Definition: ExternalProcess.h:40
export.h
String.h
agx::AgXString< std::string >
AGXOSG_EXPORT
#define AGXOSG_EXPORT