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 PageFaultsDataSource : public DataSource { 267 public: 268 PageFaultsDataSource(); 269 PageFaultsDataSource( 270 const PageFaultsDataSource& other); 271 virtual ~PageFaultsDataSource(); 272 273 virtual DataSource* Copy() 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 virtual bool AdaptiveScale() const; 283 virtual bool Primary() const; 284 285 private: 286 uint32 fPreviousFaults; 287 bigtime_t fPreviousTime; 288 }; 289 290 291 class NetworkUsageDataSource : public DataSource { 292 public: 293 NetworkUsageDataSource(bool in); 294 NetworkUsageDataSource( 295 const NetworkUsageDataSource& other); 296 virtual ~NetworkUsageDataSource(); 297 298 virtual DataSource* Copy() const; 299 300 virtual void Print(BString& text, int64 value) const; 301 virtual int64 NextValue(SystemInfo& info); 302 303 virtual const char* InternalName() const; 304 virtual const char* Name() const; 305 virtual const char* Label() const; 306 virtual const char* ShortLabel() const; 307 virtual bool AdaptiveScale() const; 308 virtual scale_type ScaleType() const; 309 virtual bool Primary() const; 310 311 private: 312 bool fIn; 313 uint64 fPreviousBytes; 314 bigtime_t fPreviousTime; 315 }; 316 317 318 class ClipboardSizeDataSource : public DataSource { 319 public: 320 ClipboardSizeDataSource(bool text); 321 ClipboardSizeDataSource( 322 const ClipboardSizeDataSource& other); 323 virtual ~ClipboardSizeDataSource(); 324 325 virtual DataSource* Copy() const; 326 327 virtual int64 NextValue(SystemInfo& info); 328 329 virtual const char* InternalName() const; 330 virtual const char* Label() const; 331 virtual const char* Unit() const; 332 virtual bool AdaptiveScale() const; 333 334 private: 335 bool fText; 336 }; 337 338 339 class MediaNodesDataSource : public DataSource { 340 public: 341 MediaNodesDataSource(); 342 virtual ~MediaNodesDataSource(); 343 344 virtual DataSource* Copy() const; 345 346 virtual const char* InternalName() const; 347 virtual int64 NextValue(SystemInfo& info); 348 virtual const char* Label() const; 349 virtual bool AdaptiveScale() const; 350 }; 351 352 #endif // DATA_SOURCE_H 353