[Nut-upsdev] RFC: allow HID subdriver's to register ups.conf

Peter Selinger selinger at mathstat.dal.ca
Sun Jun 4 00:27:44 UTC 2006


j T wrote:

> >- allow the value to be NULL if a subdriver does not require
> >   initialization.
> 
> Am I right in thinking that this is simply a case of doing:
> 
> 	subdriver_t some_subdriver = {
> 		/* ... */
> 		some_format_serial,
> 		NULL,
> 	}
> 
> Rather than:
> 
> 	subdriver_t belkin_subdriver = {
> 		/* ... */
> 		belkin_format_serial,
> 		belkin_init,
> 	}
> in the subdrivers that don't need init()ing?

Yes.
 
> >- change the call to:
> >
> >   if (subdriver->init != NULL) {
> >      subdriver->init();
> >   }
> 
> As I've found out since I came up with the original idea  (see one of my 
> previous messages)  I can't call subdriver->function() from makevartable as 
> subdriver hasn't been given a sensible value at that point, instead, I'm 
> having to do:
> 
> 	for (i=0; subdriver_list[i] != NULL; i++) {
> 		subdriver_list[i]->extendvartable();
> 	}
> 
> So I assume that I should modify this to be:
> 
> 	for (i=0; subdriver_list[i] != NULL; i++) {
> 		if (subdriver[i]->init != NULL) {
> 			subdriver_list[i]->init();
> 		}
> 	}

This is a bad idea. It would mean that the variables of *all* the
subdrivers would be loaded, rather than just the correct subdriver.
Probably a better solution is to wait until the subdriver has been
determined, and then load the variables. But I don't know if this is
possible; it might break the driver higher up.

> As init() is more general-purpose than my extendvartable(), is it still ok 
> to have it be called from the end of upsdrv_makevartable()?
> 
> I was just thinking that, while it's reasonable to expect that the 
> subdriver's vartable additions would happen there (hence the name 
> "extendvartable"), it's not necessarily the most obvious place for other 
> kinds of initialisation to happen when a routine called "makevartable" is 
> getting called from main()...
> 
> Anyway, just a thought...

This is related to the question of when to define these variables. As
you pointed out, it cannot be done in upsdrv_makevartable(). So
perhaps it is more sensible to have a general init routine, and to
call it from within upsdrv_initups(), just after the subdriver has
been selected. 

Please keep the traffic on the mailing list.

-- Peter



More information about the Nut-upsdev mailing list