[vlc-commits] objects: use object ID rather than name for "vars" command
Rémi Denis-Courmont
git at videolan.org
Wed Nov 25 19:04:25 CET 2015
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Nov 25 19:24:26 2015 +0200| [f3c8e16f4614637bc06ff6d50c3cc8b12121810b] | committer: Rémi Denis-Courmont
objects: use object ID rather than name for "vars" command
This enables looking up objects that do not have a name.
(Use "tree" as before to find object IDs.)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f3c8e16f4614637bc06ff6d50c3cc8b12121810b
---
src/misc/objects.c | 35 +++++++++++++++++++++++++++++++----
1 file changed, 31 insertions(+), 4 deletions(-)
diff --git a/src/misc/objects.c b/src/misc/objects.c
index 41e5530..5eec31d 100644
--- a/src/misc/objects.c
+++ b/src/misc/objects.c
@@ -139,16 +139,43 @@ static int TreeCommand (vlc_object_t *obj, char const *cmd,
return VLC_SUCCESS;
}
+static bool ObjectExists (vlc_object_t *root, void *obj)
+{
+ if (root == obj)
+ return true;
+
+ vlc_object_internals_t *priv = vlc_internals(root);
+
+ for (priv = priv->first; priv != NULL; priv = priv->next)
+ if (ObjectExists (vlc_externals (priv), obj))
+ return true;
+
+ return false;
+}
+
static int VarsCommand (vlc_object_t *obj, char const *cmd,
vlc_value_t oldval, vlc_value_t newval, void *data)
{
+ void *p;
+
(void) cmd; (void) oldval; (void) data;
- if (newval.psz_string[0] != '\0')
- { /* try using the object's name to find it */
- obj = vlc_object_find_name (obj, newval.psz_string);
- if (obj == NULL)
+ if (sscanf (newval.psz_string, "%p", &p) == 1)
+ {
+ libvlc_lock ((libvlc_int_t *)obj);
+ if (ObjectExists (obj, p))
+ vlc_object_hold ((vlc_object_t *)p);
+ else
+ p = NULL;
+ libvlc_unlock ((libvlc_int_t *)obj);
+
+ if (p == NULL)
+ {
+ msg_Err (obj, "no such object: %s", newval.psz_string);
return VLC_ENOOBJ;
+ }
+
+ obj = p;
}
else
vlc_object_hold (obj);
More information about the vlc-commits
mailing list