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* Unit() const; 44 virtual rgb_color Color() const; 45 virtual bool AdaptiveScale() const; 46 virtual scale_type ScaleType() const; 47 virtual int32 CPU() const; 48 virtual bool PerCPU() const; 49 virtual bool MultiCPUOnly() const; 50 virtual bool Primary() const; 51 52 static int32 CountSources(); 53 static const DataSource* SourceAt(int32 index); 54 static const DataSource* FindSource(const char* name); 55 static int32 IndexOf(const DataSource* source); 56 57 protected: 58 int64 fMinimum; 59 int64 fMaximum; 60 bigtime_t fInterval; 61 rgb_color fColor; 62 }; 63 64 65 class MemoryDataSource : public DataSource { 66 public: 67 MemoryDataSource(); 68 virtual ~MemoryDataSource(); 69 70 virtual void Print(BString& text, int64 value) const; 71 virtual const char* Unit() const; 72 }; 73 74 75 class UsedMemoryDataSource : public MemoryDataSource { 76 public: 77 UsedMemoryDataSource(); 78 virtual ~UsedMemoryDataSource(); 79 80 virtual DataSource* Copy() const; 81 82 virtual int64 NextValue(SystemInfo& info); 83 virtual const char* Label() const; 84 virtual bool Primary() const; 85 }; 86 87 88 class CachedMemoryDataSource : public MemoryDataSource { 89 public: 90 CachedMemoryDataSource(); 91 virtual ~CachedMemoryDataSource(); 92 93 virtual DataSource* Copy() const; 94 95 virtual int64 NextValue(SystemInfo& info); 96 virtual const char* Label() const; 97 virtual bool Primary() const; 98 }; 99 100 101 class SemaphoresDataSource : public DataSource { 102 public: 103 SemaphoresDataSource(); 104 virtual ~SemaphoresDataSource(); 105 106 virtual DataSource* Copy() const; 107 108 virtual int64 NextValue(SystemInfo& info); 109 virtual const char* Label() const; 110 virtual bool AdaptiveScale() const; 111 }; 112 113 114 class PortsDataSource : public DataSource { 115 public: 116 PortsDataSource(); 117 virtual ~PortsDataSource(); 118 119 virtual DataSource* Copy() const; 120 121 virtual int64 NextValue(SystemInfo& info); 122 virtual const char* Label() const; 123 virtual bool AdaptiveScale() const; 124 }; 125 126 127 class ThreadsDataSource : public DataSource { 128 public: 129 ThreadsDataSource(); 130 virtual ~ThreadsDataSource(); 131 132 virtual DataSource* Copy() const; 133 134 virtual int64 NextValue(SystemInfo& info); 135 virtual const char* Label() const; 136 virtual bool AdaptiveScale() const; 137 }; 138 139 140 class TeamsDataSource : public DataSource { 141 public: 142 TeamsDataSource(); 143 virtual ~TeamsDataSource(); 144 145 virtual DataSource* Copy() const; 146 147 virtual int64 NextValue(SystemInfo& info); 148 virtual const char* Label() const; 149 virtual bool AdaptiveScale() const; 150 }; 151 152 153 class RunningAppsDataSource : public DataSource { 154 public: 155 RunningAppsDataSource(); 156 virtual ~RunningAppsDataSource(); 157 158 virtual DataSource* Copy() const; 159 160 virtual int64 NextValue(SystemInfo& info); 161 virtual const char* Label() const; 162 virtual bool AdaptiveScale() const; 163 }; 164 165 166 class CPUUsageDataSource : public DataSource { 167 public: 168 CPUUsageDataSource(int32 cpu = 0); 169 CPUUsageDataSource(const CPUUsageDataSource& other); 170 virtual ~CPUUsageDataSource(); 171 172 virtual DataSource* Copy() const; 173 virtual DataSource* CopyForCPU(int32 cpu) const; 174 175 virtual void Print(BString& text, int64 value) const; 176 virtual int64 NextValue(SystemInfo& info); 177 178 virtual const char* Name() const; 179 virtual const char* Label() const; 180 181 virtual int32 CPU() const; 182 virtual bool PerCPU() const; 183 virtual bool Primary() const; 184 185 private: 186 void _SetCPU(int32 cpu); 187 188 bigtime_t fPreviousActive; 189 bigtime_t fPreviousTime; 190 int32 fCPU; 191 BString fLabel; 192 }; 193 194 195 class CPUCombinedUsageDataSource : public DataSource { 196 public: 197 CPUCombinedUsageDataSource(); 198 CPUCombinedUsageDataSource( 199 const CPUCombinedUsageDataSource& other); 200 virtual ~CPUCombinedUsageDataSource(); 201 202 virtual DataSource* Copy() const; 203 204 virtual void Print(BString& text, int64 value) const; 205 virtual int64 NextValue(SystemInfo& info); 206 207 virtual const char* Name() const; 208 virtual const char* Label() const; 209 210 virtual bool MultiCPUOnly() const; 211 virtual bool Primary() const; 212 213 private: 214 bigtime_t fPreviousActive; 215 bigtime_t fPreviousTime; 216 }; 217 218 219 class NetworkUsageDataSource : public DataSource { 220 public: 221 NetworkUsageDataSource(bool in); 222 NetworkUsageDataSource( 223 const NetworkUsageDataSource& other); 224 virtual ~NetworkUsageDataSource(); 225 226 virtual DataSource* Copy() const; 227 228 virtual void Print(BString& text, int64 value) const; 229 virtual int64 NextValue(SystemInfo& info); 230 231 virtual const char* Name() const; 232 virtual const char* Label() const; 233 virtual bool AdaptiveScale() const; 234 virtual bool Primary() const; 235 236 private: 237 bool fIn; 238 uint64 fPreviousBytes; 239 bigtime_t fPreviousTime; 240 }; 241 242 243 class ClipboardSizeDataSource : public DataSource { 244 public: 245 ClipboardSizeDataSource(bool text); 246 ClipboardSizeDataSource( 247 const ClipboardSizeDataSource& other); 248 virtual ~ClipboardSizeDataSource(); 249 250 virtual DataSource* Copy() const; 251 252 virtual int64 NextValue(SystemInfo& info); 253 254 virtual const char* Label() const; 255 virtual const char* Unit() const; 256 virtual bool AdaptiveScale() const; 257 258 private: 259 bool fText; 260 }; 261 262 263 class MediaNodesDataSource : public DataSource { 264 public: 265 MediaNodesDataSource(); 266 virtual ~MediaNodesDataSource(); 267 268 virtual DataSource* Copy() const; 269 270 virtual int64 NextValue(SystemInfo& info); 271 virtual const char* Label() const; 272 virtual bool AdaptiveScale() const; 273 }; 274 275 #endif // DATA_SOURCE_H 276