AGX Dynamics  2.35.0.1
ExternalProcess.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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 
59 
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
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGXOSG_EXPORT
Cross-platform utility class for wrapping and launching external processes.
ExternalProcess(const ExternalProcess &)=delete
bool startProcess(const agx::String &command, const agx::String &workingDir)
int closeAndWaitForExit()
Will try to close the external process and wait for it's exit.
bool startProcess(const agx::StringVector &commandVector, const agx::String &workingDir)
ExternalProcess(const agx::String &processTag="")
Default constructor.
void killProcess()
Will kill the external process by forcing a close.
bool isRunning() const
Return true if the process is still running. False it not.
int waitUntilExit()
Will wait until the external process has exited.
Base class providing referencing counted objects.
Definition: Referenced.h:114
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.