Specifications
CHAPTER 5. IMPLEMENTATION 36
Data Structure
Both data structures ModuleData and ModuleOption are declared in libial mod.h. The
structure ModuleData is slightly shortened compared to the source code.
typedef struct ModuleOption_s {
const char *name;
char value[MAX_BUF];
const char *descr;
} ModuleOption;
typedef struct ModuleData_s {
const char *name;
const char *token;
const char *version;
const char *author;
const char *descr;
ModuleOption *options;
gboolean(*load) (void);
gboolean(*unload) (void);
} ModuleData;
The structure ModuleOption represents a module’s configuration option. The member
name contains the name of the option followed by value in which the option’s value is stored.
It has to be initialized statically with a default value. A description of the option is stored
in descr. As mentioned above, all modules are required to define an array of ModuleOption
structures. It is essential that the last element of the array is NULL. This is necessary since
the size of the array varies for each module, as it reflects the number of the module’s options.
The daemon iterates the ModuleOption using p ointer arithmetic and stops the iteration as
soon as an element with the value NULL is found.
The first five members of the structure ModuleData are strings providing information about
the module. A meaningful name of the module is stored in name, token contains a minimal
name for the module. The member version informs about the module’s version numb er,
author contains the author’s name. The module description is stored in descr. The mem-
ber options is a pointer to the module’s options stored in the already mentioned array of
ModuleOption. The two members load() and unload() are function pointers. The module
has to implement the two functions accordingly. These functions are responsible for loading
and unloading the module, and are invoked by the daemon. The return type of load() and
unload() is gboolean which is not a standard data type of the GNU C Library. It is a data type
provided by GLib and can either be TRUE or FALSE. For example, the array mod options of
the ModuleOption structure, for a module having the two configuration options disable and
verbose, would be implemented by defining: