mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-22 04:40:30 +00:00
Module: function to get path
This commit is contained in:
27
src/module.c
27
src/module.c
@@ -325,3 +325,30 @@ void dump_tree(struct module *node, int indent) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets textual representation of path from root to module.
|
||||
*
|
||||
* Currently only simple paths are created (class names only)
|
||||
*/
|
||||
bool module_get_path_str(struct module *mod, char *buf, size_t buflen) {
|
||||
assert(buflen > 0);
|
||||
buf[0] = '\0';
|
||||
|
||||
while (mod) {
|
||||
const char *cur_name = module_class_name(mod->cls);
|
||||
if (sizeof(buf) + 1 + sizeof(cur_name) >= buflen) {
|
||||
return false;
|
||||
}
|
||||
if (strlen(buf) > 0) {
|
||||
memmove(buf + strlen(cur_name) + 1, buf, strlen(buf) + 1);
|
||||
buf[strlen(cur_name)] = '.';
|
||||
} else {
|
||||
buf[strlen(cur_name)] = '\0';
|
||||
}
|
||||
memcpy(buf, cur_name, strlen(cur_name));
|
||||
mod = mod->parent;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -146,6 +146,8 @@ void module_register(struct module *module_data, struct module *parent);
|
||||
void module_done(struct module *module_data);
|
||||
const char *module_class_name(enum module_class cls);
|
||||
void append_message_path(char *buf, int buflen, enum module_class modules[]);
|
||||
bool module_get_path_str(struct module *mod, char *buf, size_t buflen);
|
||||
|
||||
/**
|
||||
* @retval NULL if not found
|
||||
* @retval non-NULL pointer to the module
|
||||
|
||||
Reference in New Issue
Block a user