modsup.c File Reference

Module loading and support. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include "assert.h"
#include "main.h"
#include "modsup.h"
#include "error.h"
#include "chromo.h"
#include "gettext.h"

Functions

moduleoptionoption_new (moduleoption *opt, char *name, char *content)
 Inserts a new module option to the beginning of the moduleoption linked list.
moduleoptionoption_find (moduleoption *opt, char *name)
 Finds an option by name.
int option_int (moduleoption *opt, char *name)
 Finds an integer option by name.
char * option_str (moduleoption *opt, char *name)
 Finds a string option by name.
void option_free (moduleoption *opt)
 Free a linked list of options.
precalcfuncprecalc_new (init_f func)
 Register a new precalc function.
int precalc_call ()
 Call all registered precalc functions.
fitnessfuncfitness_new (char *name, int weight, int man, fitness_f func)
 Registers a new fitness function.
int fitness_request_chromo (fitnessfunc *fitness, char *restype)
 Request a chromosome to be passed to a fitness function.
int fitness_request_ext (fitnessfunc *fitness, char *contype, char *vartype)
 Request an extension to be passed to a fitness function.
int fitness_request_slist (fitnessfunc *fitness, char *vartype)
 Request a slist to be passed to a fitness function.
void table_fitness (table *tab)
 Assign a fitness to a table by calling all fitness functions.
modulehandlerhandler_tup_new (char *restriction, handler_tup_f handler)
 Registers a new tuple restriction handler.
modulehandlerhandler_res_new (char *restype, char *restriction, handler_res_f handler)
 Registers a new resource restriction handler.
modulehandlerhandler_find (modulehandler *cur, resourcetype *restype, char *restriction)
 Find a module restriction handler.
int handler_res_call (resource *res, char *restriction, char *content)
 Call a resource restriction handler.
int handler_tup_call (tupleinfo *tuple, char *restriction, char *content)
 Call a tuple restriction handler.
modulelistmodulelist_new ()
 Allocates a new modulelist structure.
char * module_filename_combine (char *prefix, char *name)
 Combines the base module name with module path and extension.
modulemodule_load (char *name, moduleoption *opt)
 Loads a module. After the module is loaded, module_init() function is called.

Variables

static modulelistmod_list = NULL
 Linked list of all registered modules.
static modulehandlermod_handler = NULL
 Linked list of all registered restriction handlers.
int mod_fitnessnum = 0
 Number of all registered fitness functions.
fitnessfuncmod_fitnessfunc = NULL
 Linked list of all registered fitness functions.
char * mod_modulepath = HAVE_MODULE_PATH
 Path to fitness and export modules.
static precalcfuncmod_precalc = NULL
 Linked list of all registered precalc functions.
static resourcetype mod_eventtype = {type: EVENT_TYPE }
 Special resource type for events. It is used only by restriction handlers.
static resourcetype mod_anytype = {type: ANY_TYPE }
 Special resource type that matches any type and is used only by restriction handlers.


Detailed Description

Module loading and support.


Function Documentation

fitnessfunc* fitness_new ( char *  name,
int  weight,
int  man,
fitness_f  func 
)

Registers a new fitness function.

Parameters:
name Description of this fitness function.
weight Weight value for this function.
man Set to 1 if this is a mandatory weight and 0 if not.
func Pointer to the fitness function.
Returns:
Pointer to the fitnessfunc struct or NULL on error.

int fitness_request_chromo ( fitnessfunc fitness,
char *  restype 
)

Request a chromosome to be passed to a fitness function.

Parameters:
fitness Pointer to the fitnessfunc structure.
restype Resource type of the chromosome to be passed to the fitness function.
Returns:
0 on success or -1 on error.

int fitness_request_ext ( fitnessfunc fitness,
char *  contype,
char *  vartype 
)

Request an extension to be passed to a fitness function.

Parameters:
fitness Pointer to the fitnessfunc structure.
contype Name of the constant resource.
vartype Name of the variable resource.
Returns:
0 on success or -1 on error.

int fitness_request_slist ( fitnessfunc fitness,
char *  vartype 
)

Request a slist to be passed to a fitness function.

Parameters:
fitness Pointer to the fitnessfunc structure.
vartype Variable resource ID. fitness function.
Returns:
0 on success or -1 on error.

modulehandler* handler_find ( modulehandler cur,
resourcetype restype,
char *  restriction 
)

Find a module restriction handler.

