[vlc-commits] Qt: Ensure event IDs are not reused.

Francois Cartegnie git at videolan.org
Fri Aug 17 18:06:24 CEST 2012


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Aug 17 18:05:46 2012 +0200| [6f435e8805274d1c52ad89893ee1121be35f2978] | committer: Francois Cartegnie

Qt: Ensure event IDs are not reused.

Qt ensures event IDs are never reused by providing a way to register
them dynamically. We have code that allocate event IDs statically and we
need to check/register those then to ensure proper offset for dynamic
ones. (we could just register them too, but this wouldn't allow
switch/case through values)

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

 modules/gui/qt4/input_manager.cpp |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/modules/gui/qt4/input_manager.cpp b/modules/gui/qt4/input_manager.cpp
index c130098..45e555f 100644
--- a/modules/gui/qt4/input_manager.cpp
+++ b/modules/gui/qt4/input_manager.cpp
@@ -57,6 +57,12 @@ static int InputEvent( vlc_object_t *, const char *,
 static int VbiEvent( vlc_object_t *, const char *,
                      vlc_value_t, vlc_value_t, void * );
 
+/* Ensure arbitratry (not dynamically allocated) event IDs are not in use */
+static inline void registerAndCheckEventIds( int start, int end )
+{
+    for ( int i=start ; i<=end ; i++ )
+        Q_ASSERT( QEvent::registerEventType( i ) == i ); /* event ID collision ! */
+}
 
 /**********************************************************************
  * InputManager implementation
@@ -80,6 +86,8 @@ InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
     timeB        = 0;
     f_cache      = -1.; /* impossible initial value, different from all */
     rateLimitedEventPoster = new RateLimitedEventPoster();
+    registerAndCheckEventIds( IMEvent::PositionUpdate, IMEvent::FullscreenControlPlanHide );
+    registerAndCheckEventIds( PLEvent::PLItemAppended, PLEvent::PLEmpty );
 }
 
 InputManager::~InputManager()



More information about the vlc-commits mailing list