libamxd
6.4.1
Data Model Manager
|
Typedefs | |
typedef bool(* | amxd_object_filter_fn_t) (amxd_object_t *const object, int32_t depth, void *priv) |
Definition of object filter function. More... | |
typedef void(* | amxd_object_cb_fn_t) (amxd_object_t *const object, int32_t depth, void *priv) |
Definition of object walk callback function. More... | |
typedef int(* | amxd_mobject_cb_t) (amxd_object_t *object, amxd_object_t *mobject, void *priv) |
Definition of matching object callback function. More... | |
typedef int(* | amxd_instance_cb_t) (amxd_object_t *templ, amxd_object_t *instance, void *priv) |
Functions | |
amxd_status_t | amxd_object_add_object (amxd_object_t *const parent, amxd_object_t *const child) |
Adds an object in the data model tree. More... | |
amxd_object_t * | amxd_object_get_parent (const amxd_object_t *const object) |
Get the parent object. More... | |
amxd_object_t * | amxd_object_get_root (const amxd_object_t *const object) |
Get the data model root. More... | |
amxd_dm_t * | amxd_object_get_dm (const amxd_object_t *const object) |
Get the data model. More... | |
amxd_object_t * | amxd_object_get_child (const amxd_object_t *object, const char *name) |
Get a child of the object. More... | |
amxd_object_t * | amxd_object_get_instance (const amxd_object_t *object, const char *name, uint32_t index) |
Get an instance of the template object. More... | |
amxd_object_t * | amxd_object_get (const amxd_object_t *object, const char *name) |
Get an instance or child of an object. More... | |
amxd_object_t * | amxd_object_findf (amxd_object_t *object, const char *rel_path,...) __attribute__((format(printf |
Find an object in the data model tree, starting from an object. More... | |
amxd_object_t amxd_status_t | amxd_object_resolve_pathf (amxd_object_t *object, amxc_llist_t *paths, const char *rel_path,...) __attribute__((format(printf |
Resolves a search path into a list of matching object paths. More... | |
amxd_object_t amxd_status_t amxd_status_t | amxd_object_resolve_pathf_ext (amxd_object_t *object, bool *key_path, amxc_llist_t *paths, const char *rel_path,...) __attribute__((format(printf |
Resolves a search path into a list of matching object paths. More... | |
amxd_object_t amxd_status_t amxd_status_t char * | amxd_object_get_path (const amxd_object_t *object, const uint32_t flags) |
Get the full path of the object. More... | |
char * | amxd_object_get_rel_path (const amxd_object_t *child, const amxd_object_t *parent, const uint32_t flags) |
Get the relative path of the object. More... | |
bool | amxd_object_is_child_of (const amxd_object_t *const child, const amxd_object_t *const parent) |
Checks if the child object is in the hierarchical tree of the parent object. More... | |
void | amxd_object_hierarchy_walk (amxd_object_t *const object, const amxd_direction_t direction, amxd_object_filter_fn_t filter, amxd_object_cb_fn_t cb, int32_t depth, void *priv) |
Iterates over all objects in the data model tree. More... | |
void | amxd_object_for_all (amxd_object_t *object, const char *rel_spath, amxd_mobject_cb_t fn, void *priv) |
Executes a task for all matching objects in an object tree. More... | |
bool | amxd_object_is_supported (amxd_object_t *object, const char *rel_path) |
Checks if a path is in the supported data model. More... | |
typedef int(* amxd_instance_cb_t) (amxd_object_t *templ, amxd_object_t *instance, void *priv) |
Definition at line 149 of file amxd_object_hierarchy.h.
typedef int(* amxd_mobject_cb_t) (amxd_object_t *object, amxd_object_t *mobject, void *priv) |
Definition of matching object callback function.
Often certain tasks need to be performed for some or all object in an object tree. Using amxd_object_for_all it is easy to iterate over all matching objects and provide an expression filter.
The amxd_object_for_all takes a callback function that must match with this signature. The provided callback is called for each matching object.
object | the starting object |
mobject | the matching object |
priv | Some private data, can be any pointer, as given to amxd_object_for_all |
Definition at line 140 of file amxd_object_hierarchy.h.
typedef void(* amxd_object_cb_fn_t) (amxd_object_t *const object, int32_t depth, void *priv) |
Definition of object walk callback function.
Iterating over all objects in a data model or iterating of a part of the data model is easy when using the function amxd_object_hierarchy_walk.
Each object in the data model tree is passed to a callback function with this signature.
object | the object |
depth | corresponds with the leftover depth as given to the amxd_object_hierarchy_walk. Left over depth = [depth] - [Level from start point] |
priv | Some private data, can be any pointer, as given to amxd_object_hierarchy_walk |
Definition at line 115 of file amxd_object_hierarchy.h.
typedef bool(* amxd_object_filter_fn_t) (amxd_object_t *const object, int32_t depth, void *priv) |
Definition of object filter function.
Iterating over all objects in a data model or iterating of a part of the data model is easy when using the function amxd_object_hierarchy_walk.
Using a filter function certain objects can be filtered out of the result. The filter function must match this singature and will be called for each object. If the filter function returns false, the object is filtered out, including all child or instance objects underneath it.
object | the object |
depth | corresponds with the leftover depth as given to the amxd_object_hierarchy_walk. Left over depth = [depth] - [Level from start point] |
priv | Some private data, can be any pointer, as given to amxd_object_hierarchy_walk |
Definition at line 94 of file amxd_object_hierarchy.h.
amxd_status_t amxd_object_add_object | ( | amxd_object_t *const | parent, |
amxd_object_t *const | child | ||
) |
Adds an object in the data model tree.
This function defines the parent - child relationship between objects.
The object type of the child must be amxd_object_singleton or amxd_object_template.
The object type of the parent can be any type. The parent object must be in a data model tree or when not, it must be of the type amxd_object_mib
An object can only have one parent object. The name of the child object must be unique in the context of the parent object. A parent can not have two child objects with the same name.
Adding an object to the root of the data model can be done using amxd_dm_add_root_object
parent | the parent object |
child | the child object |
Definition at line 207 of file amxd_object.c.
amxd_object_t* amxd_object_findf | ( | amxd_object_t * | object, |
const char * | rel_path, | ||
... | |||
) |
Find an object in the data model tree, starting from an object.
Using a starting point, searches the data model object tree. The path is relative to the starting point object, The path can be a search path.
A search path is a path that contains search criteria for addressing a set of multi-instance objects. A search path may contain a search expression or wildcard.
Wildcard and search criteria can only be specified on instance objects.
Spaces in the path are ingored.
Indexes or object names can be used to address instance objects.
object | the start object pointer |
rel_path | the relative object path, supports printf format can be a search path. |
void amxd_object_for_all | ( | amxd_object_t * | object, |
const char * | rel_spath, | ||
amxd_mobject_cb_t | fn, | ||
void * | priv | ||
) |
Executes a task for all matching objects in an object tree.
Loops over all objects in an object tree that are matching the expressions and calls a callback function for each matching object.
For each object that is matching the expression given in the search path, the callback function is called. The callback function takes three arguments
object | pointer to the start object |
rel_spath | search path, used to match the objects, is relative to the start object |
fn | the task calback function |
priv | private data pointer, is passed to the callback function as is |
Definition at line 554 of file amxd_object_hierarchy.c.
amxd_object_t* amxd_object_get | ( | const amxd_object_t * | object, |
const char * | name | ||
) |
Get an instance or child of an object.
This function searches through the instance list and child list for a matching object.
If the object pointer given is pointing to a template object the instances are searched first. If the name starts with a digit (0 - 9), it is asumed that the name contains an index, and the search on the instances is done using the indexes. If no instance is found, the search continues in the list of child objects.
For all other object types only the list of childeren is searched.
object | the object pointer |
name | the child or instance name |
Definition at line 373 of file amxd_object_hierarchy.c.
amxd_object_t* amxd_object_get_child | ( | const amxd_object_t * | object, |
const char * | name | ||
) |
Get a child of the object.
Searches in the list of childeren for a child with the given name.
object | the object pointer |
name | the child name |
Definition at line 299 of file amxd_object_hierarchy.c.
amxd_dm_t* amxd_object_get_dm | ( | const amxd_object_t *const | object | ) |
Get the data model.
Gets the data model structure. See also amxd_dm_init or amxd_dm_new
object | the object pointer |
Definition at line 265 of file amxd_object_hierarchy.c.
amxd_object_t* amxd_object_get_instance | ( | const amxd_object_t * | object, |
const char * | name, | ||
uint32_t | index | ||
) |
Get an instance of the template object.
Searches in the list of instances for an instance with the given name or index
This function only works on tempalte objects, for all other object types this function always returns a NULL pointer.
Calling this function on a singleton object has not effect and a NULL pointer is returned.
object | the object pointer |
name | the instance name or NULL |
index | the instance index or NULL |
Definition at line 327 of file amxd_object_hierarchy.c.
amxd_object_t* amxd_object_get_parent | ( | const amxd_object_t *const | object | ) |
Get the parent object.
All objects in the data model tree have a parent.
The following objects will not have a parent object:
If there is a need to go up multiple-levels in the hierarchical tree, this function can be called multiple times or as an alternative amxd_object_findf can be used.
object | the object pointer |
Definition at line 227 of file amxd_object_hierarchy.c.
amxd_object_t amxd_status_t amxd_status_t char* amxd_object_get_path | ( | const amxd_object_t * | object, |
const uint32_t | flags | ||
) |
Get the full path of the object.
For instances the name or index is used depending on the flags given, AMXD_OBJECT_INDEXED or AMXD_OBJECT_NAMED, these flags are mutually exlusive. If both are given the index path is returned.
To make clear that a part of the path is refering to an instance object, the flag AMXD_OBJECT_EXTENDED can be used to put the name or index of the instance object between square brackets.
When AMXD_OBJECT_REGEXP is used in the flags the returned path is a regular expression(all dots are escaped).
When AMXD_OBJECT_TERMINATE is used in the flags the object path is terminated with a dot.
When AMXD_OBJECT_SUPPORTED is used in the flags all instance are replaced with the placeholder '{i}'. The placeholder '{i}' is automatically added behind each multi-instance object in the path.
object | the object pointer |
flags | bit map of AMXD_OBJECT_INDEXED, AMXD_OBJECT_NAMED, AMXD_OBJECT_EXTENDED, AMXD_OBJECT_REGEXP, AMXD_OBJECT_TERMINATE, AMXD_OBJECT_SUPPORTED separated with '|' |
Definition at line 483 of file amxd_object_hierarchy.c.
char* amxd_object_get_rel_path | ( | const amxd_object_t * | child, |
const amxd_object_t * | parent, | ||
const uint32_t | flags | ||
) |
Get the relative path of the object.
For instances the name or index is used depending on the flags given, AMXD_OBJECT_INDEXED or AMXD_OBJECT_NAMED, these flags are mutually exlusive. If both are given the index path is returned.
To make clear that a part of the path is refering to an instance object, the flag AMXD_OBJECT_EXTENDED can be used to put the name or index of the instance object between square brackets.
When AMXD_OBJECT_REGEXP is used in the flags the returned path is a regular expression(all dots are escaped).
When AMXD_OBJECT_TERMINATE is used in the flags the object path is terminated with a dot.
When AMXD_OBJECT_SUPPORTED is used in the flags all instance are replaced with the placeholder '{i}'. The placeholder '{i}' is automatically added behind each multi-instance object in the path.
The path returned is relative to the given parent object. The parent object must be in the upper hierarchy of the child object.
If the provided parent is not in the upper hierarchy of the given child object the function fails and returns a NULL pointer.
child | the object pointer for which a relative path is requested |
parent | the object pointer of the "parent" object. |
flags | bit map of AMXD_OBJECT_INDEXED, AMXD_OBJECT_NAMED, AMXD_OBJECT_EXTENDED, AMXD_OBJECT_REGEXP, AMXD_OBJECT_TERMINATE, AMXD_OBJECT_SUPPORTED separated with '|' |
Definition at line 496 of file amxd_object_hierarchy.c.
amxd_object_t* amxd_object_get_root | ( | const amxd_object_t *const | object | ) |
Get the data model root.
The data model root is the top most object in the data model tree. This object does not have a parent object and does not have a name. The object type of the root object is amxd_object_root.
You can add objects to the root object using amxd_dm_add_root_object.
Objects that are not added to the data model object hierarchy, does not have a root object. See amxd_object_get_parent
object | the object pointer |
Definition at line 244 of file amxd_object_hierarchy.c.
void amxd_object_hierarchy_walk | ( | amxd_object_t *const | object, |
const amxd_direction_t | direction, | ||
amxd_object_filter_fn_t | filter, | ||
amxd_object_cb_fn_t | cb, | ||
int32_t | depth, | ||
void * | priv | ||
) |
Iterates over all objects in the data model tree.
Starting from the specified object, iterates over all the objects in a certain direction (up or down). A filter function can be specified (see amxd_object_filter_fn_t).
For each object encountered the callback function is called. (see amxd_object_cb_fn_t).
A depth can be specified, whenever the depth reaches 0, iteration over the data model object hierarchy is stopped.
object | the object pointer, this is the starting object. |
direction | can be one of amxd_direction_up or amxd_direction_down |
filter | filter function, when the filter function returns false the object is not matching and will not be provided to the callback function |
cb | the callback function, called for each matching object |
depth | the maximum depth |
priv | pointer to any data, is passed to the filter (if given) function and the callback function |
Definition at line 535 of file amxd_object_hierarchy.c.
bool amxd_object_is_child_of | ( | const amxd_object_t *const | child, |
const amxd_object_t *const | parent | ||
) |
Checks if the child object is in the hierarchical tree of the parent object.
child | the object pointer for which a relative path is requested |
parent | the object pointer of the "parent" object. |
Definition at line 515 of file amxd_object_hierarchy.c.
bool amxd_object_is_supported | ( | amxd_object_t * | object, |
const char * | rel_path | ||
) |
Checks if a path is in the supported data model.
This function checks if a given path is in the supported data model. It does not verify if the instances exist.
object | an object pointer, the starting point. |
rel_path | search path, used to match the instances |
Definition at line 585 of file amxd_object_hierarchy.c.
amxd_object_t amxd_status_t amxd_object_resolve_pathf | ( | amxd_object_t * | object, |
amxc_llist_t * | paths, | ||
const char * | rel_path, | ||
... | |||
) |
Resolves a search path into a list of matching object paths.
Using a starting point, searches the data model object tree. The path is relative to the starting point object, The path can be a search path.
A search path is a path that contains search criteria for addressing a set of multi-instance objects. A search path may contain a search expression or wildcard.
Wildcard and search criteria can only be specified on instance objects.
Spaces in the path are ingored.
Indexes or object names can be used to address instance objects.
object | the start object pointer |
paths | an initialized linked list, the matching object paths are added to this list |
rel_path | the relative (search) path. Supports printf formatting |
amxd_object_t amxd_status_t amxd_status_t amxd_object_resolve_pathf_ext | ( | amxd_object_t * | object, |
bool * | key_path, | ||
amxc_llist_t * | paths, | ||
const char * | rel_path, | ||
... | |||
) |
Resolves a search path into a list of matching object paths.
Using a starting point, searches the data model object tree. The path is relative to the starting point object, The path can be a search path.
A search path is a path that contains search criteria for addressing a set of multi-instance objects. A search path may contain a search expression or wildcard.
Wildcard and search criteria can only be specified on instance objects.
Spaces in the path are ingored.
Indexes or object names can be used to address instance objects.
object | the start object pointer |
key_path | will be set to true when that paths are key paths |
paths | an initialized linked list, the matching object paths are added to this list |
rel_path | the relative (search) path. Supports printf formatting |