1 /******************************************************************************
3 * Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
23 #include "base/i2-base.hpp"
24 #include "base/dictionary.hpp"
25 #include <boost/function.hpp>
34 * The result of a Process task.
41 double ExecutionStart;
48 * A process task. Executes an external application and returns the exit
49 * code and console output.
53 class I2_BASE_API Process : public Object
56 DECLARE_PTR_TYPEDEFS(Process);
59 typedef String Arguments;
60 typedef HANDLE ProcessHandle;
61 typedef HANDLE ConsoleHandle;
63 typedef std::vector<String> Arguments;
64 typedef pid_t ProcessHandle;
65 typedef int ConsoleHandle;
68 static const std::deque<Process::Ptr>::size_type MaxTasksPerThread = 512;
70 Process(const Arguments& arguments, const Dictionary::Ptr& extraEnvironment = Dictionary::Ptr());
73 void SetTimeout(double timeout);
74 double GetTimeout(void) const;
76 void Run(const boost::function<void (const ProcessResult&)>& callback = boost::function<void (const ProcessResult&)>());
78 pid_t GetPID(void) const;
80 static Arguments PrepareCommand(const Value& command);
82 static void StaticInitialize(void);
83 static void ThreadInitialize(void);
85 static String PrettyPrintArguments(const Arguments& arguments);
88 Arguments m_Arguments;
89 Dictionary::Ptr m_ExtraEnvironment;
93 ProcessHandle m_Process;
100 OVERLAPPED m_Overlapped;
101 char m_ReadBuffer[1024];
104 std::ostringstream m_OutputStream;
105 boost::function<void (const ProcessResult&)> m_Callback;
106 ProcessResult m_Result;
108 static void IOThreadProc(int tid);
110 int GetTID(void) const;
115 #endif /* PROCESS_H */