libamxo
4.3.4
Object Definition Language (ODL) parsing
|
Modules | |
Function Table Resolver API | |
Import Resolver API | |
Macros | |
#define | AMXO_FUNC(x) ((amxo_fn_ptr_t) x) |
Function ponter caster macro. More... | |
Functions | |
int | amxo_register_resolver (const char *name, amxo_resolver_t *resolver) |
Registers a function resolver. More... | |
int | amxo_unregister_resolver (const char *name) |
Unregisters a function resolver. More... | |
amxc_htable_t * | amxo_parser_claim_resolver_data (amxo_parser_t *parser, const char *resolver_name) |
Fetches resolver specific data for a parser instance. More... | |
amxc_htable_t * | amxo_parser_get_resolver_data (amxo_parser_t *parser, const char *resolver_name) |
Gets the resolver specific parser data. More... | |
void | amxo_parser_remove_resolver_data (amxo_parser_t *parser, const char *resolver_name) |
Removes the resolver specific parser data. More... | |
The odl parser can resolve functions for a data model functions. By default the odl parser supports the following function resolvers:
In the odl file, the odl parser can be instructed to use a specific function resolver. After each function definition a resolver directive can be placed. Such a resolver directive starts with "<!" and ends with "!>".
In between the name of the resolver and optionally extra resolver data can be placed. The resolver data is specific for each resolver, please read the documentation of the resolver itself.
Default resolver names:
If no resolver directive is specified, the automatic resolver is used.
If a resolver directive is specified, the resolver is used, no other resolvers are used.
If a data model can not be resolved, the odl parser continues and the data model method exists, but will not have an implementation.
To make it possible for the odl parser to use the function table resolver, the function table must be supplied with function pointers, prior to start parsing an odl file.
To supply the function pointers use amxo_resolver_ftab_add
The function name is optional, if not given the name of the function specified in the odl file is used.
Search a function implementation for the data model method "say" in the function table resolver, with name "say.
Search a function implementation for the data model method "say" in the function table resolver, with name "dump".
In this example, a "say" data model method is defined in the odl file under the object "Greeter". The odl parser can automatically bind a C implementation to this data model method by using the function table resolver.
#define AMXO_FUNC | ( | x | ) | ((amxo_fn_ptr_t) x) |
Function ponter caster macro.
x | C function pointer |
Definition at line 80 of file amxo_types.h.
amxc_htable_t* amxo_parser_claim_resolver_data | ( | amxo_parser_t * | parser, |
const char * | resolver_name | ||
) |
Fetches resolver specific data for a parser instance.
Allocates or returns the resolver specific data for the parser instance. Each parser instance can keep resolver specific data. This function is typically called in the API functions provided by the resolver.
When there already was a data table for the function resolver available, due to a previous call to this function, that pointer is returned.
A hash table is allocated, the data stored in this table is up to the function resolver implementation.
parser | the odl parser instance |
resolver_name | name of the resolver |
Definition at line 167 of file amxo_resolver_mngr.c.
amxc_htable_t* amxo_parser_get_resolver_data | ( | amxo_parser_t * | parser, |
const char * | resolver_name | ||
) |
Gets the resolver specific parser data.
Returns the function resolver specific data for the given parser. If no such data is available it will return a NULL pointer
This function will not allocate a table if there is no available. Use amxo_parser_claim_resolver_data to allocate a resolver data table.
parser | the odl parser instance |
resolver_name | name of the resolver |
Definition at line 197 of file amxo_resolver_mngr.c.
void amxo_parser_remove_resolver_data | ( | amxo_parser_t * | parser, |
const char * | resolver_name | ||
) |
Removes the resolver specific parser data.
Removes the resolver specific data. If the resolver allocated memory for the resolver specific data it is the responsibility of the resolver to free the allocated memory for the data before removing it from the parser context
parser | the odl parser instance |
resolver_name | name of the resolver |
Definition at line 216 of file amxo_resolver_mngr.c.
int amxo_register_resolver | ( | const char * | name, |
amxo_resolver_t * | resolver | ||
) |
Registers a function resolver.
The odl parser provides already two function resolvers. In most cases this is sufficient. Extra resolvers can be registered using this function.
The resolver must at least provide the "resolve" method, the other two are optional ("get" and "clean").
The "resolve" method is called during the parsing of odl files. The "get" method is called when a parser is initializing to fetch all default configuration options for the function resolver. The "clean" method is called when parsing is done. In this method the resolver can clean-up stuff that was allocated during function resolving.
A function resolver is typically implemented in a library and can provide extra API functions. The default "ftab" and "import" resolvers are providing extra API functions see amxo_resolver_ftab_add, amxo_resolver_ftab_remove, amxo_resolver_ftab_clear, amxo_resolver_import_open and amxo_resolver_import_close_all. A custom function resolver can do the same, so it is easier for an application developer to use your function resolver.
The name of the resolver must be unique.
name | of the resolver, must match the name used in the odl files |
resolver | the resolver implementation function table |
Definition at line 137 of file amxo_resolver_mngr.c.
int amxo_unregister_resolver | ( | const char * | name | ) |
Unregisters a function resolver.
Removes the function resolver. After removing the resolver can not be used in any parsing anymore until it is re-added.
It is not recommended to unregister a function resolver during parsing, for example in parser hooks.
name | of the resolver |
Definition at line 153 of file amxo_resolver_mngr.c.