[Panel-devel] Connection of Sensor and Meter
Aaron J. Seigo
aseigo at kde.org
Tue Sep 20 15:36:11 CEST 2005
On Monday 19 September 2005 23:57, Vinay Khaitan wrote:
> What about the cases, in which data changes every millisecond (cpu load)?
hopefully, unless this data is being consumed by a meter, a sensor won't
update itself that often.
> sensor can have only one interval, and two meters want to refresh in
> different intervals?
if the plan is to have a one to many relationship between sensors and meters,
then the sensors shouldn't be actually emitting the signal but a proxy object
that sits between the sensor and the meter.
this proxy object, call it .. hm... SensorSignal would have a signal that is
connected to a meter and a QTimer that represents the refresh rate. so you
have something like:
void SensorSignal::SensorSignal(Sensor* sensor, unsigned int rate)
: QObject(sensor),
m_sensor(sensor)
{
setSignalRate(rate);
connect(timer, SIGNAL(timeout()), this, SLOT(emitSignal()));
}
void SensorSignal::setSignalRate(unsigned int ms)
{
timer.start(ms);
}
void SensorSignal::stopSignals()
{
timer.stop();
}
void SensorSignal::emitSignal()
{
emit updateValue(m_sensor->currentValue());
}
then, when a Sensor is connected to a Meter, it actually connects a
SensorSignal object to the Meter. when the Meter changes the rate (via the
Sensor) the sensor changes the rate of the SensorSignal. if you wanted to be
extra efficient you could use the same SensorSignal more than once if the
requested rate is the same for more than one Meter. i wouldn't be so
concerned about that, though, unless it became a performance issue (i doubt
it will).
the remaining problem would then be when the associated Meter is destroyed,
the SensorSignal ought to be cleaned up as well. keep a QMap<Meter,
SensorSignal> in the Sensor and connecting to the Meter's
QObject::destroyed(QObject*) should do the trick though.
--
Aaron J. Seigo
GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA EE75 D6B7 2EB1 A7F1 DB43
Full time KDE developer sponsored by Trolltech (http://www.trolltech.com)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/panel-devel/attachments/20050920/084c3764/attachment.pgp
More information about the Panel-devel
mailing list