[vlc-commits] objects: add vlc_object_typename()

Rémi Denis-Courmont git at videolan.org
Tue Feb 19 17:40:02 CET 2019


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Feb 19 18:30:48 2019 +0200| [050884ea063b44ea0149520f18e9fb071075c979] | committer: Rémi Denis-Courmont

objects: add vlc_object_typename()

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=050884ea063b44ea0149520f18e9fb071075c979
---

 include/vlc_objects.h                | 11 +++++++++++
 modules/gui/ncurses.c                |  2 +-
 modules/gui/qt/dialogs/messages.cpp  |  2 +-
 modules/services_discovery/podcast.c |  2 +-
 src/libvlccore.sym                   |  1 +
 src/misc/messages.c                  |  2 +-
 src/misc/objects.c                   | 14 +++++++++-----
 7 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/include/vlc_objects.h b/include/vlc_objects.h
index d5ad38c7d3..3fcb1839e9 100644
--- a/include/vlc_objects.h
+++ b/include/vlc_objects.h
@@ -111,6 +111,17 @@ VLC_API vlc_object_t *vlc_object_find_name( vlc_object_t *, const char * ) VLC_U
 VLC_API void * vlc_object_hold( vlc_object_t * );
 VLC_API void vlc_object_release( vlc_object_t * );
 VLC_API size_t vlc_list_children(vlc_object_t *, vlc_object_t **, size_t) VLC_USED;
+
+/**
+ * Returns the object type name.
+ *
+ * This returns a nul-terminated string identifying the object type.
+ * The string is valid for at least as long as the object reference.
+ *
+ * \param obj object whose type name to get
+ */
+VLC_API const char *vlc_object_typename(const vlc_object_t *obj) VLC_USED;
+
 VLC_API char *vlc_object_get_name( const vlc_object_t * ) VLC_USED;
 
 #define vlc_object_create(a,b) vlc_object_create( VLC_OBJECT(a), b )
diff --git a/modules/gui/ncurses.c b/modules/gui/ncurses.c
index fa2b11b765..0d6e22b76a 100644
--- a/modules/gui/ncurses.c
+++ b/modules/gui/ncurses.c
@@ -714,7 +714,7 @@ static int SubDrawObject(intf_sys_t *sys, int l, vlc_object_t *p_obj, int i_leve
 {
     char *name = vlc_object_get_name(p_obj);
     MainBoxWrite(sys, l++, "%*s%s%s \"%s\" (%p)", 2 * i_level++, "", prefix,
-                  p_obj->obj.object_type, name ? name : "", (void *)p_obj);
+                 vlc_object_typename(p_obj), name ? name : "", (void *)p_obj);
     free(name);
 
     size_t count = 0, size;
diff --git a/modules/gui/qt/dialogs/messages.cpp b/modules/gui/qt/dialogs/messages.cpp
index 58e6fdaa07..7a770875bb 100644
--- a/modules/gui/qt/dialogs/messages.cpp
+++ b/modules/gui/qt/dialogs/messages.cpp
@@ -304,7 +304,7 @@ void MessagesDialog::buildTree( QTreeWidgetItem *parentItem,
 
     char *name = vlc_object_get_name( p_obj );
     item->setText( 0, QString("%1%2 (0x%3)")
-                   .arg( qfu( p_obj->obj.object_type ) )
+                   .arg( qfu( vlc_object_typename(p_obj) ) )
                    .arg( ( name != NULL )
                          ? QString( " \"%1\"" ).arg( qfu( name ) )
                              : "" )
diff --git a/modules/services_discovery/podcast.c b/modules/services_discovery/podcast.c
index 66784b94a5..b9a31a1e18 100644
--- a/modules/services_discovery/podcast.c
+++ b/modules/services_discovery/podcast.c
@@ -120,7 +120,7 @@ static void SaveUrls( services_discovery_t *p_sd );
  *****************************************************************************/
 static int Open( vlc_object_t *p_this )
 {
-    if( strcmp( p_this->obj.parent->obj.object_type, "playlist" ) )
+    if( strcmp( vlc_object_typename(p_this->obj.parent), "playlist" ) )
         return VLC_EGENERIC; /* FIXME: support LibVLC SD too! */
 
     services_discovery_t *p_sd = ( services_discovery_t* )p_this;
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 85cf3802a7..38df09ee69 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -670,6 +670,7 @@ vlc_object_create
 vlc_object_find_name
 vlc_object_hold
 vlc_object_release
+vlc_object_typename
 vlc_object_get_name
 vlc_once
 vlc_rand_bytes
diff --git a/src/misc/messages.c b/src/misc/messages.c
index 8effb55c4a..1c02c232a2 100644
--- a/src/misc/messages.c
+++ b/src/misc/messages.c
@@ -110,7 +110,7 @@ void vlc_vaLog (vlc_object_t *obj, int type, const char *module,
     vlc_log_t msg;
 
     msg.i_object_id = (uintptr_t)obj;
-    msg.psz_object_type = (obj != NULL) ? obj->obj.object_type : "generic";
+    msg.psz_object_type = (obj != NULL) ? vlc_object_typename(obj) : "generic";
     msg.psz_module = module;
     msg.psz_header = NULL;
     msg.file = file;
diff --git a/src/misc/objects.c b/src/misc/objects.c
index d6c7c4e997..9c66745973 100644
--- a/src/misc/objects.c
+++ b/src/misc/objects.c
@@ -85,7 +85,7 @@ static void PrintObject(vlc_object_t *obj)
     PrintObjectPrefix(obj, true);
     printf("\xE2\x94\x80\xE2\x94%c\xE2\x95\xB4%p %s, %u refs\n",
            vlc_list_is_empty(&priv->children) ? 0x80 : 0xAC,
-           (void *)obj, obj->obj.object_type, atomic_load(&priv->refs));
+           (void *)obj, vlc_object_typename(obj), atomic_load(&priv->refs));
 
     vlc_restorecancel (canc);
 }
@@ -173,8 +173,8 @@ static int VarsCommand (vlc_object_t *obj, char const *cmd,
     else
         vlc_object_hold (obj);
 
-    printf(" o %p %s, parent %p\n", (void *)obj,
-           obj->obj.object_type, (void *)obj->obj.parent);
+    printf(" o %p %s, parent %p\n", (void *)obj, vlc_object_typename(obj),
+           (void *)obj->obj.parent);
     DumpVariables (obj);
     vlc_object_release (obj);
 
@@ -278,6 +278,11 @@ void vlc_object_set_destructor( vlc_object_t *p_this,
     p_priv->pf_destructor = pf_destructor;
 }
 
+const char *vlc_object_typename(const vlc_object_t *obj)
+{
+    return obj->obj.object_type;
+}
+
 static vlc_mutex_t name_lock = VLC_STATIC_MUTEX;
 
 #undef vlc_object_set_name
@@ -375,8 +380,7 @@ static int strcmp_void(const void *a, const void *b)
  * Finds a named object and increment its reference count.
  * Beware that objects found in this manner can be "owned" by another thread,
  * be of _any_ type, and be attached to any module (if any). With such an
- * object reference, you can set or get object variables, emit log messages,
- * and read write-once object parameters (obj.object_type, etc).
+ * object reference, you can set or get object variables, emit log messages.
  * You CANNOT cast the object to a more specific object type, and you
  * definitely cannot invoke object type-specific callbacks with this.
  *



More information about the vlc-commits mailing list