Commit 2f63e68b authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Reimplement libvlc_event_type_name

parent 8fa0ec3c
...@@ -242,6 +242,13 @@ VLC_PUBLIC_API void libvlc_event_detach( libvlc_event_manager_t *p_event_manager ...@@ -242,6 +242,13 @@ VLC_PUBLIC_API void libvlc_event_detach( libvlc_event_manager_t *p_event_manager
libvlc_callback_t f_callback, libvlc_callback_t f_callback,
void *p_user_data ); 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 /** \defgroup libvlc_log LibVLC logging
......
...@@ -43,8 +43,9 @@ extern "C" { ...@@ -43,8 +43,9 @@ extern "C" {
* Event types * Event types
*/ */
enum libvlc_event_e { enum libvlc_event_e {
/* Append new event types at the end. Do not remove, insert or /* Append new event types at the end of a category.
* re-order any entry. The cpp will prepend libvlc_ to the symbols. */ * 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_MediaMetaChanged=0,
libvlc_MediaSubItemAdded, libvlc_MediaSubItemAdded,
libvlc_MediaDurationChanged, libvlc_MediaDurationChanged,
......
...@@ -240,6 +240,85 @@ void libvlc_event_send( libvlc_event_manager_t * p_em, ...@@ -240,6 +240,85 @@ void libvlc_event_send( libvlc_event_manager_t * p_em,
* Public libvlc functions * 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) : * event_attach (internal) :
* *
...@@ -278,7 +357,8 @@ int event_attach( libvlc_event_manager_t * p_event_manager, ...@@ -278,7 +357,8 @@ int event_attach( libvlc_event_manager_t * p_event_manager,
vlc_mutex_unlock( &p_event_manager->object_lock ); vlc_mutex_unlock( &p_event_manager->object_lock );
free(listener); 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); assert(0);
return -1; return -1;
} }
......
...@@ -29,6 +29,7 @@ libvlc_event_manager_new ...@@ -29,6 +29,7 @@ libvlc_event_manager_new
libvlc_event_manager_register_event_type libvlc_event_manager_register_event_type
libvlc_event_manager_release libvlc_event_manager_release
libvlc_event_send libvlc_event_send
libvlc_event_type_name
libvlc_get_changeset libvlc_get_changeset
libvlc_get_compiler libvlc_get_compiler
libvlc_get_fullscreen libvlc_get_fullscreen
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment