xref: /haiku/src/apps/activitymonitor/DataSource.h (revision 58481f0f6ef1a61ba07283f012cafbc2ed874ead)
1 /*
2  * Copyright 2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef DATA_SOURCE_H
6 #define DATA_SOURCE_H
7 
8 
9 #include <InterfaceDefs.h>
10 #include <String.h>
11 
12 class SystemInfo;
13 
14 
15 enum scale_type {
16 	kNoScale,
17 	kBytePerSecondScale,
18 };
19 
20 class DataSource {
21 public:
22 						DataSource(int64 initialMin, int64 initialMax);
23 						DataSource();
24 						DataSource(const DataSource& other);
25 	virtual				~DataSource();
26 
27 	virtual DataSource*	Copy() const;
28 	virtual DataSource*	CopyForCPU(int32 cpu) const;
29 
30 			int64		Minimum() const;
31 			int64		Maximum() const;
32 			bigtime_t	RefreshInterval() const;
33 
34 	virtual void		SetLimits(int64 min, int64 max);
35 	virtual void		SetRefreshInterval(bigtime_t interval);
36 	virtual void		SetColor(rgb_color color);
37 
38 	virtual	int64		NextValue(SystemInfo& info);
39 	virtual void		Print(BString& text, int64 value) const;
40 
41 	virtual const char*	Name() const;
42 	virtual const char*	Label() const;
43 	virtual const char*	ShortLabel() const;
44 	virtual const char*	Unit() const;
45 	virtual rgb_color	Color() const;
46 	virtual bool		AdaptiveScale() const;
47 	virtual scale_type	ScaleType() const;
48 	virtual int32		CPU() const;
49 	virtual bool		PerCPU() const;
50 	virtual bool		MultiCPUOnly() const;
51 	virtual bool		Primary() const;
52 
53 	static int32		CountSources();
54 	static const DataSource* SourceAt(int32 index);
55 	static const DataSource* FindSource(const char* name);
56 	static int32		IndexOf(const DataSource* source);
57 
58 protected:
59 	int64				fMinimum;
60 	int64				fMaximum;
61 	bigtime_t			fInterval;
62 	rgb_color			fColor;
63 };
64 
65 
66 class MemoryDataSource : public DataSource {
67 public:
68 						MemoryDataSource();
69 	virtual				~MemoryDataSource();
70 
71 	virtual void		Print(BString& text, int64 value) const;
72 	virtual const char*	Unit() const;
73 };
74 
75 
76 class UsedMemoryDataSource : public MemoryDataSource {
77 public:
78 						UsedMemoryDataSource();
79 	virtual				~UsedMemoryDataSource();
80 
81 	virtual DataSource*	Copy() const;
82 
83 	virtual	int64		NextValue(SystemInfo& info);
84 	virtual const char*	Label() const;
85 	virtual const char*	ShortLabel() const;
86 	virtual bool		Primary() const;
87 };
88 
89 
90 class CachedMemoryDataSource : public MemoryDataSource {
91 public:
92 						CachedMemoryDataSource();
93 	virtual				~CachedMemoryDataSource();
94 
95 	virtual DataSource*	Copy() const;
96 
97 	virtual	int64		NextValue(SystemInfo& info);
98 	virtual const char*	Label() const;
99 	virtual const char*	ShortLabel() const;
100 	virtual bool		Primary() const;
101 };
102 
103 
104 class SwapSpaceDataSource : public MemoryDataSource {
105 public:
106 						SwapSpaceDataSource();
107 	virtual				~SwapSpaceDataSource();
108 
109 	virtual DataSource*	Copy() const;
110 
111 	virtual	int64		NextValue(SystemInfo& info);
112 	virtual const char*	Label() const;
113 	virtual const char*	ShortLabel() const;
114 	virtual bool		Primary() const;
115 };
116 
117 
118 class SemaphoresDataSource : public DataSource {
119 public:
120 						SemaphoresDataSource();
121 	virtual				~SemaphoresDataSource();
122 
123 	virtual DataSource*	Copy() const;
124 
125 	virtual	int64		NextValue(SystemInfo& info);
126 	virtual const char*	Label() const;
127 	virtual const char*	ShortLabel() const;
128 	virtual bool		AdaptiveScale() const;
129 };
130 
131 
132 class PortsDataSource : public DataSource {
133 public:
134 						PortsDataSource();
135 	virtual				~PortsDataSource();
136 
137 	virtual DataSource*	Copy() const;
138 
139 	virtual	int64		NextValue(SystemInfo& info);
140 	virtual const char*	Label() const;
141 	virtual bool		AdaptiveScale() const;
142 };
143 
144 
145 class ThreadsDataSource : public DataSource {
146 public:
147 						ThreadsDataSource();
148 	virtual				~ThreadsDataSource();
149 
150 	virtual DataSource*	Copy() const;
151 
152 	virtual	int64		NextValue(SystemInfo& info);
153 	virtual const char*	Label() const;
154 	virtual bool		AdaptiveScale() const;
155 };
156 
157 
158 class TeamsDataSource : public DataSource {
159 public:
160 						TeamsDataSource();
161 	virtual				~TeamsDataSource();
162 
163 	virtual DataSource*	Copy() const;
164 
165 	virtual	int64		NextValue(SystemInfo& info);
166 	virtual const char*	Label() const;
167 	virtual bool		AdaptiveScale() const;
168 };
169 
170 
171 class RunningAppsDataSource : public DataSource {
172 public:
173 						RunningAppsDataSource();
174 	virtual				~RunningAppsDataSource();
175 
176 	virtual DataSource*	Copy() const;
177 
178 	virtual	int64		NextValue(SystemInfo& info);
179 	virtual const char*	Label() const;
180 	virtual const char*	ShortLabel() const;
181 	virtual bool		AdaptiveScale() const;
182 };
183 
184 
185 class CPUUsageDataSource : public DataSource {
186 public:
187 						CPUUsageDataSource(int32 cpu = 0);
188 						CPUUsageDataSource(const CPUUsageDataSource& other);
189 	virtual				~CPUUsageDataSource();
190 
191 	virtual DataSource*	Copy() const;
192 	virtual DataSource*	CopyForCPU(int32 cpu) const;
193 
194 	virtual void		Print(BString& text, int64 value) const;
195 	virtual	int64		NextValue(SystemInfo& info);
196 
197 	virtual const char*	Name() const;
198 	virtual const char*	Label() const;
199 	virtual const char*	ShortLabel() const;
200 
201 	virtual int32		CPU() const;
202 	virtual bool		PerCPU() const;
203 	virtual bool		Primary() const;
204 
205 private:
206 			void		_SetCPU(int32 cpu);
207 
208 	bigtime_t			fPreviousActive;
209 	bigtime_t			fPreviousTime;
210 	int32				fCPU;
211 	BString				fLabel;
212 	BString				fShortLabel;
213 };
214 
215 
216 class CPUCombinedUsageDataSource : public DataSource {
217 public:
218 						CPUCombinedUsageDataSource();
219 						CPUCombinedUsageDataSource(
220 							const CPUCombinedUsageDataSource& other);
221 	virtual				~CPUCombinedUsageDataSource();
222 
223 	virtual DataSource*	Copy() const;
224 
225 	virtual void		Print(BString& text, int64 value) const;
226 	virtual	int64		NextValue(SystemInfo& info);
227 
228 	virtual const char*	Name() const;
229 	virtual const char*	Label() const;
230 	virtual const char*	ShortLabel() const;
231 
232 	virtual bool		MultiCPUOnly() const;
233 	virtual bool		Primary() const;
234 
235 private:
236 	bigtime_t			fPreviousActive;
237 	bigtime_t			fPreviousTime;
238 };
239 
240 
241 class PageFaultsDataSource : public DataSource {
242 public:
243 						PageFaultsDataSource();
244 						PageFaultsDataSource(
245 							const PageFaultsDataSource& other);
246 	virtual				~PageFaultsDataSource();
247 
248 	virtual DataSource*	Copy() const;
249 
250 	virtual void		Print(BString& text, int64 value) const;
251 	virtual	int64		NextValue(SystemInfo& info);
252 
253 	virtual const char*	Name() const;
254 	virtual const char*	Label() const;
255 	virtual const char*	ShortLabel() const;
256 	virtual bool		AdaptiveScale() const;
257 	virtual bool		Primary() const;
258 
259 private:
260 	uint32				fPreviousFaults;
261 	bigtime_t			fPreviousTime;
262 };
263 
264 
265 class NetworkUsageDataSource : public DataSource {
266 public:
267 						NetworkUsageDataSource(bool in);
268 						NetworkUsageDataSource(
269 							const NetworkUsageDataSource& other);
270 	virtual				~NetworkUsageDataSource();
271 
272 	virtual DataSource*	Copy() const;
273 
274 	virtual void		Print(BString& text, int64 value) const;
275 	virtual	int64		NextValue(SystemInfo& info);
276 
277 	virtual const char*	Name() const;
278 	virtual const char*	Label() const;
279 	virtual const char*	ShortLabel() const;
280 	virtual bool		AdaptiveScale() const;
281 	virtual scale_type	ScaleType() const;
282 	virtual bool		Primary() const;
283 
284 private:
285 	bool				fIn;
286 	uint64				fPreviousBytes;
287 	bigtime_t			fPreviousTime;
288 };
289 
290 
291 class ClipboardSizeDataSource : public DataSource {
292 public:
293 						ClipboardSizeDataSource(bool text);
294 						ClipboardSizeDataSource(
295 							const ClipboardSizeDataSource& other);
296 	virtual				~ClipboardSizeDataSource();
297 
298 	virtual DataSource*	Copy() const;
299 
300 	virtual	int64		NextValue(SystemInfo& info);
301 
302 	virtual const char*	Label() const;
303 	virtual const char*	Unit() const;
304 	virtual bool		AdaptiveScale() const;
305 
306 private:
307 	bool				fText;
308 };
309 
310 
311 class MediaNodesDataSource : public DataSource {
312 public:
313 						MediaNodesDataSource();
314 	virtual				~MediaNodesDataSource();
315 
316 	virtual DataSource*	Copy() const;
317 
318 	virtual	int64		NextValue(SystemInfo& info);
319 	virtual const char*	Label() const;
320 	virtual bool		AdaptiveScale() const;
321 };
322 
323 #endif	// DATA_SOURCE_H
324