xref: /aosp_15_r20/external/libbrillo/brillo/process_information.h (revision 1a96fba65179ea7d3f56207137718607415c5953)
1*1a96fba6SXin Li // Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2*1a96fba6SXin Li // Use of this source code is governed by a BSD-style license that can be
3*1a96fba6SXin Li // found in the LICENSE file.
4*1a96fba6SXin Li 
5*1a96fba6SXin Li #ifndef LIBBRILLO_BRILLO_PROCESS_INFORMATION_H_
6*1a96fba6SXin Li #define LIBBRILLO_BRILLO_PROCESS_INFORMATION_H_
7*1a96fba6SXin Li 
8*1a96fba6SXin Li #include <set>
9*1a96fba6SXin Li #include <string>
10*1a96fba6SXin Li #include <vector>
11*1a96fba6SXin Li 
12*1a96fba6SXin Li #include <brillo/brillo_export.h>
13*1a96fba6SXin Li 
14*1a96fba6SXin Li namespace brillo {
15*1a96fba6SXin Li 
16*1a96fba6SXin Li // Information for a single running process. Stores its command line, set of
17*1a96fba6SXin Li // open files, process id and working directory.
18*1a96fba6SXin Li class BRILLO_EXPORT ProcessInformation {
19*1a96fba6SXin Li  public:
20*1a96fba6SXin Li   ProcessInformation();
21*1a96fba6SXin Li   virtual ~ProcessInformation();
22*1a96fba6SXin Li 
23*1a96fba6SXin Li   std::string GetCommandLine();
24*1a96fba6SXin Li 
25*1a96fba6SXin Li   // Set the command line array.  This method DOES swap out the contents of
26*1a96fba6SXin Li   // |value|.  The caller should expect an empty vector on return.
set_cmd_line(std::vector<std::string> * value)27*1a96fba6SXin Li   void set_cmd_line(std::vector<std::string>* value) {
28*1a96fba6SXin Li     cmd_line_.clear();
29*1a96fba6SXin Li     cmd_line_.swap(*value);
30*1a96fba6SXin Li   }
31*1a96fba6SXin Li 
get_cmd_line()32*1a96fba6SXin Li   const std::vector<std::string>& get_cmd_line() { return cmd_line_; }
33*1a96fba6SXin Li 
34*1a96fba6SXin Li   // Set the collection of open files.  This method DOES swap out the contents
35*1a96fba6SXin Li   // of |value|.  The caller should expect an empty set on return.
set_open_files(std::set<std::string> * value)36*1a96fba6SXin Li   void set_open_files(std::set<std::string>* value) {
37*1a96fba6SXin Li     open_files_.clear();
38*1a96fba6SXin Li     open_files_.swap(*value);
39*1a96fba6SXin Li   }
40*1a96fba6SXin Li 
get_open_files()41*1a96fba6SXin Li   const std::set<std::string>& get_open_files() { return open_files_; }
42*1a96fba6SXin Li 
43*1a96fba6SXin Li   // Set the current working directory.  This method DOES swap out the contents
44*1a96fba6SXin Li   // of |value|.  The caller should expect an empty string on return.
set_cwd(std::string * value)45*1a96fba6SXin Li   void set_cwd(std::string* value) {
46*1a96fba6SXin Li     cwd_.clear();
47*1a96fba6SXin Li     cwd_.swap(*value);
48*1a96fba6SXin Li   }
49*1a96fba6SXin Li 
get_cwd()50*1a96fba6SXin Li   const std::string& get_cwd() { return cwd_; }
51*1a96fba6SXin Li 
set_process_id(int value)52*1a96fba6SXin Li   void set_process_id(int value) { process_id_ = value; }
53*1a96fba6SXin Li 
get_process_id()54*1a96fba6SXin Li   int get_process_id() { return process_id_; }
55*1a96fba6SXin Li 
56*1a96fba6SXin Li  private:
57*1a96fba6SXin Li   std::vector<std::string> cmd_line_;
58*1a96fba6SXin Li   std::set<std::string> open_files_;
59*1a96fba6SXin Li   std::string cwd_;
60*1a96fba6SXin Li   int process_id_;
61*1a96fba6SXin Li };
62*1a96fba6SXin Li 
63*1a96fba6SXin Li }  // namespace brillo
64*1a96fba6SXin Li 
65*1a96fba6SXin Li #endif  // LIBBRILLO_BRILLO_PROCESS_INFORMATION_H_
66