[libbluray-devel] Added BDJActionManager (merge from dslibbluray)

hpi1 git at videolan.org
Tue Sep 18 12:23:47 CEST 2012


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Sat Sep 15 21:54:57 2012 +0300| [6c4a30c1e3a203fb2b3c052e1aefd61128ebd9d9] | committer: hpi1

Added BDJActionManager (merge from dslibbluray)

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

 src/libbluray/bdj/java/org/videolan/BDJAction.java |   86 ++++++++++++++++++++
 .../bdj/java/org/videolan/BDJActionManager.java    |   56 +++++++++++++
 .../bdj/java/org/videolan/BDJActionQueue.java      |   75 +++++++++++++++++
 3 files changed, 217 insertions(+)

diff --git a/src/libbluray/bdj/java/org/videolan/BDJAction.java b/src/libbluray/bdj/java/org/videolan/BDJAction.java
new file mode 100644
index 0000000..3e9d1f3
--- /dev/null
+++ b/src/libbluray/bdj/java/org/videolan/BDJAction.java
@@ -0,0 +1,86 @@
+/*
+ * This file is part of libbluray
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+package org.videolan;
+
+public abstract class BDJAction {
+    public BDJAction() {
+        this(BDJXletContext.getCurrentContext());
+    }
+
+    public BDJAction(BDJXletContext context) {
+        this.context = context;
+    }
+
+    public BDJXletContext getContext() {
+        return context;
+    }
+
+    public int getState() {
+        synchronized (this) {
+            return state;
+        }
+    }
+
+    public void waitBegin() {
+        synchronized (this) {
+            while (state == NOT_PROCESSED) {
+                try {
+                    this.wait();
+                } catch (InterruptedException e) {
+                }
+            }
+        }
+    }
+
+    public void waitEnd() {
+        synchronized (this) {
+            while (state != PROCESSED) {
+                try {
+                    this.wait();
+                } catch (InterruptedException e) {
+                }
+            }
+        }
+    }
+
+    public void process() {
+        synchronized (this) {
+            state = PROCESSING;
+            this.notifyAll();
+        }
+        try {
+            doAction();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        synchronized (this) {
+            state = PROCESSED;
+            this.notifyAll();
+        }
+    }
+
+    protected abstract void doAction();
+
+    private BDJXletContext context;
+    private int state = NOT_PROCESSED;
+
+    public static final int NOT_PROCESSED = 0;
+    public static final int PROCESSING = 1;
+    public static final int PROCESSED = 2;
+}
diff --git a/src/libbluray/bdj/java/org/videolan/BDJActionManager.java b/src/libbluray/bdj/java/org/videolan/BDJActionManager.java
new file mode 100644
index 0000000..2a2373b
--- /dev/null
+++ b/src/libbluray/bdj/java/org/videolan/BDJActionManager.java
@@ -0,0 +1,56 @@
+/*
+ * This file is part of libbluray
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+package org.videolan;
+
+public class BDJActionManager {
+    public static BDJActionManager getInstance() {
+        synchronized (BDJActionManager.class) {
+            if (instance == null)
+                instance = new BDJActionManager();
+        }
+        return instance;
+    }
+
+    public BDJActionManager() {
+        commandQueue = new BDJActionQueue();
+        callbackQueue = new BDJActionQueue();
+    }
+
+    protected void finalize() throws Throwable {
+        commandQueue.finalize();
+        callbackQueue.finalize();
+        synchronized (BDJActionManager.class) {
+            instance = null;
+        }
+        super.finalize();
+    }
+
+    public void putCommand(BDJAction action) {
+        commandQueue.put(action);
+    }
+
+    public void putCallback(BDJAction action) {
+        callbackQueue.put(action);
+    }
+
+    private BDJActionQueue commandQueue;
+    private BDJActionQueue callbackQueue;
+
+    private static BDJActionManager instance = null;
+}
diff --git a/src/libbluray/bdj/java/org/videolan/BDJActionQueue.java b/src/libbluray/bdj/java/org/videolan/BDJActionQueue.java
new file mode 100644
index 0000000..34822ab
--- /dev/null
+++ b/src/libbluray/bdj/java/org/videolan/BDJActionQueue.java
@@ -0,0 +1,75 @@
+/*
+ * This file is part of libbluray
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+package org.videolan;
+
+import java.util.LinkedList;
+
+public class BDJActionQueue implements Runnable {
+    public BDJActionQueue() {
+        group = new BDJThreadGroup("ActionQueue", null);
+        thread = new Thread(this);
+        thread.setDaemon(true);
+        thread.start();
+    }
+
+    protected void finalize() throws Throwable {
+        synchronized (actions) {
+            actions.addLast(null);
+            actions.notifyAll();
+        }
+        thread.join();
+        super.finalize();
+    }
+
+    public void run() {
+        while (true) {
+            Object action;
+            synchronized (actions) {
+                while (actions.isEmpty()) {
+                    try {
+                        actions.wait();
+                    } catch (InterruptedException e) {
+                    }
+                }
+                action = actions.removeFirst();
+            }
+            if (action == null)
+                return;
+            try {
+                group.setContext(((BDJAction)action).getContext());
+                ((BDJAction)action).process();
+            } catch (Throwable e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    public void put(BDJAction action) {
+        if (action != null) {
+            synchronized (actions) {
+                actions.addLast(action);
+                actions.notifyAll();
+            }
+        }
+    }
+
+    private BDJThreadGroup group;
+    private Thread thread;
+    private LinkedList actions = new LinkedList();
+}



More information about the libbluray-devel mailing list