1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
/*
KSysGuard, the KDE System Guard
Copyright (c) 1999, 2000 Chris Schlaeger <cs@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of version 2 of the GNU General Public
License as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
KSysGuard is currently maintained by Chris Schlaeger <cs@kde.org>.
Please do not commit any changes without consulting me first. Thanks!
*/
#ifndef KSG_SENSORCLIENT_H
#define KSG_SENSORCLIENT_H
#include <tqptrlist.h>
#include <tqstring.h>
namespace KSGRD {
/**
Every object that should act as a client to a sensor must inherit from
this class. A pointer to the client object is passed as SensorClient*
to the SensorAgent. When the requested information is available or a
problem occurred one of the member functions is called.
*/
class SensorClient
{
public:
SensorClient() { }
virtual ~SensorClient() { }
/**
This function is called whenever the information form the sensor has
been received by the sensor agent. This function must be reimplemented
by the sensor client to receive and process this information.
*/
virtual void answerReceived( int, const TQString& ) { }
/**
In case of an unexpected fatal problem with the sensor the sensor
agent will call this function to notify the client about it.
*/
virtual void sensorLost( int ) { }
};
/**
Every object that has a SensorClient as a child must inherit from
this class to support the advanced update interval settings.
*/
class SensorBoard
{
public:
SensorBoard() { }
virtual ~SensorBoard() { }
void updateInterval( int interval ) { mUpdateInterval = interval; }
int updateInterval() { return mUpdateInterval; }
private:
int mUpdateInterval;
};
/**
The following classes are utility classes that provide a
convenient way to retrieve pieces of information from the sensor
answers. For each type of answer there is a separate class.
*/
class SensorTokenizer
{
public:
SensorTokenizer( const TQString &info, TQChar separator )
{
mTokens = TQStringList::split( separator, info );
}
~SensorTokenizer() { }
const TQString& operator[]( unsigned idx )
{
return mTokens[ idx ];
}
uint count()
{
return mTokens.count();
}
private:
TQStringList mTokens;
};
/**
An integer info tqcontains 4 fields seperated by TABS, a description
(name), the minimum and the maximum values and the unit.
e.g. Swap Memory 0 133885952 KB
*/
class SensorIntegerInfo : public SensorTokenizer
{
public:
SensorIntegerInfo( const TQString &info )
: SensorTokenizer( info, '\t' ) { }
~SensorIntegerInfo() { }
const TQString &name()
{
return (*this)[ 0 ];
}
long min()
{
return (*this)[ 1 ].toLong();
}
long max()
{
return (*this)[ 2 ].toLong();
}
const TQString &unit()
{
return (*this)[ 3 ];
}
};
/**
An float info tqcontains 4 fields seperated by TABS, a description
(name), the minimum and the maximum values and the unit.
e.g. CPU Voltage 0.0 5.0 V
*/
class SensorFloatInfo : public SensorTokenizer
{
public:
SensorFloatInfo( const TQString &info )
: SensorTokenizer( info, '\t' ) { }
~SensorFloatInfo() { }
const TQString &name()
{
return (*this)[ 0 ];
}
double min()
{
return (*this)[ 1 ].toDouble();
}
double max()
{
return (*this)[ 2 ].toDouble();
}
const TQString &unit()
{
return (*this)[ 3 ];
}
};
/**
A PS line consists of information about a process. Each piece of
information is seperated by a TAB. The first 4 fields are process name,
PID, PPID and real user ID. Those fields are mandatory.
*/
class SensorPSLine : public SensorTokenizer
{
public:
SensorPSLine( const TQString &line )
: SensorTokenizer( line, '\t' ) { }
~SensorPSLine() { }
const TQString& name()
{
return (*this)[ 0 ];
}
long pid()
{
return (*this)[ 1 ].toLong();
}
long ppid()
{
return (*this)[ 2 ].toLong();
}
long uid()
{
return (*this)[ 3 ].toLong();
}
};
}
#endif
|