Module: function to get path

This commit is contained in:
Martin Pulec
2019-10-31 09:22:48 +01:00
parent 171672f620
commit a700befec9
2 changed files with 29 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -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