Skip to content

Commit 41daedf

Browse files
committed
docs/new-drivers.txt: document addvar, getval and testvar, and nut_usb_addvars (and planned ser/modbus siblings) [networkupstools#2419, networkupstools#2748]
Documentation addition triggered by discussion in networkupstools#3181 Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
1 parent 2cbdaea commit 41daedf

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed

docs/new-drivers.txt

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,87 @@ for eventual `exit(EXIT_FAILURE)` and `EF_EXIT_SUCCESS` (`-2`) for
181181
`exit(EXIT_SUCCESS)`, which would be handled in the standard driver
182182
loop or in `forceshutdown()` method of `main.c`.
183183

184+
addvar, getval and testvar
185+
~~~~~~~~~~~~~~~~~~~~~~~~~~
186+
187+
NUT drivers can be configured at run-time with optional settings, which
188+
can be passed on command line or via the linkman:ups.conf[5] file.
189+
Such settings broadly fall into two categories: "values" which convey
190+
some specific value (e.g. `port` or `desc` strings), and "flags" which
191+
can be seen as a sort of booleans which are `true` if mentioned and
192+
`false` if not (any assigned value would be ignored, if not rejected
193+
by configuration parser).
194+
195+
Some options are common to all drivers and are handled in `drivers/main.c`
196+
(which also defines and implements most of the methods in this area), while
197+
others may be specific to individual drivers or even their sub-drivers.
198+
199+
The `addvar()` method allows to specify a certain option name, with its
200+
type and a help message string:
201+
202+
addvar(VAR_VALUE, "sdtype", "Specify simple shutdown method (0-6)");
203+
204+
addvar(VAR_FLAG, "wait", "Wait for AC power");
205+
206+
In driver code, these calls should comprise the `upsdrv_makevartable()`
207+
method.
208+
209+
The `getval()` method allows to get the user-provided string value (or
210+
`NULL` -- but it is hard to tell apart if the option was not specified
211+
or no value was assigned). The `testvar()` method allows to check if
212+
the option name was specified (even if without a value), so is better
213+
suited for flags. Internally there is no difference between "values"
214+
and "flags", so historically some flags were "promoted" to values with
215+
boolean-ish strings handled explicitly, in addition to some new features.
216+
217+
NOTE: Internally, the values can also be marked as reloadable (so that a
218+
running driver program may change them when re-reading the configuration
219+
file due to a signal). The implementation may be currently limited to
220+
common options handled by `main.c` itself. In code base this is exposed
221+
with the `addvar_reloadable()` and several `test*_reloadable()` methods.
222+
223+
Since these methods involve a data structure walk to locate (or not) the
224+
entry for each option, they should not be used in data processing loops.
225+
Instead, the driver initialization methods such as `upsdrv_initups()`
226+
should consider all values and flags that can impact the set-up of the
227+
driver, and save them into C variables (typically strings, booleans, or
228+
processed and range/value-checked number types) which are then directly
229+
used in the driver program code.
230+
231+
nut_usb_addvars
232+
~~~~~~~~~~~~~~~
233+
234+
For consistency between USB-capable NUT drivers, a set of `addvar()`
235+
options related to USB media setup and expected by `nut_libusb_open()`
236+
can be defined by calling the `nut_usb_addvars()` method, which can be
237+
seen in `drivers/libusb{0,1}.c`.
238+
239+
Like `addvar()`, a call to this method belongs in `upsdrv_makevartable()`
240+
(see existing drivers for examples).
241+
242+
243+
nut_ser_addvars
244+
~~~~~~~~~~~~~~~
245+
246+
WARNING: NOT CURRENTLY IMPLEMENTED.
247+
248+
Issue https://github.com/networkupstools/nut/issues/2748 tracks the idea
249+
to standardize the set and names of options involved in the serial driver
250+
connection set-up (speed, parity, stop-bits, etc.) similarly to the
251+
precedent of `nut_usb_addvars()`. One problem is that many drivers
252+
released during the past decades reinvented this wheel with different
253+
option names.
254+
255+
nut_modbus_addvars
256+
~~~~~~~~~~~~~~~~~~
257+
258+
WARNING: NOT CURRENTLY IMPLEMENTED.
259+
260+
Issue https://github.com/networkupstools/nut/issues/2419 tracks a similar
261+
idea for Modbus-capable drivers (which may involve or not Serial and/or
262+
USB link and option support, and uniquely TCP/IP RTU support, for example).
263+
264+
184265
Data types
185266
----------
186267

docs/nut.dict

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
personal_ws-1.1 en 3577 utf-8
1+
personal_ws-1.1 en 3582 utf-8
22
AAC
33
AAS
44
ABI
@@ -1546,6 +1546,7 @@ additionalSOLibSearchPath
15461546
addons
15471547
addr
15481548
addrange
1549+
addvar
15491550
addvars
15501551
adelsystem
15511552
adkorte
@@ -1707,6 +1708,7 @@ bmake
17071708
bn
17081709
bool
17091710
boolean
1711+
booleans
17101712
bootable
17111713
bootenv
17121714
bootfs
@@ -2151,6 +2153,7 @@ getopt
21512153
getproctag
21522154
gettext
21532155
gettextize
2156+
getval
21542157
getvar
21552158
gh
21562159
gif
@@ -2953,6 +2956,7 @@ regtype
29532956
relatime
29542957
releasekeyring
29552958
relicensing
2959+
reloadable
29562960
relogtime
29572961
remoteip
29582962
renderer
@@ -3263,6 +3267,7 @@ termios
32633267
testime
32643268
testtime
32653269
testuser
3270+
testvar
32663271
textproc
32673272
tgcware
32683273
tgt

0 commit comments

Comments
 (0)