[libbluray-devel] Fix using wrong context for org.dvb.application.AppsDatabase events

hpi1 git at videolan.org
Wed Dec 3 14:26:34 CET 2014


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Wed Dec  3 15:24:35 2014 +0200| [6328d625408d9cac452ee0ae0244b934e8e72fd8] | committer: hpi1

Fix using wrong context for org.dvb.application.AppsDatabase events

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=6328d625408d9cac452ee0ae0244b934e8e72fd8
---

 .../bdj/java/org/dvb/application/AppsDatabase.java |   33 +++-----------------
 .../bdj/java/org/videolan/BDJListeners.java        |   20 ++++++++++++
 2 files changed, 25 insertions(+), 28 deletions(-)

diff --git a/src/libbluray/bdj/java/org/dvb/application/AppsDatabase.java b/src/libbluray/bdj/java/org/dvb/application/AppsDatabase.java
index acdc684..daf92c2 100644
--- a/src/libbluray/bdj/java/org/dvb/application/AppsDatabase.java
+++ b/src/libbluray/bdj/java/org/dvb/application/AppsDatabase.java
@@ -22,6 +22,7 @@ package org.dvb.application;
 import java.util.LinkedList;
 import java.util.Enumeration;
 import org.videolan.BDJAppsDatabase;
+import org.videolan.BDJListeners;
 import org.videolan.Logger;
 
 public class AppsDatabase {
@@ -55,41 +56,17 @@ public class AppsDatabase {
     }
 
     public void addListener(AppsDatabaseEventListener listener) {
-        synchronized(listeners) {
-            listeners.add(listener);
-        }
+        listeners.add(listener);
     }
 
     public void removeListener(AppsDatabaseEventListener listener) {
-        synchronized(listeners) {
-            listeners.remove(listener);
-        }
+        listeners.remove(listener);
     }
 
     protected void notifyListeners(int id, AppID appid) {
-        LinkedList list;
-        synchronized(listeners) {
-            list = (LinkedList)listeners.clone();
-        }
-        AppsDatabaseEvent event = new AppsDatabaseEvent(id, appid, this);
-        for (int i = 0; i < list.size(); i++) {
-            switch (id) {
-            case AppsDatabaseEvent.APP_ADDED:
-                ((AppsDatabaseEventListener)list.get(i)).entryAdded(event);
-                break;
-            case AppsDatabaseEvent.APP_CHANGED:
-                ((AppsDatabaseEventListener)list.get(i)).entryChanged(event);
-                break;
-            case AppsDatabaseEvent.APP_DELETED:
-                ((AppsDatabaseEventListener)list.get(i)).entryRemoved(event);
-                break;
-            case AppsDatabaseEvent.NEW_DATABASE:
-                ((AppsDatabaseEventListener)list.get(i)).newDatabase(event);
-                break;
-            }
-        }
+        listeners.putCallback(new AppsDatabaseEvent(id, appid, this));
     }
 
-    private LinkedList listeners = new LinkedList();
+    private BDJListeners listeners = new BDJListeners();
     private static final Logger logger = Logger.getLogger(AppsDatabase.class.getName());
 }
diff --git a/src/libbluray/bdj/java/org/videolan/BDJListeners.java b/src/libbluray/bdj/java/org/videolan/BDJListeners.java
index d40901a..eda3ed0 100644
--- a/src/libbluray/bdj/java/org/videolan/BDJListeners.java
+++ b/src/libbluray/bdj/java/org/videolan/BDJListeners.java
@@ -44,6 +44,8 @@ import org.bluray.media.UOMaskedEvent;
 import org.davic.resources.ResourceStatusEvent;
 import org.davic.resources.ResourceStatusListener;
 
+import org.dvb.application.AppsDatabaseEvent;
+import org.dvb.application.AppsDatabaseEventListener;
 import org.dvb.media.SubtitleListener;
 import java.util.EventObject;
 
@@ -150,6 +152,24 @@ public class BDJListeners {
             } else if (event instanceof ResourceStatusEvent) {
                 ((ResourceStatusListener)listener).statusChanged((ResourceStatusEvent)event);
 
+            } else if (event instanceof AppsDatabaseEvent) {
+                AppsDatabaseEvent dbevent = (AppsDatabaseEvent)event;
+                AppsDatabaseEventListener dblistener = (AppsDatabaseEventListener)listener;
+                switch (dbevent.getEventId()) {
+                case AppsDatabaseEvent.APP_ADDED:
+                    dblistener.entryAdded(dbevent);
+                    break;
+                case AppsDatabaseEvent.APP_CHANGED:
+                    dblistener.entryChanged(dbevent);
+                    break;
+                case AppsDatabaseEvent.APP_DELETED:
+                    dblistener.entryRemoved(dbevent);
+                    break;
+                case AppsDatabaseEvent.NEW_DATABASE:
+                    dblistener.newDatabase(dbevent);
+                    break;
+                }
+
             /* need to use wrapper if some other callback uses EventObject */
             } else if (event instanceof EventObject &&
                        listener instanceof SubtitleListener) {



More information about the libbluray-devel mailing list