Index: chromeos/process.h |
diff --git a/chromeos/process.h b/chromeos/process.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ccb4795018078eb009173d3c4924f582af68905d |
--- /dev/null |
+++ b/chromeos/process.h |
@@ -0,0 +1,68 @@ |
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROMEOS_PROCESS_H_ |
+#define CHROMEOS_PROCESS_H_ |
+ |
+#include <sys/types.h> |
+ |
+#include <string> |
+#include <vector> |
+ |
+#include <base/string_util.h> |
+ |
+// Manages a process. Can create the process, attach to an existing |
+// process by pid or pid file, and kill the process. Upon destruction |
+// any managed process is killed with SIGKILL. Use Release() to |
+// release the process from management. |
+class Process { |
petkov
2011/02/25 19:20:16
You need brief docstrings for the individual metho
kmixter1
2011/02/26 00:54:31
Done.
|
+ public: |
+ Process(); |
+ virtual ~Process(); |
+ |
+ virtual void AddArg(const std::string& arg) = 0; |
+ inline void AddStringValue(const std::string& arg, const std::string& value) { |
+ AddArg(arg); |
+ AddArg(value); |
+ } |
+ inline void AddIntValue(const std::string& arg, int value) { |
+ AddArg(arg); |
+ AddArg(StringPrintf("%d", value)); |
+ } |
+ virtual void SetOutput(const std::string& output_file) = 0; |
+ virtual bool Start() = 0; |
+ virtual int Wait() = 0; |
+ virtual int Run() = 0; |
+ virtual pid_t GetPid() = 0; |
+ virtual bool Kill(int signal, int timeout) = 0; |
+ virtual void Reset(pid_t pid) = 0; |
+ virtual bool ResetPidByFile(const std::string& pid_file) = 0; |
+ virtual pid_t Release() = 0; |
+ |
+ static bool ProcessExists(pid_t pid); |
+}; |
+ |
+class ProcessImpl : public Process { |
+ public: |
+ ProcessImpl(); |
+ virtual ~ProcessImpl(); |
+ |
+ virtual void AddArg(const std::string& arg); |
+ virtual void SetOutput(const std::string& output_file); |
+ virtual bool Start(); |
+ virtual int Wait(); |
+ virtual int Run(); |
+ virtual pid_t GetPid(); |
+ virtual bool Kill(int signal, int timeout); |
+ virtual void Reset(pid_t pid); |
+ virtual bool ResetPidByFile(const std::string& pid_file); |
+ virtual pid_t Release(); |
+ |
+ protected: |
+ std::string output_file_; |
+ pid_t pid_; |
+ std::vector<std::string> arguments_; |
+}; |
+ |
+#endif // CHROMEOS_PROCESS_H |