[vlc-commits] Simplify events mapping

Jean-Baptiste Kempf git at videolan.org
Wed Apr 23 19:28:55 CEST 2014


npapi-vlc | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Wed Apr 23 19:24:02 2014 +0200| [d7d5988858b2b8400e61797ff9957eb40839b3e1] | committer: Jean-Baptiste Kempf

Simplify events mapping

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

 npapi/events.cpp |   18 ++++--------------
 npapi/events.h   |    7 ++++---
 2 files changed, 8 insertions(+), 17 deletions(-)

diff --git a/npapi/events.cpp b/npapi/events.cpp
index 58cdc9e..a5a98d7 100644
--- a/npapi/events.cpp
+++ b/npapi/events.cpp
@@ -175,29 +175,19 @@ void EventObj::callback(const libvlc_event_t* event,
     plugin_unlock(&lock);
 }
 
-vlcplugin_event_t *EventObj::find_event(const char *s) const
+vlcplugin_event_t *EventObj::find_event(const NPString &name) const
 {
     for( size_t i = 0; i < ARRAY_SIZE(vlcevents); i++ )
     {
-        if( strncmp(vlcevents[i].name, s, strlen(vlcevents[i].name)) == 0 )
+        if( strncmp(vlcevents[i].name, name.UTF8Characters, strlen(vlcevents[i].name)) == 0 )
             return &vlcevents[i];
     }
     return NULL;
 }
 
-const char *EventObj::find_name(const libvlc_event_t *event)
-{
-    for( size_t i = 0; i < ARRAY_SIZE(vlcevents); i++ )
-    {
-        if( vlcevents[i].libvlc_type == event->type )
-            return vlcevents[i].name;
-    }
-    return NULL;
-}
-
 bool EventObj::insert(const NPString &name, NPObject *listener, bool bubble)
 {
-    vlcplugin_event_t *event = find_event(name.UTF8Characters);
+    vlcplugin_event_t *event = find_event(name);
     if( !event )
         return false;
 
@@ -217,7 +207,7 @@ bool EventObj::insert(const NPString &name, NPObject *listener, bool bubble)
 
 bool EventObj::remove(const NPString &name, NPObject *listener, bool bubble)
 {
-    vlcplugin_event_t *event = find_event(name.UTF8Characters);
+    vlcplugin_event_t *event = find_event(name);
     if( !event )
         return false;
 
diff --git a/npapi/events.h b/npapi/events.h
index 75c1897..ff6e057 100644
--- a/npapi/events.h
+++ b/npapi/events.h
@@ -85,7 +85,7 @@ private:
         NPVariant *_npparams;
         uint32_t _npcount;
     };
-    libvlc_event_manager_t *_em; /* libvlc media_player event manager */
+
 public:
     EventObj(): _em(NULL), _already_in_deliver(false) { /* deferred to init() */ }
     bool init();
@@ -98,8 +98,9 @@ public:
     void unhook_manager(void *);
     void hook_manager(libvlc_event_manager_t *, void *);
 private:
-    vlcplugin_event_t *find_event(const char *s) const;
-    const char *find_name(const libvlc_event_t *event);
+    libvlc_event_manager_t *_em; /* libvlc media_player event manager */
+    vlcplugin_event_t *find_event(const NPString &name) const;
+
     typedef std::vector<Listener> lr_l;
     typedef std::vector<VLCEvent> ev_l;
     lr_l _llist; /* list of registered listeners with 'addEventListener' method */



More information about the vlc-commits mailing list