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