libamxd  6.4.1
Data Model Manager
Hierarchical Tree
Collaboration diagram for Hierarchical Tree:

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_tamxd_object_get_parent (const amxd_object_t *const object)
 Get the parent object. More...
 
amxd_object_tamxd_object_get_root (const amxd_object_t *const object)
 Get the data model root. More...
 
amxd_dm_tamxd_object_get_dm (const amxd_object_t *const object)
 Get the data model. More...
 
amxd_object_tamxd_object_get_child (const amxd_object_t *object, const char *name)
 Get a child of the object. More...
 
amxd_object_tamxd_object_get_instance (const amxd_object_t *object, const char *name, uint32_t index)
 Get an instance of the template object. More...
 
amxd_object_tamxd_object_get (const amxd_object_t *object, const char *name)
 Get an instance or child of an object. More...
 
amxd_object_tamxd_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...
 

Detailed Description

Typedef Documentation

◆ amxd_instance_cb_t

typedef int(* amxd_instance_cb_t) (amxd_object_t *templ, amxd_object_t *instance, void *priv)
Deprecated:
Use amxd_mobject_cb_t

Definition at line 149 of file amxd_object_hierarchy.h.

◆ amxd_mobject_cb_t

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.

Parameters
objectthe starting object
mobjectthe matching object
privSome private data, can be any pointer, as given to amxd_object_for_all
Returns
true when object must be include, false when it must be filtered out.

Definition at line 140 of file amxd_object_hierarchy.h.

◆ amxd_object_cb_fn_t

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.

Parameters
objectthe object
depthcorresponds with the leftover depth as given to the amxd_object_hierarchy_walk. Left over depth = [depth] - [Level from start point]
privSome private data, can be any pointer, as given to amxd_object_hierarchy_walk

Definition at line 115 of file amxd_object_hierarchy.h.

◆ amxd_object_filter_fn_t

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.

Parameters
objectthe object
depthcorresponds with the leftover depth as given to the amxd_object_hierarchy_walk. Left over depth = [depth] - [Level from start point]
privSome private data, can be any pointer, as given to amxd_object_hierarchy_walk
Returns
true when object must be include, false when it must be filtered out.

Definition at line 94 of file amxd_object_hierarchy.h.

Function Documentation

◆ amxd_object_add_object()

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

Parameters
parentthe parent object
childthe child object
Returns
amxd_status_ok when the object is added to the data model tree, or another status code when failed to add the object

Definition at line 207 of file amxd_object.c.

208  {
210 
211  when_null(parent, exit);
212  when_null(child, exit);
213  when_true(parent == child, exit);
214 
215  when_true_status(child->it.llist == &parent->objects,
216  exit,
217  retval = amxd_status_ok);
218  when_not_null(child->it.llist, exit);
219 
220  when_true_status(!amxd_object_type_is_valid(child->type),
221  exit,
222  retval = amxd_status_invalid_type);
223  when_true_status(child->type == amxd_object_mib,
224  exit,
225  retval = amxd_status_invalid_type);
226  when_not_null_status(amxd_object_get_child(parent, child->name),
227  exit,
228  retval = amxd_status_duplicate);
229 
230  when_failed(amxc_llist_append(&parent->objects, &child->it), exit);
231  amxd_dm_event("dm:object-added", child, NULL, false);
232 
233  retval = amxd_status_ok;
234 
235 exit:
236  return retval;
237 }
void PRIVATE amxd_dm_event(const char *signal, const amxd_object_t *const object, amxc_var_t *const data, bool trigger)
Definition: amxd_dm_priv.c:550
static bool amxd_object_type_is_valid(const amxd_object_type_t type)
Definition: amxd_object.c:86
enum _amxd_status amxd_status_t
@ amxd_status_invalid_type
Definition: amxd_types.h:90
@ amxd_status_ok
Definition: amxd_types.h:78
@ amxd_status_unknown_error
Definition: amxd_types.h:79
@ amxd_status_duplicate
Definition: amxd_types.h:91
@ amxd_object_mib
Definition: amxd_types.h:188
amxd_object_t * amxd_object_get_child(const amxd_object_t *object, const char *name)
Get a child of the object.
amxd_object_type_t type
Definition: amxd_types.h:236
amxc_llist_t objects
Definition: amxd_types.h:243
char * name
Definition: amxd_types.h:238
amxc_llist_it_t it
Definition: amxd_types.h:230

