OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROMEOS_PROCESS_H_ | |
6 #define CHROMEOS_PROCESS_H_ | |
7 | |
8 #include <sys/types.h> | |
9 | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include <base/string_util.h> | |
14 | |
15 // Manages a process. Can create the process, attach to an existing | |
16 // process by pid or pid file, and kill the process. Upon destruction | |
17 // any managed process is killed with SIGKILL. Use Release() to | |
18 // release the process from management. | |
19 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.
| |
20 public: | |
21 Process(); | |
22 virtual ~Process(); | |
23 | |
24 virtual void AddArg(const std::string& arg) = 0; | |
25 inline void AddStringValue(const std::string& arg, const std::string& value) { | |
26 AddArg(arg); | |
27 AddArg(value); | |
28 } | |
29 inline void AddIntValue(const std::string& arg, int value) { | |
30 AddArg(arg); | |
31 AddArg(StringPrintf("%d", value)); | |
32 } | |
33 virtual void SetOutput(const std::string& output_file) = 0; | |
34 virtual bool Start() = 0; | |
35 virtual int Wait() = 0; | |
36 virtual int Run() = 0; | |
37 virtual pid_t GetPid() = 0; | |
38 virtual bool Kill(int signal, int timeout) = 0; | |
39 virtual void Reset(pid_t pid) = 0; | |
40 virtual bool ResetPidByFile(const std::string& pid_file) = 0; | |
41 virtual pid_t Release() = 0; | |
42 | |
43 static bool ProcessExists(pid_t pid); | |
44 }; | |
45 | |
46 class ProcessImpl : public Process { | |
47 public: | |
48 ProcessImpl(); | |
49 virtual ~ProcessImpl(); | |
50 | |
51 virtual void AddArg(const std::string& arg); | |
52 virtual void SetOutput(const std::string& output_file); | |
53 virtual bool Start(); | |
54 virtual int Wait(); | |
55 virtual int Run(); | |
56 virtual pid_t GetPid(); | |
57 virtual bool Kill(int signal, int timeout); | |
58 virtual void Reset(pid_t pid); | |
59 virtual bool ResetPidByFile(const std::string& pid_file); | |
60 virtual pid_t Release(); | |
61 | |
62 protected: | |
63 std::string output_file_; | |
64 pid_t pid_; | |
65 std::vector<std::string> arguments_; | |
66 }; | |
67 | |
68 #endif // CHROMEOS_PROCESS_H | |
OLD | NEW |