|
From: Michael R. <re...@eu...> - 2004-01-17 09:53:56
|
Hi Xavier, Hi list,
>>If you use a hash, you fill up the hash with all values from
>>/proc/cpuinfo when parsing it. Subsequent calls would not parse the file
>>again, but read the values from the hash.
>
> Okay, I understand it ! In fact, hashes are handled by the plugins internally.
Right!
>>You have to use something like a "timeout", and remember the time when
>>the contents of the file was last read. If the timeout is over, you have
>>to read and parse the file again.
> What about this timeout ? Is there a helper ? Maybe a function to
> register timeouts and see if they timed-out. It may be in yet, sorry
> I don't have to code under my eyes :/
The code is that simple that I didn't write a helper for it(although
there is a timer queue management, but this is used for widge updates).
If your timeout is 1 second or higher, and second-resolution is enough,
use the following:
static int parse_anything(void)
{
static time_t now=0;
// reread every second only
if (time(NULL)==now) return 0;
time(&now);
// real parsing happens here...
return 0;
}
If you need higher resolutions (milliseconds), you need the following
snippet:
static struct timeval end = {0, 0};
struct timeval now;
// update every 10 msec
gettimeofday(&now, NULL);
if (now.tv_sec==end.tv_sec?
now.tv_usec<end.tv_usec:now.tv_sec<end.tv_sec) {
return 0;
}
end.tv_sec = now.tv_sec;
end.tv_usec = now.tv_usec + 1000*msec;
while (end.tv_usec > 1000000) {
end.tv_usec -= 1000000;
end.tv_sec++;
}
// parse it...
> 'lcd4linux -l' can load all
> the drivers it knows, we don't matter about memory usage as it'll die
> then. Same to list plugins.
Thats what I'm thinking of, too.
> I fact, I thinked about a sort of 'callback' function : now if the eval
> doesn't know a function, it returns an error. It may call a function
> which loads the good plugin and evaluates the function, so that the
> evaluator doesn't mind and everybody's happy ;) It's not the evaluator
> that searches for plugins at startup, it 'learns' with its "errors". In
> this way, we don't need to modify much the eval.
And how should the evaluator know which .so to load?
> This .so-ing may be later, but we should keep it in mind so that we
> don't do silly things that will prevent us to make it then.
Full ACK.
bye, Michael
--
Michael Reinelt Tel: +43 676 3079941
Geisslergasse 4 Fax: +43 316 692343
A-8045 Graz, Austria e-mail: re...@eu...
|