[vlc-devel] [PATCH 2/7] objects: add vlc_object_set_module
Thomas Guillem
thomas at gllm.fr
Mon May 27 16:45:11 CEST 2019
Refs #21997
---
include/vlc_objects.h | 3 +++
src/misc/objects.c | 13 +++++++++++++
src/misc/variables.h | 1 +
src/modules/modules.c | 8 +++-----
4 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/include/vlc_objects.h b/include/vlc_objects.h
index cc5eea64eb..b83c0e06b7 100644
--- a/include/vlc_objects.h
+++ b/include/vlc_objects.h
@@ -175,6 +175,9 @@ static inline struct vlc_logger *vlc_object_logger(vlc_object_t *obj)
*/
#define vlc_object_get_name(obj) var_GetString(obj, "module-name")
+void vlc_object_set_module(vlc_object_t *obj, const module_t *module);
+#define vlc_object_set_module(o, m) vlc_object_set_module(VLC_OBJECT(o), m)
+
#define vlc_object_create(a,b) vlc_object_create( VLC_OBJECT(a), b )
#define vlc_object_find_name(a,b) \
diff --git a/src/misc/objects.c b/src/misc/objects.c
index 940c39ab16..7ed35ea608 100644
--- a/src/misc/objects.c
+++ b/src/misc/objects.c
@@ -45,6 +45,7 @@
#include "vlc_interface.h"
#include "vlc_codec.h"
+#include "vlc_modules.h"
#include "variables.h"
@@ -75,6 +76,7 @@ int vlc_object_init(vlc_object_t *restrict obj, vlc_object_t *parent,
vlc_mutex_init (&priv->var_lock);
vlc_cond_init (&priv->var_wait);
priv->resources = NULL;
+ priv->module = NULL;
obj->priv = priv;
obj->force = false;
@@ -222,3 +224,14 @@ size_t vlc_list_children(vlc_object_t *obj, vlc_object_t **restrict tab,
vlc_mutex_unlock(&tree_lock);
return count;
}
+
+#undef vlc_object_set_module
+void vlc_object_set_module(vlc_object_t *obj, const module_t *module)
+{
+ vlc_object_internals_t *priv = vlc_internals(obj);
+ vlc_mutex_lock(&tree_lock);
+ /* Don't override module if it already exist */
+ if (!!module != !!priv->module)
+ priv->module = module;
+ vlc_mutex_unlock(&tree_lock);
+}
diff --git a/src/misc/variables.h b/src/misc/variables.h
index 710460989d..f4fdf433c5 100644
--- a/src/misc/variables.h
+++ b/src/misc/variables.h
@@ -44,6 +44,7 @@ struct vlc_object_internals
/* Objects tree structure */
struct vlc_list list; /**< Legacy list node */
+ const module_t *module;
/* Object resources */
struct vlc_res *resources;
diff --git a/src/modules/modules.c b/src/modules/modules.c
index 9c5c4229a2..41e36fbc78 100644
--- a/src/modules/modules.c
+++ b/src/modules/modules.c
@@ -276,10 +276,8 @@ module_t *module_need(vlc_object_t *obj, const char *cap, const char *name,
const bool b_force_backup = obj->force; /* FIXME: remove this */
module_t *module = vlc_module_load(obj->logger, cap, name, strict,
generic_start, obj);
- if (module != NULL) {
- var_Create(obj, "module-name", VLC_VAR_STRING);
- var_SetString(obj, "module-name", module_get_object(module));
- }
+ if (module != NULL)
+ vlc_object_set_module(obj, module);
obj->force = b_force_backup;
return module;
@@ -289,7 +287,7 @@ module_t *module_need(vlc_object_t *obj, const char *cap, const char *name,
void module_unneed(vlc_object_t *obj, module_t *module)
{
msg_Dbg(obj, "removing module \"%s\"", module_get_object(module));
- var_Destroy(obj, "module-name");
+ vlc_object_set_module(obj, NULL);
vlc_module_unload(module, generic_stop, obj);
vlc_objres_clear(obj);
}
--
2.20.1
More information about the vlc-devel
mailing list