From a700befec984d1e2d4d75cbafac2705d856a6cba Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Thu, 31 Oct 2019 09:22:48 +0100 Subject: [PATCH] Module: function to get path --- src/module.c | 27 +++++++++++++++++++++++++++ src/module.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/src/module.c b/src/module.c index f230e4ace..7378d2fa5 100644 --- a/src/module.c +++ b/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; +} + diff --git a/src/module.h b/src/module.h index 55ca9394f..41fee5ade 100644 --- a/src/module.h +++ b/src/module.h @@ -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