1 // Copyright (c) 2012 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 LIBBRILLO_BRILLO_PROCESS_INFORMATION_H_ 6 #define LIBBRILLO_BRILLO_PROCESS_INFORMATION_H_ 7 8 #include <set> 9 #include <string> 10 #include <vector> 11 12 #include <brillo/brillo_export.h> 13 14 namespace brillo { 15 16 // Information for a single running process. Stores its command line, set of 17 // open files, process id and working directory. 18 class BRILLO_EXPORT ProcessInformation { 19 public: 20 ProcessInformation(); 21 virtual ~ProcessInformation(); 22 23 std::string GetCommandLine(); 24 25 // Set the command line array. This method DOES swap out the contents of 26 // |value|. The caller should expect an empty vector on return. set_cmd_line(std::vector<std::string> * value)27 void set_cmd_line(std::vector<std::string>* value) { 28 cmd_line_.clear(); 29 cmd_line_.swap(*value); 30 } 31 get_cmd_line()32 const std::vector<std::string>& get_cmd_line() { return cmd_line_; } 33 34 // Set the collection of open files. This method DOES swap out the contents 35 // of |value|. The caller should expect an empty set on return. set_open_files(std::set<std::string> * value)36 void set_open_files(std::set<std::string>* value) { 37 open_files_.clear(); 38 open_files_.swap(*value); 39 } 40 get_open_files()41 const std::set<std::string>& get_open_files() { return open_files_; } 42 43 // Set the current working directory. This method DOES swap out the contents 44 // of |value|. The caller should expect an empty string on return. set_cwd(std::string * value)45 void set_cwd(std::string* value) { 46 cwd_.clear(); 47 cwd_.swap(*value); 48 } 49 get_cwd()50 const std::string& get_cwd() { return cwd_; } 51 set_process_id(int value)52 void set_process_id(int value) { process_id_ = value; } 53 get_process_id()54 int get_process_id() { return process_id_; } 55 56 private: 57 std::vector<std::string> cmd_line_; 58 std::set<std::string> open_files_; 59 std::string cwd_; 60 int process_id_; 61 }; 62 63 } // namespace brillo 64 65 #endif // LIBBRILLO_BRILLO_PROCESS_INFORMATION_H_ 66