[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-panel-devel
Subject:    Re: [Panel-devel] Connection of Sensor and Meter
From:       "Aaron J. Seigo" <aseigo () kde ! org>
Date:       2005-09-20 13:36:11
Message-ID: 200509200736.12510.aseigo () kde ! org
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


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)

[Attachment #5 (application/pgp-signature)]

_______________________________________________
Panel-devel mailing list
Panel-devel@kde.org
https://mail.kde.org/mailman/listinfo/panel-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic