82 while(current != NULL && depth >= 0) {
83 if((filter != NULL) && !filter(current, depth, priv)) {
86 cb(current, depth, priv);
88 depth = depth == INT32_MAX ? INT32_MAX : depth - 1;
102 if((filter != NULL) && !filter(
object, depth, priv)) {
106 cb(
object, depth, priv);
109 depth = depth == INT32_MAX ? INT32_MAX : depth - 1;
120 cb(
object, depth, priv);
128 const uint32_t flags) {
132 amxc_string_prepend(path,
"\\]", 2);
134 amxc_string_prepend(path,
"]", 1);
138 amxc_string_prependf(path,
"%" PRId32, object->
index);
140 amxc_string_prepend(path, name, length);
144 amxc_string_prepend(path,
"\\[", 2);
146 amxc_string_prepend(path,
"[", 1);
154 const uint32_t flags) {
157 const char* sep = NULL;
158 char* str_path = NULL;
169 amxc_string_init(&path, 64);
171 while(current != stop &&
174 int length = strlen(name);
176 if(!amxc_string_is_empty(&path) &&
177 ( strncmp(path.buffer, sep, sep_length) != 0)) {
178 amxc_string_prepend(&path, sep, sep_length);
186 amxc_string_prepend(&path,
"{i}", 3);
187 amxc_string_prepend(&path, sep, sep_length);
189 amxc_string_prepend(&path, name, length);
195 amxc_string_append(&path, sep, sep_length);
198 str_path = amxc_string_take_buffer(&path);
199 amxc_string_clean(&path);
213 if((part != NULL) && (part[0] ==
'.')) {
217 when_null(part, exit);
220 when_null(
object, exit);
229 when_null(
object, exit);
232 when_null(object->
it.llist, exit);
235 parent = amxc_container_of(object->
it.llist,
amxd_object_t, instances);
246 when_null(
object, exit);
251 when_null(root, exit);
253 while(root && root->
it.llist != NULL) {
269 when_null(
object, exit);
273 when_null(object->
it.llist, exit);
282 while(parent != NULL &&
289 when_null(parent->
it.llist, exit);
303 when_null(
object, exit);
304 when_str_empty(name, exit);
306 length = strlen(name);
307 if(name[length - 1] ==
'.') {
311 amxc_llist_for_each(it, (&object->
objects)) {
312 const char* n = NULL;
317 if((nlen == length) && (strncmp(n, name, length) == 0)) {
333 when_null(
object, exit);
335 if((name != NULL) && (name[0] != 0)) {
337 length = strlen(name);
338 if(alias_param == NULL) {
339 if(name[length - 1] ==
'.') {
343 length = strlen(name);
350 amxc_llist_for_each(it, (&object->
instances)) {
351 const char* n = NULL;
355 if(result->
index == index) {
359 if((name != NULL) && (name[0] != 0)) {
360 int nlen = strlen(n);
361 if((nlen == length) && (strncmp(n, name + offset, length) == 0)) {
375 when_str_empty(name, exit);
378 if(isdigit(name[0]) == 0) {
393 const char* rel_path,
400 bool key_path =
false;
404 when_null(
object, exit);
405 when_str_empty(rel_path, exit);
411 va_start(args, rel_path);
414 when_failed(
status, exit);
428 const char* rel_path,
433 bool key_path =
false;
437 when_null(
object, exit);
439 when_str_empty(rel_path, exit);
441 va_start(args, rel_path);
444 when_failed(
status, exit);
456 const char* rel_path,
464 when_null(key_path, exit);
465 when_null(
object, exit);
467 when_str_empty(rel_path, exit);
471 va_start(args, rel_path);
474 when_failed(
status, exit);
484 const uint32_t flags) {
486 when_null(
object, exit);
498 const uint32_t flags) {
501 when_null(child, exit);
503 when_null(parent, exit);
518 when_null(child, exit);
520 when_null(parent, exit);
524 while(upper != NULL) {
525 if(upper == parent) {
532 return (upper != NULL);
541 when_null(
object, exit);
555 const char* rel_spath,
561 amxc_llist_init(&paths);
563 when_null(
object, exit);
566 when_str_empty(rel_spath, exit);
572 amxc_llist_for_each(it, (&paths)) {
573 amxc_string_t* path = amxc_string_from_llist_it(it);
575 if(mobject != NULL) {
576 fn(
object, mobject, priv);
581 amxc_llist_clean(&paths, amxc_string_list_it_free);
586 const char* req_path) {
593 amxc_llist_init(&paths);
595 when_null(
object, exit);
599 when_str_empty(req_path, exit);
602 when_not_null(sup_obj, exit);
609 retval = !amxc_llist_is_empty(&paths);
612 amxc_llist_clean(&paths, amxc_string_list_it_free);
Ambiorix Data Model API header file.
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)
Ambiorix Data Model API header file.
static amxd_object_t * amxd_object_is_supported_impl(amxd_object_t *object, amxd_path_t *path)
amxd_status_t amxd_object_resolve_pathf(amxd_object_t *object, amxc_llist_t *paths, const char *rel_path,...)
static void amxd_path_prepend_instance(const amxd_object_t *object, amxc_string_t *path, const char *name, uint32_t length, const uint32_t flags)
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)
amxd_object_t * amxd_object_findf(amxd_object_t *const object, const char *rel_path,...)
amxd_status_t amxd_object_resolve_pathf_ext(amxd_object_t *object, bool *key_path, amxc_llist_t *paths, const char *rel_path,...)
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)
static char * amxd_object_build_path(const amxd_object_t *object, const amxd_object_t *stop, const uint32_t flags)
PRIVATE amxd_object_t * amxd_object_find_internal(amxd_object_t *const object, bool *key_path, amxd_path_t *path, amxd_status_t *status)
PRIVATE amxd_status_t amxd_object_resolve_internal(amxd_object_t *const object, bool *key_path, amxc_llist_t *paths, amxd_path_t *path)
Ambiorix path API header file.
enum _amxd_direction amxd_direction_t
enum _amxd_status amxd_status_t
@ amxd_status_unknown_error
@ amxd_direction_down_reverse
#define AMXD_OBJECT_SUPPORTED
Path format flag - adds {i} as placeholder for an instance object.
#define AMXD_OBJECT_INDEXED
Name and path format flag - use index for instance objects.
#define AMXD_OBJECT_REGEXP
Path format flag - create path that can be used as regular expression.
#define AMXD_OBJECT_NAMED
Name and path format flag - default behavior, use name for instance objects.
#define AMXD_OBJECT_EXTENDED
Path format flag - set name or index of instrance objects between '[' and ']'.
#define AMXD_OBJECT_TERMINATE
Path format flag - when set the object path is terminated with a dot.
char * amxd_object_get_path(const amxd_object_t *object, const uint32_t flags)
Get the full path of the object.
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_t * amxd_object_get_parent(const amxd_object_t *const object)
Get the parent object.
amxd_object_t * amxd_object_get_child(const amxd_object_t *object, const char *name)
Get a child of the object.
amxd_object_t * amxd_object_get_root(const amxd_object_t *const object)
Get the data model root.
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.
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.
int(* amxd_mobject_cb_t)(amxd_object_t *object, amxd_object_t *mobject, void *priv)
Definition of matching object callback function.
amxd_dm_t * amxd_object_get_dm(const amxd_object_t *const object)
Get the data model.
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.
amxd_object_t * amxd_object_get(const amxd_object_t *object, const char *name)
Get an instance or child of an object.
void(* amxd_object_cb_fn_t)(amxd_object_t *const object, int32_t depth, void *priv)
Definition of object walk callback function.
bool amxd_object_is_supported(amxd_object_t *object, const char *req_path)
Checks if a path is in the supported data model.
bool(* amxd_object_filter_fn_t)(amxd_object_t *const object, int32_t depth, void *priv)
Definition of object filter function.
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.
amxd_param_t * amxd_object_get_param_def(const amxd_object_t *const object, const char *name)
Gets a parameter definition from an object.
static amxd_object_type_t amxd_object_get_type(const amxd_object_t *const object)
Returns the object type.
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)
#define amxd_object_for_each(type, it, object)
Helper macro for iterating object content.
amxd_status_t amxd_path_init(amxd_path_t *path, const char *object_path)
Initializes an amxd_path_t structure.
char * amxd_path_get_first(amxd_path_t *path, bool remove)
Gets the first part of the path.
void amxd_path_clean(amxd_path_t *path)
Cleans an amxd_path_t structure.
amxd_status_t amxd_path_vsetf(amxd_path_t *path, bool add_dot, const char *obj_path, va_list args)
Sets or replaces the path contained in the amxd_path_t structure.
static amxd_status_t status