rtop
info.h
Go to the documentation of this file.
1 #include <string>
2 #include <map>
3 #include <vector>
4 #include <fstream>
5 #include <iostream>
6 #include <iomanip>
7 #include <unordered_set>
8 #include <mutex>
9 #include <sstream>
10 
11 #ifndef _INFO_
12 #define _INFO_
13 #include "rtop_logger.h"
14 
15 extern src::severity_logger<severity_level> lg;
16 extern logSpacer log_spacer;
17 
18 namespace rtop
19 {
21 
25  class Info
26  {
27  private:
29  std::string header, longdesc, shortdesc;
30 
31  std::string units;
32  public:
33  Info(std::string hdr, std::string short_desc, std::string long_desc)
34  {
35  header = hdr;
36  longdesc = long_desc;
37  shortdesc = short_desc;
38  units = "";
39  }
40 
41  Info(std::string hdr, std::string short_desc, std::string long_desc, std::string unit_str)
42  {
43  header = hdr;
44  longdesc = long_desc;
45  shortdesc = short_desc;
46  units = unit_str;
47  }
48 
49  Info(const Info& obj)
50  {
51  header = obj.header;
52  longdesc = obj.longdesc;
53  shortdesc = obj.shortdesc;
54  units = obj.units;
55  }
56 
57  const char* Header(){return (const char*) header.c_str();}
58  const char* longDesc(){return (const char*)longdesc.c_str();}
59  const char* shortDesc(){return (const char*)shortdesc.c_str();}
60  std::string Unit(){return units;}
61  };
62 
64 
70  template <class T=int>
71  class InfoProc
72  {
73  private:
74  T val;
76  std::string shortdesc;
77  public:
79  InfoProc(T v){val = v;}
81  T Val(){return val;}
83  void setVal(T v){val = v;}
85  const char* longDesc()
86  {
87  return "";
88  }
90  const char* shortDesc()
91  {
92  std::stringstream ss;
93  ss<<val;
94  shortdesc = ss.str();
95  return (const char*)(shortdesc.c_str());
96  }
97  friend bool operator<=(const InfoProc<std::string>&, const InfoProc<std::string>&);
98  template<typename J>
99  friend std::ostream& operator<<(std::ostream&, const InfoProc<J>&);
100  };
101 
104  {
105  return (std::stoi(a.val) <= std::stoi(b.val));
106  }
107 
109  class ProcDb
110  {
111  private:
112  std::mutex access;
113  int uuid;
115  std::map<std::string, std::vector<InfoProc<std::string>>> database;
117  std::vector<int> sorted_indices;
119  std::map<int, std::pair<std::string, std::string>> field_prop_dict;
121  std::map<std::string, std::string> prop_type_dict;
123  int dbsize;
124  public:
126  ProcDb(int id):uuid{id}{dbsize=0;}
127  friend class ProcInfo;
128  friend class XMLTree;
129  friend class ProcViewPanel;
130  };
131 
132 
133 } // namespace rtop
134 
135 #endif
136 
137 
138 
std::string shortdesc
string representation of value
Definition: info.h:76
bool operator<=(const InfoProc< std::string > &a, const InfoProc< std::string > &b)
overloaded <= operator for comparing two InfoProc objects
Definition: info.h:103
Info(std::string hdr, std::string short_desc, std::string long_desc)
Definition: info.h:33
int uuid
Definition: info.h:113
friend bool operator<=(const InfoProc< std::string > &, const InfoProc< std::string > &)
overloaded <= operator for comparing two InfoProc objects
Definition: info.h:103
int dbsize
size of property vector i.e. number of processes whose properties are being maintained
Definition: info.h:123
const char * Header()
Definition: info.h:57
std::string shortdesc
Definition: info.h:29
ProcDb(int id)
ProcDb constructor. Instantiates object with provided unique identifier.
Definition: info.h:126
const char * shortDesc()
returns c-string corresponding to stored value. wasteful, as performs conversion everytime
Definition: info.h:90
const char * longDesc()
Definition: info.h:85
Info(std::string hdr, std::string short_desc, std::string long_desc, std::string unit_str)
Definition: info.h:41
data structure that hold property values for processes. contains facilities to enable their proper ac...
Definition: info.h:109
Info(const Info &obj)
Definition: info.h:49
void setVal(T v)
sets value
Definition: info.h:83
std::vector< int > sorted_indices
vector that holds the permutation order to parse property vectors in sorted order
Definition: info.h:117
std::string units
Definition: info.h:31
panel data structure responsible for displaying of property values for all live processes.
Definition: panel2.h:915
const char * longDesc()
Definition: info.h:58
logSpacer log_spacer
Definition: rtop_logger.h:186
friend std::ostream & operator<<(std::ostream &, const InfoProc< J > &)
std::map< std::string, std::vector< InfoProc< std::string > > > database
dictionary that holds vector of values corresponding to each property name string
Definition: info.h:115
std::string longdesc
Definition: info.h:29
data structure that defines type of entry from which panel menu entrires obtain their c-string data
Definition: info.h:25
std::string Unit()
Definition: info.h:60
std::map< int, std::pair< std::string, std::string > > field_prop_dict
dictionary that holds property locations in /proc/pid/stat file, and correspondingg prop name and typ...
Definition: info.h:119
src::severity_logger< severity_level > lg
Definition: rtop_logger.h:108
std::map< std::string, std::string > prop_type_dict
dictionary hold property name and corresponding type
Definition: info.h:121
enables indentation of logs for easy viewing
Definition: rtop_logger.h:118
data structure that defines type of entry from which panel menu entries obtain their c-string data
Definition: info.h:71
InfoProc(T v)
InfoProc constructor. Initializes InfoProc with provided value.
Definition: info.h:79
interfaces with linux API to read process information and update ProcDb with it
Definition: proc_info.h:24
std::string header
header, longdesc and shortdesc of a panel entry
Definition: info.h:29
const char * shortDesc()
Definition: info.h:59
parses config file
Definition: fileio.h:28
Definition: action.h:7
std::mutex access
Definition: info.h:112
T Val()
returns stored value
Definition: info.h:81