[vlc-devel] commit: Reimplement libvlc_event_type_name ( Rémi Denis-Courmont )

git version control git at videolan.org
Sat Feb 20 13:31:56 CET 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Feb 20 14:31:23 2010 +0200| [2f63e68b447e5b2484954f60b90d430afd887b98] | committer: Rémi Denis-Courmont 

Reimplement libvlc_event_type_name

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

 include/vlc/libvlc.h        |    7 ++++
 include/vlc/libvlc_events.h |    5 ++-
 src/control/event.c         |   82 ++++++++++++++++++++++++++++++++++++++++++-
 src/libvlc.sym              |    1 +
 4 files changed, 92 insertions(+), 3 deletions(-)

diff --git a/include/vlc/libvlc.h b/include/vlc/libvlc.h
index 4ccbfeb..480774e 100644
--- a/include/vlc/libvlc.h
+++ b/include/vlc/libvlc.h
@@ -242,6 +242,13 @@ VLC_PUBLIC_API void libvlc_event_detach( libvlc_event_manager_t *p_event_manager
                                          libvlc_callback_t f_callback,
                                          void *p_user_data );
 
+/**
+ * Get an event's type name.
+ *
+ * \param event_type the desired event
+ */
+VLC_PUBLIC_API const char * libvlc_event_type_name( libvlc_event_type_t event_type );
+
 /** @} */
 
 /** \defgroup libvlc_log LibVLC logging
diff --git a/include/vlc/libvlc_events.h b/include/vlc/libvlc_events.h
index 729c80f..a58987b 100644
--- a/include/vlc/libvlc_events.h
+++ b/include/vlc/libvlc_events.h
@@ -43,8 +43,9 @@ extern "C" {
  * Event types
  */
 enum libvlc_event_e {
-    /* Append new event types at the end. Do not remove, insert or
-     * re-order any entry. The cpp will prepend libvlc_ to the symbols. */
+    /* Append new event types at the end of a category.
+     * Do not remove, insert or re-order any entry.
+     * Keep this in sync with src/control/event.c:libvlc_event_type_name(). */
     libvlc_MediaMetaChanged=0,
     libvlc_MediaSubItemAdded,
     libvlc_MediaDurationChanged,
diff --git a/src/control/event.c b/src/control/event.c
index 2fb9c35..768c361 100644
--- a/src/control/event.c
+++ b/src/control/event.c
@@ -240,6 +240,85 @@ void libvlc_event_send( libvlc_event_manager_t * p_em,
  * Public libvlc functions
  */
 
+#define DEF( a ) { libvlc_##a, #a, },
+
+typedef struct
+{
+    int type;
+    const char name[40];
+} event_name_t;
+
+static const event_name_t event_list[] = {
+    DEF(MediaMetaChanged)
+    DEF(MediaSubItemAdded)
+    DEF(MediaDurationChanged)
+    DEF(MediaPreparsedChanged)
+    DEF(MediaFreed)
+    DEF(MediaStateChanged)
+
+    DEF(MediaPlayerMediaChanged)
+    DEF(MediaPlayerNothingSpecial)
+    DEF(MediaPlayerOpening)
+    DEF(MediaPlayerBuffering)
+    DEF(MediaPlayerPlaying)
+    DEF(MediaPlayerPaused)
+    DEF(MediaPlayerStopped)
+    DEF(MediaPlayerForward)
+    DEF(MediaPlayerBackward)
+    DEF(MediaPlayerEndReached)
+    DEF(MediaPlayerEncounteredError)
+    DEF(MediaPlayerTimeChanged)
+    DEF(MediaPlayerPositionChanged)
+    DEF(MediaPlayerSeekableChanged)
+    DEF(MediaPlayerPausableChanged)
+    DEF(MediaPlayerTitleChanged)
+    DEF(MediaPlayerSnapshotTaken)
+    DEF(MediaPlayerLengthChanged)
+
+    DEF(MediaListItemAdded)
+    DEF(MediaListWillAddItem)
+    DEF(MediaListItemDeleted)
+    DEF(MediaListWillDeleteItem)
+
+    DEF(MediaListViewItemAdded)
+    DEF(MediaListViewWillAddItem)
+    DEF(MediaListViewItemDeleted)
+    DEF(MediaListViewWillDeleteItem)
+
+    DEF(MediaListPlayerPlayed)
+    DEF(MediaListPlayerNextItemSet)
+    DEF(MediaListPlayerStopped)
+
+    DEF(MediaDiscovererStarted)
+    DEF(MediaDiscovererEnded)
+
+    DEF(VlmMediaAdded)
+    DEF(VlmMediaRemoved)
+    DEF(VlmMediaChanged)
+    DEF(VlmMediaInstanceStarted)
+    DEF(VlmMediaInstanceStopped)
+    DEF(VlmMediaInstanceStatusInit)
+    DEF(VlmMediaInstanceStatusOpening)
+};
+#undef DEF
+
+static const char unknown_event_name[] = "Unknown Event";
+
+static int evcmp( const void *a, const void *b )
+{
+    return (*(const int *)a) - ((event_name_t *)b)->type;
+}
+
+const char * libvlc_event_type_name( int event_type )
+{
+    const event_name_t *p;
+
+    p = bsearch( &event_type, event_list,
+                 sizeof(event_list)/sizeof(event_list[0]), sizeof(*p),
+                 evcmp );
+    return p ? p->name : unknown_event_name;
+}
+
 /**************************************************************************
  *       event_attach (internal) :
  *
@@ -278,7 +357,8 @@ int event_attach( libvlc_event_manager_t * p_event_manager,
     vlc_mutex_unlock( &p_event_manager->object_lock );
     
     free(listener);
-    fprintf( stderr, "Unknown event type %d", event_type );
+    fprintf( stderr, "This object event manager doesn't know about '%s' events",
+             libvlc_event_type_name(event_type) );
     assert(0);
     return -1;
 }
diff --git a/src/libvlc.sym b/src/libvlc.sym
index ac3a64d..b38ec01 100644
--- a/src/libvlc.sym
+++ b/src/libvlc.sym
@@ -29,6 +29,7 @@ libvlc_event_manager_new
 libvlc_event_manager_register_event_type
 libvlc_event_manager_release
 libvlc_event_send
+libvlc_event_type_name
 libvlc_get_changeset
 libvlc_get_compiler
 libvlc_get_fullscreen




More information about the vlc-devel mailing list