]> git.sesse.net Git - vlc/blobdiff - src/control/event.c
Move LibVLC error messages to libvlc_printerr().
[vlc] / src / control / event.c
index 724bd5dd058f3bd9b82af2413e430bccd913ab16..af7f9aa654e948d7c26a8e40ed235ab664cfaec5 100644 (file)
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
 
+#define  LIBVLC_EVENT_TYPES_KEEP_DEFINE
 #include <vlc/libvlc.h>
 
 #include "libvlc_internal.h"
 #include "event_internal.h"
+#include <assert.h>
 
 typedef struct libvlc_event_listeners_group_t
 {
@@ -73,7 +75,8 @@ libvlc_event_manager_new( void * p_obj, libvlc_instance_t * p_libvlc_inst,
     p_em = malloc(sizeof( libvlc_event_manager_t ));
     if( !p_em )
     {
-        libvlc_exception_raise( p_e, "No Memory left" );
+        libvlc_exception_raise( p_e );
+        libvlc_printerr( "Not enough memory" );
         return NULL;
     }
 
@@ -133,7 +136,8 @@ void libvlc_event_manager_register_event_type(
     listeners_group = malloc(sizeof(libvlc_event_listeners_group_t));
     if( !listeners_group )
     {
-        libvlc_exception_raise( p_e, "No Memory left" );
+        libvlc_exception_raise( p_e );
+        libvlc_printerr( "Not enough memory" );
         return;
     }
 
@@ -250,58 +254,19 @@ void libvlc_event_send( libvlc_event_manager_t * p_em,
  *
  * Get the char * name of an event type.
  **************************************************************************/
-static const char event_type_to_name[][35] =
+static const char event_type_to_name[][libvlc_num_event_types] =
 {
-#define EVENT(a) [a]=#a
-    EVENT(libvlc_MediaMetaChanged),
-    EVENT(libvlc_MediaSubItemAdded),
-    EVENT(libvlc_MediaDurationChanged),
-    EVENT(libvlc_MediaPreparsedChanged),
-    EVENT(libvlc_MediaFreed),
-    EVENT(libvlc_MediaStateChanged),
-
-    EVENT(libvlc_MediaPlayerNothingSpecial),
-    EVENT(libvlc_MediaPlayerOpening),
-    EVENT(libvlc_MediaPlayerBuffering),
-    EVENT(libvlc_MediaPlayerPlaying),
-    EVENT(libvlc_MediaPlayerPaused),
-    EVENT(libvlc_MediaPlayerStopped),
-    EVENT(libvlc_MediaPlayerForward),
-    EVENT(libvlc_MediaPlayerBackward),
-    EVENT(libvlc_MediaPlayerEndReached),
-    EVENT(libvlc_MediaPlayerTimeChanged),
-    EVENT(libvlc_MediaPlayerTitleChanged),
-    EVENT(libvlc_MediaPlayerPositionChanged),
-    EVENT(libvlc_MediaPlayerSeekableChanged),
-    EVENT(libvlc_MediaPlayerPausableChanged),
-
-    EVENT(libvlc_MediaListItemAdded),
-    EVENT(libvlc_MediaListWillAddItem),
-    EVENT(libvlc_MediaListItemDeleted),
-    EVENT(libvlc_MediaListWillDeleteItem),
-
-    EVENT(libvlc_MediaListViewItemAdded),
-    EVENT(libvlc_MediaListViewWillAddItem),
-    EVENT(libvlc_MediaListViewItemDeleted),
-    EVENT(libvlc_MediaListViewWillDeleteItem),
-
-    EVENT(libvlc_MediaListPlayerPlayed),
-    EVENT(libvlc_MediaListPlayerNextItemSet),
-    EVENT(libvlc_MediaListPlayerStopped),
-
-    EVENT(libvlc_MediaDiscovererStarted),
-    EVENT(libvlc_MediaDiscovererEnded),
-
-    EVENT(libvlc_MediaPlayerSnapshotTaken),
-#undef EVENT
+#define DEF(a) [libvlc_##a]=#a
+    DEFINE_LIBVLC_EVENT_TYPES
+#undef  DEF
 };
 
-static const char unkwown_event_name[] = "Unknown Event";
+static const char unknown_event_name[] = "Unknown Event";
 
 const char * libvlc_event_type_name( libvlc_event_type_t event_type )
 {
-    if( event_type >= sizeof(event_type_to_name)/sizeof(event_type_to_name[0]))
-        return unkwown_event_name;
+    if( event_type >= libvlc_num_event_types )
+        return unknown_event_name;
     return event_type_to_name[event_type];
 }
 
@@ -325,7 +290,8 @@ void event_attach( libvlc_event_manager_t * p_event_manager,
     listener = malloc(sizeof(libvlc_event_listener_t));
     if( !listener )
     {
-        libvlc_exception_raise( p_e, "No Memory left" );
+        libvlc_exception_raise( p_e );
+        libvlc_printerr( "Not enough memory" );
         return;
     }
     
@@ -348,9 +314,9 @@ void event_attach( libvlc_event_manager_t * p_event_manager,
     vlc_mutex_unlock( &p_event_manager->object_lock );
     
     free(listener);
-    libvlc_exception_raise( p_e,
-                           "This object event manager doesn't know about '%s' events",
-                           libvlc_event_type_name(event_type));
+    fprintf( stderr, "This object event manager doesn't know about '%s' events",
+             libvlc_event_type_name(event_type) );
+    assert(0);
 }
 
 /**************************************************************************
@@ -437,10 +403,5 @@ void libvlc_event_detach( libvlc_event_manager_t *p_event_manager,
 
     libvlc_event_async_ensure_listener_removal(p_event_manager, &listener_to_remove);
 
-    if(!found)
-    {
-        libvlc_exception_raise( p_e,
-                               "This object event manager doesn't know about '%s,%p,%p' event observer",
-                               libvlc_event_type_name(event_type), pf_callback, p_user_data );        
-    }
+    assert(found);
 }