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