1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
6 #include "base/i2-base.hpp"
7 #include "base/dictionary.hpp"
17 * The result of a Process task.
24 double ExecutionStart;
31 * A process task. Executes an external application and returns the exit
32 * code and console output.
36 class Process final : public Object
39 DECLARE_PTR_TYPEDEFS(Process);
42 typedef String Arguments;
43 typedef HANDLE ProcessHandle;
44 typedef HANDLE ConsoleHandle;
46 typedef std::vector<String> Arguments;
47 typedef pid_t ProcessHandle;
48 typedef int ConsoleHandle;
51 static const std::deque<Process::Ptr>::size_type MaxTasksPerThread = 512;
53 Process(Arguments arguments, Dictionary::Ptr extraEnvironment = nullptr);
56 void SetTimeout(double timeout);
57 double GetTimeout() const;
59 void SetAdjustPriority(bool adjust);
60 bool GetAdjustPriority() const;
62 void Run(const std::function<void (const ProcessResult&)>& callback = std::function<void (const ProcessResult&)>());
66 static Arguments PrepareCommand(const Value& command);
68 static void ThreadInitialize();
70 static String PrettyPrintArguments(const Arguments& arguments);
73 static void InitializeSpawnHelper();
77 Arguments m_Arguments;
78 Dictionary::Ptr m_ExtraEnvironment;
81 bool m_AdjustPriority;
83 ProcessHandle m_Process;
90 OVERLAPPED m_Overlapped;
91 char m_ReadBuffer[1024];
94 std::ostringstream m_OutputStream;
95 std::function<void (const ProcessResult&)> m_Callback;
96 ProcessResult m_Result;
98 static void IOThreadProc(int tid);
105 #endif /* PROCESS_H */