AGX Dynamics  2.37.3.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  \return True if process is still running
51  */
52  bool startProcess(const agx::StringVector& commandVector, const agx::String& workingDir);
53 
58  int waitUntilExit();
59 
64  int closeAndWaitForExit();
65 
67  void killProcess();
68 
70  bool isRunning() const;
71 
72  ExternalProcess(const ExternalProcess&) = delete;
73  protected:
74  virtual ~ExternalProcess();
75 
76  bool startProcess(const agx::String& command, const agx::String& workingDir);
77 
78  private:
79  const agx::String m_processTag;
80  std::unique_ptr<detail::Process> m_externalProcess;
81  std::thread m_processThread;
82  std::atomic_bool m_processIsRunning;
83  int m_exitStatus;
84  };
85 }
86 
87 #endif
Cross-platform utility class for wrapping and launching external processes.
#define AGXOSG_EXPORT
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Base class providing referencing counted objects.
Definition: Referenced.h:119
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.