Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Unified Diff: chromeos/process.h

Issue 6509006: libchromeos: add process control library, syslog logging capability, and run unit tests (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/common.git@master
Patch Set: sync Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698