◆ amxd_object_findf()

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.

Note
If a search path with expressions or wildcards is used and multiple objects match the search path, this function will fail. To get a list of all matching objects use amxd_object_resolve_pathf
Parameters
objectthe start object pointer
rel_paththe relative object path, supports printf format can be a search path.
Returns
Returns the object pointer of the found object or NULL if no matching object is found or mulitple matching objects are found.

◆ amxd_object_for_all()

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

  1. The starting object pointer
  2. The matching object pointer
  3. The private data pointer
Parameters
objectpointer to the start object
rel_spathsearch path, used to match the objects, is relative to the start object
fnthe task calback function
privprivate data pointer, is passed to the callback function as is

Definition at line 554 of file amxd_object_hierarchy.c.

557  {
558  amxc_llist_t paths;
559  amxd_dm_t* dm = NULL;
560 
561  amxc_llist_init(&paths);
562 
563  when_null(object, exit);
564  when_true(amxd_object_is_base(object), exit);
565  when_null(fn, exit);
566  when_str_empty(rel_spath, exit);
567 
568  dm = amxd_object_get_dm(object);
569 
570  amxd_object_resolve_pathf(object, &paths, "%s", rel_spath);
571 
572  amxc_llist_for_each(it, (&paths)) {
573  amxc_string_t* path = amxc_string_from_llist_it(it);
574  amxd_object_t* mobject = amxd_dm_findf(dm, "%s", amxc_string_get(path, 0));
575  if(mobject != NULL) {
576  fn(object, mobject, priv);
577  }
578  }
579 
580 exit:
581  amxc_llist_clean(&paths, amxc_string_list_it_free);
582  return;
583 }
amxd_object_t * amxd_dm_findf(amxd_dm_t *const dm, const char *abs_path,...) __attribute__((format(printf
bool PRIVATE amxd_object_is_base(const amxd_object_t *const object)
Definition: amxd_dm_priv.c:504
amxd_status_t amxd_object_resolve_pathf(amxd_object_t *object, amxc_llist_t *paths, const char *rel_path,...)
amxd_dm_t * amxd_object_get_dm(const amxd_object_t *const object)
Get the data model.
static amxd_dm_t dm

◆ amxd_object_get()

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.

Parameters
objectthe object pointer
namethe child or instance name
Returns
Returns the object pointer of the child or instance matching the name or NULL if there is no child or instance object with the given name.
See also
amxd_object_get_child, amxd_object_get_instance

Definition at line 373 of file amxd_object_hierarchy.c.

373  {
374  amxd_object_t* result = NULL;
375  when_str_empty(name, exit);
376 
378  if(isdigit(name[0]) == 0) {
379  result = amxd_object_get_instance(object, name, 0);
380  } else {
381  result = amxd_object_get_instance(object, NULL, atoi(name));
382  }
383  }
384  if(result == NULL) {
385  result = amxd_object_get_child(object, name);
386  }
387 
388 exit:
389  return result;
390 }
@ amxd_object_template
Definition: amxd_types.h:183
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.
static amxd_object_type_t amxd_object_get_type(const amxd_object_t *const object)
Returns the object type.
Definition: amxd_object.h:586

◆ amxd_object_get_child()

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.

Note
If this function is called using a template object pointer it is not searching through the instances, use amxd_object_get_instance to find an instance or amxd_object_get
Parameters
objectthe object pointer
namethe child name
Returns
Returns the object pointer of the child matching the name or NULL if there is no child object with the given name.

Definition at line 299 of file amxd_object_hierarchy.c.

300  {
301  amxd_object_t* result = NULL;
302  int length = 0;
303  when_null(object, exit);
304  when_str_empty(name, exit);
305 
306  length = strlen(name);
307  if(name[length - 1] == '.') {
308  length--;
309  }
310 
311  amxc_llist_for_each(it, (&object->objects)) {
312  const char* n = NULL;
313  int nlen = 0;
314  result = amxc_llist_it_get_data(it, amxd_object_t, it);
316  nlen = strlen(n);
317  if((nlen == length) && (strncmp(n, name, length) == 0)) {
318  break;
319  }
320  result = NULL;
321  }
322 
323 exit:
324  return result;
325 }
#define AMXD_OBJECT_NAMED
Name and path format flag - default behavior, use name for instance objects.
Definition: amxd_object.h:164
const char * amxd_object_get_name(const amxd_object_t *const object, const uint32_t flags)
Get the name of the object (or index as a string for instance objects)
Definition: amxd_object.c:239

◆ amxd_object_get_dm()

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

Parameters
objectthe object pointer
Returns
Returns the data model pointer or NULL if the object is not in a data model object tree.

Definition at line 265 of file amxd_object_hierarchy.c.

265  {
266  amxd_object_t* parent = NULL;
267  amxd_dm_t* dm = NULL;
268 
269  when_null(object, exit);
270  when_true(amxd_object_is_base(object), exit);
271 
272  if(amxd_object_get_type(object) == amxd_object_mib) {
273  when_null(object->it.llist, exit);
274  dm = amxc_container_of(object->it.llist, amxd_dm_t, mibs);
275  goto exit;
276  } else if(amxd_object_get_type(object) == amxd_object_root) {
277  dm = amxc_container_of(object, amxd_dm_t, object);
278  goto exit;
279  }
280 
281  parent = amxd_object_get_parent(object);
282  while(parent != NULL &&
283  parent->type != amxd_object_mib &&
284  parent->type != amxd_object_root) {
285  parent = amxd_object_get_parent(parent);
286  }
287 
288  if(amxd_object_get_type(parent) == amxd_object_mib) {
289  when_null(parent->it.llist, exit);
290  dm = amxc_container_of(parent->it.llist, amxd_dm_t, mibs);
291  } else if(amxd_object_get_type(parent) == amxd_object_root) {
292  dm = amxc_container_of(parent, amxd_dm_t, object);
293  }
294 
295 exit:
296  return dm;
297 }
@ amxd_object_root
Definition: amxd_types.h:178
amxd_object_t * amxd_object_get_parent(const amxd_object_t *const object)
Get the parent object.

◆ amxd_object_get_instance()

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.

Note
It is not needed to provide a name and an index. Both are optional, but at least one should be given. The name can be a NULL pointer then the search is done using the index. The index can be 0, then the search is done using the name. If both are given the name is checked first.

Calling this function on a singleton object has not effect and a NULL pointer is returned.

Parameters
objectthe object pointer
namethe instance name or NULL
indexthe instance index or NULL
Returns
Returns the object pointer of the child matching the name or index, NULL if there is no instance object with the given name or index.
See also
amxd_object_get_instance, amxd_object_get

Definition at line 327 of file amxd_object_hierarchy.c.

329  {
330  amxd_object_t* result = NULL;
331  int length = 0;
332  int offset = 0;
333  when_null(object, exit);
334 
335  if((name != NULL) && (name[0] != 0)) {
336  amxd_param_t* alias_param = amxd_object_get_param_def(object, "Alias");
337  length = strlen(name);
338  if(alias_param == NULL) {
339  if(name[length - 1] == '.') {
340  length--;
341  }
342  if(name[0] == '[') {
343  length = strlen(name);
344  length -= 2;
345  offset = 1;
346  }
347  }
348  }
349 
350  amxc_llist_for_each(it, (&object->instances)) {
351  const char* n = NULL;
352  result = amxc_llist_it_get_data(it, amxd_object_t, it);
354  if(index != 0) {
355  if(result->index == index) {
356  break;
357  }
358  } else {
359  if((name != NULL) && (name[0] != 0)) {
360  int nlen = strlen(n);
361  if((nlen == length) && (strncmp(n, name + offset, length) == 0)) {
362  break;
363  }
364  }
365  }
366  result = NULL;
367  }
368 
369 exit:
370  return result;
371 }
amxd_param_t * amxd_object_get_param_def(const amxd_object_t *const object, const char *name)
Gets a parameter definition from an object.
uint32_t index
Definition: amxd_types.h:240
amxc_llist_t instances
Definition: amxd_types.h:244

◆ amxd_object_get_parent()

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.

// assume that curobj = "Ethernet.Interace.1"
// going up to levels can be done like:
// alternativly use amxd_object_findf
amxd_object_t *pp = amxd_object_findf(curobj, "^.^.");
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.
Parameters
objectthe object pointer
Returns
Returns the object pointer of the parent object or NULL if the object does not have a parent

Definition at line 227 of file amxd_object_hierarchy.c.

227  {
228  amxd_object_t* parent = NULL;
229  when_null(object, exit);
230  when_true(amxd_object_is_base(object), exit);
231  when_true(object->type == amxd_object_mib, exit);
232  when_null(object->it.llist, exit);
233 
234  if(object->type == amxd_object_instance) {
235  parent = amxc_container_of(object->it.llist, amxd_object_t, instances);
236  } else {
237  parent = amxc_container_of(object->it.llist, amxd_object_t, objects);
238  }
239 
240 exit:
241  return parent;
242 }
@ amxd_object_instance
Definition: amxd_types.h:186

◆ amxd_object_get_path()

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.

Note
This function allocates memory to store the full path. The memory must be freed using "free" if not needed anymore.
Parameters
objectthe object pointer
flagsbit map of AMXD_OBJECT_INDEXED, AMXD_OBJECT_NAMED, AMXD_OBJECT_EXTENDED, AMXD_OBJECT_REGEXP, AMXD_OBJECT_TERMINATE, AMXD_OBJECT_SUPPORTED separated with '|'
Returns
Returns the full path of the object or NULL.

Definition at line 483 of file amxd_object_hierarchy.c.

484  {
485  char* path = NULL;
486  when_null(object, exit);
487  when_true(amxd_object_is_base(object), exit);
488  when_null(amxd_object_get_name(object, flags), exit);
489 
490  path = amxd_object_build_path(object, NULL, flags);
491 
492 exit:
493  return path;
494 }
static char * amxd_object_build_path(const amxd_object_t *object, const amxd_object_t *stop, const uint32_t flags)

◆ amxd_object_get_rel_path()

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.

Note
This function allocates memory to store the full path. The memory must be freed using "free" if not needed anymore.
Parameters
childthe object pointer for which a relative path is requested
parentthe object pointer of the "parent" object.
flagsbit map of AMXD_OBJECT_INDEXED, AMXD_OBJECT_NAMED, AMXD_OBJECT_EXTENDED, AMXD_OBJECT_REGEXP, AMXD_OBJECT_TERMINATE, AMXD_OBJECT_SUPPORTED separated with '|'
Returns
Returns the relative path of the child object or NULL.

Definition at line 496 of file amxd_object_hierarchy.c.

498  {
499 
500  char* path = NULL;
501  when_null(child, exit);
502  when_true(amxd_object_is_base(child), exit);
503  when_null(parent, exit);
504  when_true(amxd_object_is_base(parent), exit);
505 
506  when_true(!amxd_object_is_child_of(child, parent), exit);
507  when_null(amxd_object_get_name(child, flags), exit);
508 
509  path = amxd_object_build_path(child, parent, flags);
510 
511 exit:
512  return path;
513 }
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.

◆ amxd_object_get_root()

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

Parameters
objectthe object pointer
Returns
Returns the data model root object pointer or NULL if the object is not in a data model object tree.

Definition at line 244 of file amxd_object_hierarchy.c.

244  {
245  amxd_object_t* root = NULL;
246  when_null(object, exit);
247  when_true(amxd_object_is_base(object), exit);
248  when_true(object->type == amxd_object_mib, exit);
249 
250  root = amxd_object_get_parent(object);
251  when_null(root, exit);
252 
253  while(root && root->it.llist != NULL) {
254  root = amxd_object_get_parent(root);
255  }
256 
257  if((root != NULL) && (root->type != amxd_object_root)) {
258  root = NULL;
259  }
260 
261 exit:
262  return root;
263 }

◆ amxd_object_hierarchy_walk()

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.

Parameters
objectthe object pointer, this is the starting object.
directioncan be one of amxd_direction_up or amxd_direction_down
filterfilter function, when the filter function returns false the object is not matching and will not be provided to the callback function
cbthe callback function, called for each matching object
depththe maximum depth
privpointer 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.

540  {
541  when_null(object, exit);
542  when_null(cb, exit);
543 
544  if(direction == amxd_direction_up) {
545  amxd_object_hierarchy_up(object, filter, cb, depth, priv);
546  } else {
547  amxd_object_hierarchy_down(object, direction, filter, cb, depth, priv);
548  }
549 
550 exit:
551  return;
552 }
static void amxd_object_hierarchy_down(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)
static void amxd_object_hierarchy_up(amxd_object_t *const object, amxd_object_filter_fn_t filter, amxd_object_cb_fn_t cb, int32_t depth, void *priv)
@ amxd_direction_up
Definition: amxd_types.h:215

◆ amxd_object_is_child_of()

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.

Parameters
childthe object pointer for which a relative path is requested
parentthe object pointer of the "parent" object.
Returns
true when the child object is a child of the parent object

Definition at line 515 of file amxd_object_hierarchy.c.

516  {
517  amxd_object_t* upper = NULL;
518  when_null(child, exit);
519  when_true(amxd_object_is_base(child), exit);
520  when_null(parent, exit);
521  when_true(amxd_object_is_base(parent), exit);
522 
523  upper = amxd_object_get_parent(child);
524  while(upper != NULL) {
525  if(upper == parent) {
526  break;
527  }
528  upper = amxd_object_get_parent(upper);
529  }
530 
531 exit:
532  return (upper != NULL);
533 }

◆ amxd_object_is_supported()

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.

Parameters
objectan object pointer, the starting point.
rel_pathsearch path, used to match the instances
Returns
true when the path is a supported path, false otherwise

Definition at line 585 of file amxd_object_hierarchy.c.

586  {
587  amxd_object_t* sup_obj = NULL;
588  amxd_path_t path;
589  amxc_llist_t paths;
590  bool retval = false;
591 
592  amxd_path_init(&path, req_path);
593  amxc_llist_init(&paths);
594 
595  when_null(object, exit);
596  when_true(amxd_object_is_base(object), exit);
597 
598  retval = true;
599  when_str_empty(req_path, exit);
600 
601  sup_obj = amxd_object_is_supported_impl(object, &path);
602  when_not_null(sup_obj, exit); // object is in supported data model
603 
604  // when objects are added using mibs, they will not be visible in the
605  // supported data model part.
606  // therefor when the object(s) exist (at least one is found),
607  // also return true
608  amxd_object_resolve_pathf(object, &paths, "%s", req_path);
609  retval = !amxc_llist_is_empty(&paths);
610 
611 exit:
612  amxc_llist_clean(&paths, amxc_string_list_it_free);
613  amxd_path_clean(&path);
614  return retval;
615 }
static amxd_object_t * amxd_object_is_supported_impl(amxd_object_t *object, amxd_path_t *path)
amxd_status_t amxd_path_init(amxd_path_t *path, const char *object_path)
Initializes an amxd_path_t structure.
Definition: amxd_path.c:328
void amxd_path_clean(amxd_path_t *path)
Cleans an amxd_path_t structure.
Definition: amxd_path.c:351

◆ amxd_object_resolve_pathf()

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.

Parameters
objectthe start object pointer
pathsan initialized linked list, the matching object paths are added to this list
rel_paththe relative (search) path. Supports printf formatting
Returns
amxd_status_ok if matching objects are found.

◆ amxd_object_resolve_pathf_ext()

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.

Parameters
objectthe start object pointer
key_pathwill be set to true when that paths are key paths
pathsan initialized linked list, the matching object paths are added to this list
rel_paththe relative (search) path. Supports printf formatting
Returns
amxd_status_ok if matching objects are found.