Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

JS: Hierarchy and Navigation

Hierarchy and Navigation

The gobjs build a tree of parents and children. The root is the yuno. The services are under the yuno. Each gobj has one parent, and the yuno has none.

Yuno
 ├── Service "auth"     (C_IEVENT_CLI)
 ├── Service "main"     (C_MY_SERVICE)
 │    └── Child "sub"   (C_SOME_GCLASS)
 └── Service "timer"    (C_TIMER)

Source code: src/gobj.js


The root and the services

gobj_yuno()

Gives the yuno, which is the root of the tree.

__yuno__

The variable that holds the yuno. Read it with gobj_yuno(), which is the public form.

gobj_services()

Gives the names of the registered services, as a list.

gobj_default_service()

Gives the default service.

gobj_find_service(service_name, verbose)

Finds a service by its name. With verbose set to true the function writes a log error when the service does not exist.


Names

gobj_name(gobj)

Gives the name of a gobj.

gobj_gclass_name(gobj)

Gives the name of the gclass of a gobj.

gobj_short_name(gobj)

Gives the short name, which is the gclass and the name. A log message uses it.

gobj_full_name(gobj)

Gives the full name, which carries the path from the yuno.

gobj_yuno_name()

Gives the name of the yuno.

gobj_yuno_role()

Gives the role of the yuno.

gobj_yuno_id()

Gives the identifier of the yuno.


Parents and children

gobj_parent(gobj)

Gives the parent of a gobj.

gobj_change_parent(gobj, parent)

Moves a gobj to another parent, and gives 0. A walk of the tree that is in progress gives the gobj in its new place, not in its old place (gobj-js 7.26.28; see gobj_walk_gobj_children()).

It gives -1 with an ERROR, and moves nothing, when the gobj or the new parent is destroyed, when the new parent is not a gobj, or when the new parent is the gobj itself or one of its descendants (that makes a cycle; gobj-js 7.26.29).

gobj_change_parent(a, a_child);   // -1: a gobj cannot be its own ancestor
// c1, c2 and c3 are children of root; c1 has the child g1, c2 the child g2.
gobj_walk_gobj_children_tree(root, walk_type_t.WALK_TOP2BOTTOM, (child) => {
    if(child === c1) {
        gobj_change_parent(c2, c3);
    }
    return 0;
}, 0, 0);
// The callback gets: c1, g1, c3, c2, g2 (7.26.27 gave c1, g1, c2, g2, c3, c2, g2)

gobj_bottom_gobj(gobj)

Gives the bottom gobj, which is the gobj that carries the work of the layer below. A gclass of a protocol keeps its transport there.

gobj_set_bottom_gobj(gobj, bottom_gobj)

Writes the bottom gobj. The function writes a log warning when the gobj holds one already.


gobj_find_child(gobj, jn_filter)

Gives the first child that matches a filter of attributes.

gobj_match_children(gobj, jn_filter)

Gives every child that matches a filter, as a list.

gobj_match_children_tree(gobj, jn_filter)

Gives every gobj below this one that matches a filter, at any depth.

gobj_match_gobj(gobj, jn_filter)

Tells if one gobj matches a filter. The three functions above use it.

gobj_find_gobj(gobj, path)

Finds a gobj from a path.

gobj_search_path(gobj, path)

Finds a gobj from a path, and begins the search at gobj.


Walk the tree

walk_type_t

The order the two walks take. One of WALK_TOP2BOTTOM, WALK_BOTTOM2TOP or WALK_BYLEVEL must be given; with WALK_BYLEVEL, add WALK_FIRST2LAST or WALK_LAST2FIRST. Same names and same values as the C walk_type_t.

gobj_walk_gobj_children(gobj, walk_type, cb_walking, user_data, user_data2)

Calls cb_walking(gobj, user_data, user_data2) for each child. walk_type chooses the order. A callback that gives a negative value stops the walk, and the walk gives that value. 0 or a positive value goes on to the next child.

The callback can destroy any gobj, also the current one. The walk does not give a destroyed gobj to the callback (7.26.27).

The callback can also move a gobj with gobj_change_parent(). The walk gives each gobj to the callback one time at most (gobj-js 7.26.28):

Before 7.26.28, the walk gave a moved gobj two times: in its old place and in its new place.

gobj_walk_gobj_children_tree(gobj, walk_type, cb_walking, user_data, user_data2)

The same walk, and it goes down to every depth. With WALK_TOP2BOTTOM, a positive value from the callback skips the children of that gobj. The walk does not go into the children of a gobj that the callback destroyed. A gobj that the callback moves is given one time at most, as above.

gobj_walk_gobj_children_tree(gobj, walk_type_t.WALK_TOP2BOTTOM, (child) => {
    if(gobj_is_disabled(child)) {
        return 1;           // skip its children
    }
    log_info(gobj_short_name(child));
    return 0;               // go on, and down into its children
}, 0, 0);