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