Parameters:
cur Pointer to the linked list of modulehandler structs.
restype Resource type for this handler (set to mod_eventtype to search for tuple restrictions.
restriction Name of the restriction.
Returns:
Pointer to the modulehandler struct or NULL if the handler was not found.

int handler_res_call ( resource res,
char *  restriction,
char *  content 
)

Call a resource restriction handler.

Parameters:
res Pointer to the resource for this restriction.
restriction Type of this restriction.
content Content of this restriction.
Returns:
0 if all handlers were successful, 1 if some or all handlers returned errors, 2 if no handlers were found.

modulehandler* handler_res_new ( char *  restype,
char *  restriction,
handler_res_f  handler 
)

Registers a new resource restriction handler.

Parameters:
restype Name of the resource type. If equal to NULL then handler will be registered for all resource types.
restriction Type of the restriction.
handler Pointer to the restriction handler function.
Returns:
Pointer to the modulehandler struct or NULL on error.

int handler_tup_call ( tupleinfo tuple,
char *  restriction,
char *  content 
)

Call a tuple restriction handler.

Parameters:
tuple Pointer to the tuple for this restriction.
restriction Type of this restriction.
content Content of this restriction.
Returns:
0 if all handlers were successful, 1 if some or all handlers returned errors, 2 if no handlers were found.

modulehandler* handler_tup_new ( char *  restriction,
handler_tup_f  handler 
)

Registers a new tuple restriction handler.

Parameters:
restriction Type of the restriction.
handler Pointer to the restriction handler function.
Returns:
Pointer to the modulehandler struct or NULL on error.

char* module_filename_combine ( char *  prefix,
char *  name 
)

Combines the base module name with module path and extension.

If file name has no extension the default shared library extension for this system will be appended.

If file name has a ".so" extension this extension will be replaced with the default shared library extension to remain backward compatible.

Parameters:
name File name of the module
prefix Module prefix (for example "export_" for export modules)
Returns:
Absolute path to the module with proper extension. Must be freed after use. Returns NULL on memory allocation error.

module* module_load ( char *  name,
moduleoption opt 
)

Loads a module. After the module is loaded, module_init() function is called.

See also:
module_filename_combine()
Parameters:
name File name of the module (example: "timeplace").
opt Linked list of options for this module.
Returns:
Pointer to the module structure of the loaded module or NULL on error.

modulelist* modulelist_new (  ) 

Allocates a new modulelist structure.

Returns:
Pointer to modulelist struct or NULL on error.

moduleoption* option_find ( moduleoption opt,
char *  name 
)

Finds an option by name.

If there many options with the same name in the linked list, you can find them all with the following loop:

 moduleoption *result;

 // "list" is the pointer to the linked list to search
 result=option_find(list, "name");
 while(result!=NULL) {
        // do something with "result"
        result=option_find(result->next, "name");
 }

Parameters:
opt Pointer to the first element in the linked list.
name Name of the option to find.
Returns:
Pointer to the moduleoption struct or NULL if not found.

void option_free ( moduleoption opt  ) 

Free a linked list of options.

Parameters:
opt Pointer to the first element in the linked list.

int option_int ( moduleoption opt,
char *  name 
)

Finds an integer option by name.

Note that if more than one option with the same name is defined then this function returns the value of the option that was added last to the linked list by option_new()

See also:
option_find()
Parameters:
opt Pointer to the first element in the linked list.
name Name of the option to find.
Returns:
Integer value of the module option or INT_MIN if not found or if the module option does not contain an integer value.

moduleoption* option_new ( moduleoption opt,
char *  name,
char *  content 
)

Inserts a new module option to the beginning of the moduleoption linked list.

Parameters:
opt Pointer to the first element in the linked list (can be NULL).
name Name of the option.
content Content of the option.
Returns:
Pointer to the allocated moduleoption struct or NULL on error.

char* option_str ( moduleoption opt,
char *  name 
)

Finds a string option by name.

Note that if more than one option with the same name is defined then this function returns the value of the option that was added last to the linked list by option_new()

See also:
option_find()
Parameters:
opt Pointer to the first element in the linked list.
name Name of the option to find.
Returns:
Content of the module option or NULL if not found.

int precalc_call (  ) 

Call all registered precalc functions.

Returns:
0 on success and -1 on error.

precalcfunc* precalc_new ( init_f  func  ) 

Register a new precalc function.

Parameters:
func Pointer to the precalc function.
Returns:
Pointer to the new precalcfunc struct or NULL on error.

void table_fitness ( table tab  ) 

Assign a fitness to a table by calling all fitness functions.

Parameters:
tab Pointer to the table to be fitnessd.


Variable Documentation

char* mod_modulepath = HAVE_MODULE_PATH

Path to fitness and export modules.

Defaults to the location where modules were installed by "make install".


Generated on Tue Jul 3 13:23:36 2007 for Tablix by  doxygen 1.5.2