OSDN Git Service

Renamed port classes to more intuitive names.
authorMarius Renn <renn@google.com>
Mon, 27 Jun 2011 22:21:40 +0000 (15:21 -0700)
committerMarius Renn <renn@google.com>
Mon, 27 Jun 2011 22:21:40 +0000 (15:21 -0700)
Ports are used internally only, so this does not change API.

Change-Id: I60a274ddd30bbb1f82d1b12980b6b95a07cb65ce

mca/filterfw/java/android/filterfw/core/FieldPort.java
mca/filterfw/java/android/filterfw/core/Filter.java
mca/filterfw/java/android/filterfw/core/FilterFunction.java
mca/filterfw/java/android/filterfw/core/FilterGraph.java
mca/filterfw/java/android/filterfw/core/InputPort.java
mca/filterfw/java/android/filterfw/core/OutputPort.java
mca/filterfw/java/android/filterfw/core/SourcePort.java [deleted file]
mca/filterfw/java/android/filterfw/core/StreamPort.java [new file with mode: 0644]
mca/filterfw/java/android/filterfw/core/TargetPort.java [deleted file]

index e421832..d0b6bb8 100644 (file)
@@ -19,7 +19,7 @@ package android.filterfw.core;
 
 import java.lang.reflect.Field;
 
-public class FieldPort extends TargetPort {
+public class FieldPort extends InputPort {
 
     protected Field mField;
     protected boolean mHasFrame;
index d4e495d..9ecc4ce 100644 (file)
@@ -50,8 +50,8 @@ public abstract class Filter {
     private int mInputCount = -1;
     private int mOutputCount = -1;
 
-    private HashMap<String, TargetPort> mInputPorts;
-    private HashMap<String, SourcePort> mOutputPorts;
+    private HashMap<String, InputPort> mInputPorts;
+    private HashMap<String, OutputPort> mOutputPorts;
 
     private HashSet<Frame> mFramesToRelease;
     private HashMap<String, Frame> mFramesToSet;
@@ -146,7 +146,7 @@ public abstract class Filter {
     }
 
     public final FrameFormat getInputFormat(String portName) {
-        TargetPort inputPort = getInputPort(portName);
+        InputPort inputPort = getInputPort(portName);
         return inputPort.getSourceFormat();
     }
 
@@ -167,7 +167,7 @@ public abstract class Filter {
 
     public final int getNumberOfConnectedInputs() {
         int c = 0;
-        for (TargetPort inputPort : mInputPorts.values()) {
+        for (InputPort inputPort : mInputPorts.values()) {
             if (inputPort.isConnected()) {
                 ++c;
             }
@@ -177,7 +177,7 @@ public abstract class Filter {
 
     public final int getNumberOfConnectedOutputs() {
         int c = 0;
-        for (SourcePort outputPort : mOutputPorts.values()) {
+        for (OutputPort outputPort : mOutputPorts.values()) {
             if (outputPort.isConnected()) {
                 ++c;
             }
@@ -193,8 +193,8 @@ public abstract class Filter {
         return mInputPorts == null ? 0 : mOutputPorts.size();
     }
 
-    public final TargetPort getInputPort(String portName) {
-        TargetPort result = mInputPorts.get(portName);
+    public final InputPort getInputPort(String portName) {
+        InputPort result = mInputPorts.get(portName);
         if (result == null) {
             throw new IllegalArgumentException("Unknown input port '" + portName + "' on filter "
                 + this + "!");
@@ -202,8 +202,8 @@ public abstract class Filter {
         return result;
     }
 
-    public final SourcePort getOutputPort(String portName) {
-        SourcePort result = mOutputPorts.get(portName);
+    public final OutputPort getOutputPort(String portName) {
+        OutputPort result = mOutputPorts.get(portName);
         if (result == null) {
             throw new IllegalArgumentException("Unknown output port '" + portName + "' on filter "
                 + this + "!");
@@ -248,7 +248,7 @@ public abstract class Filter {
      * @param formatMask a format mask, which filters the allowable input types
      */
     protected void addMaskedInputPort(String name, FrameFormat formatMask) {
-        TargetPort port = new InputPort(this, name);
+        InputPort port = new StreamPort(this, name);
         if (mLogVerbose) Log.v(TAG, "Filter " + this + " adding " + port);
         mInputPorts.put(name, port);
         port.setPortFormat(formatMask);
@@ -296,7 +296,7 @@ public abstract class Filter {
         field.setAccessible(true);
 
         // Create port for this input
-        TargetPort fieldPort = isFinal
+        InputPort fieldPort = isFinal
             ? new FinalPort(this, name, field, hasDefault)
             : new FieldPort(this, name, field, hasDefault);
 
@@ -319,7 +319,7 @@ public abstract class Filter {
         field.setAccessible(true);
 
         // Create port for this input
-        TargetPort programPort = new ProgramPort(this, name, varName, field, hasDefault);
+        InputPort programPort = new ProgramPort(this, name, varName, field, hasDefault);
 
         // Create format for this input
         if (mLogVerbose) Log.v(TAG, "Filter " + this + " adding " + programPort);
@@ -443,11 +443,11 @@ public abstract class Filter {
     }
 
     // Core internal methods ///////////////////////////////////////////////////////////////////////
-    final Collection<TargetPort> getInputPorts() {
+    final Collection<InputPort> getInputPorts() {
         return mInputPorts.values();
     }
 
-    final Collection<SourcePort> getOutputPorts() {
+    final Collection<OutputPort> getOutputPorts() {
         return mOutputPorts.values();
     }
 
@@ -513,7 +513,7 @@ public abstract class Filter {
 
     final void openOutputs() {
         if (mLogVerbose) Log.v(TAG, "Opening all output ports on " + this + "!");
-        for (SourcePort outputPort : mOutputPorts.values()) {
+        for (OutputPort outputPort : mOutputPorts.values()) {
             if (!outputPort.isOpen()) {
                 outputPort.open();
             }
@@ -528,8 +528,8 @@ public abstract class Filter {
 
     // Filter internal methods /////////////////////////////////////////////////////////////////////
     private final void initFinalPorts(KeyValueMap values) {
-        mInputPorts = new HashMap<String, TargetPort>();
-        mOutputPorts = new HashMap<String, SourcePort>();
+        mInputPorts = new HashMap<String, InputPort>();
+        mOutputPorts = new HashMap<String, OutputPort>();
         addAndSetFinalPorts(values);
     }
 
@@ -607,7 +607,7 @@ public abstract class Filter {
     }
 
     private final void transferInputFrames(FilterContext context) {
-        for (TargetPort inputPort : mInputPorts.values()) {
+        for (InputPort inputPort : mInputPorts.values()) {
             inputPort.transfer(context);
         }
     }
@@ -641,22 +641,22 @@ public abstract class Filter {
 
     private final void closePorts() {
         if (mLogVerbose) Log.v(TAG, "Closing all ports on " + this + "!");
-        for (TargetPort inputPort : mInputPorts.values()) {
+        for (InputPort inputPort : mInputPorts.values()) {
             inputPort.close();
         }
-        for (SourcePort outputPort : mOutputPorts.values()) {
+        for (OutputPort outputPort : mOutputPorts.values()) {
             outputPort.close();
         }
     }
 
     private final boolean filterMustClose() {
-        for (TargetPort inputPort : mInputPorts.values()) {
+        for (InputPort inputPort : mInputPorts.values()) {
             if (inputPort.filterMustClose()) {
                 if (mLogVerbose) Log.v(TAG, "Filter " + this + " must close due to port " + inputPort);
                 return true;
             }
         }
-        for (SourcePort outputPort : mOutputPorts.values()) {
+        for (OutputPort outputPort : mOutputPorts.values()) {
             if (outputPort.filterMustClose()) {
                 if (mLogVerbose) Log.v(TAG, "Filter " + this + " must close due to port " + outputPort);
                 return true;
index 43e3dc9..4cfd207 100644 (file)
@@ -26,7 +26,7 @@ public class FilterFunction {
     private boolean mFilterIsSetup = false;
     private FrameHolderPort[] mResultHolders;
 
-    private class FrameHolderPort extends InputPort {
+    private class FrameHolderPort extends StreamPort {
         public FrameHolderPort() {
             super(null, "holder");
         }
@@ -100,7 +100,7 @@ public class FilterFunction {
     private void connectFilterOutputs() {
         int  i = 0;
         mResultHolders = new FrameHolderPort[mFilter.getNumberOfOutputs()];
-        for (SourcePort outputPort : mFilter.getOutputPorts()) {
+        for (OutputPort outputPort : mFilter.getOutputPorts()) {
             mResultHolders[i] = new FrameHolderPort();
             outputPort.connectTo(mResultHolders[i]);
             ++i;
index ac45f61..002b2b9 100644 (file)
@@ -36,8 +36,8 @@ public class FilterGraph {
 
     private HashSet<Filter> mFilters = new HashSet<Filter>();
     private HashMap<String, Filter> mNameMap = new HashMap<String, Filter>();
-    private HashMap<SourcePort, LinkedList<TargetPort>> mPreconnections = new
-            HashMap<SourcePort, LinkedList<TargetPort>>();
+    private HashMap<OutputPort, LinkedList<InputPort>> mPreconnections = new
+            HashMap<OutputPort, LinkedList<InputPort>>();
 
     public static final int AUTOBRANCH_OFF      = 0;
     public static final int AUTOBRANCH_SYNCED   = 1;
@@ -81,8 +81,8 @@ public class FilterGraph {
             throw new RuntimeException("Attempting to connect filter not in graph!");
         }
 
-        SourcePort outPort = source.getOutputPort(outputName);
-        TargetPort inPort = target.getInputPort(inputName);
+        OutputPort outPort = source.getOutputPort(outputName);
+        InputPort inPort = target.getInputPort(inputName);
         if (outPort == null) {
             throw new RuntimeException("Unknown output port '" + outputName + "' on Filter " +
                                        source + "!");
@@ -149,7 +149,7 @@ public class FilterGraph {
         }
 
         // Check if all dependencies have been processed
-        for (TargetPort port : filter.getInputPorts()) {
+        for (InputPort port : filter.getInputPorts()) {
             Filter dependency = port.getSourceFilter();
             if (dependency != null && !processed.contains(dependency)) {
                 return false;
@@ -176,7 +176,7 @@ public class FilterGraph {
             runTypeCheckOn(filter, strict);
 
             // Push connected filters onto stack
-            for (SourcePort port : filter.getOutputPorts()) {
+            for (OutputPort port : filter.getOutputPorts()) {
                 Filter target = port.getTargetFilter();
                 if (target != null && readyForProcessing(target, processedFilters)) {
                     filterStack.push(target);
@@ -191,8 +191,8 @@ public class FilterGraph {
     }
 
     private void updateOutputs(Filter filter) {
-        for (SourcePort outputPort : filter.getOutputPorts()) {
-            TargetPort inputPort = outputPort.getBasePort();
+        for (OutputPort outputPort : filter.getOutputPorts()) {
+            InputPort inputPort = outputPort.getBasePort();
             if (inputPort != null) {
                 FrameFormat inputFormat = inputPort.getSourceFormat();
                 FrameFormat outputFormat = filter.getOutputFormat(outputPort.getName(),
@@ -207,7 +207,7 @@ public class FilterGraph {
     }
 
     private void runTypeCheckOn(Filter filter, boolean strict) {
-        for (TargetPort inputPort : filter.getInputPorts()) {
+        for (InputPort inputPort : filter.getInputPorts()) {
             if (mLogVerbose) Log.v(TAG, "Type checking port " + inputPort);
             FrameFormat sourceFormat = inputPort.getSourceFormat();
             FrameFormat targetFormat = inputPort.getPortFormat();
@@ -233,7 +233,7 @@ public class FilterGraph {
         LinkedList<Filter> addedFilters = new LinkedList<Filter>();
         for (Filter filter : mFilters) {
             int id = 0;
-            for (SourcePort port : filter.getOutputPorts()) {
+            for (OutputPort port : filter.getOutputPorts()) {
                 if (!port.isConnected()) {
                     if (mLogVerbose) Log.v(TAG, "Autoconnecting unconnected " + port + " to Null filter.");
                     NullFilter nullFilter = new NullFilter(filter.getName() + "ToNull" + id);
@@ -255,11 +255,11 @@ public class FilterGraph {
         mNameMap.remove(filter.getName());
     }
 
-    private void preconnect(SourcePort outPort, TargetPort inPort) {
-        LinkedList<TargetPort> targets;
+    private void preconnect(OutputPort outPort, InputPort inPort) {
+        LinkedList<InputPort> targets;
         targets = mPreconnections.get(outPort);
         if (targets == null) {
-            targets = new LinkedList<TargetPort>();
+            targets = new LinkedList<InputPort>();
             mPreconnections.put(outPort, targets);
         }
         targets.add(inPort);
@@ -267,16 +267,16 @@ public class FilterGraph {
 
     private void connectPorts() {
         int branchId = 1;
-        for (Entry<SourcePort, LinkedList<TargetPort>> connection : mPreconnections.entrySet()) {
-            SourcePort sourcePort = connection.getKey();
-            LinkedList<TargetPort> targetPorts = connection.getValue();
-            if (targetPorts.size() == 1) {
-                sourcePort.connectTo(targetPorts.get(0));
+        for (Entry<OutputPort, LinkedList<InputPort>> connection : mPreconnections.entrySet()) {
+            OutputPort outputPort = connection.getKey();
+            LinkedList<InputPort> inputPorts = connection.getValue();
+            if (inputPorts.size() == 1) {
+                outputPort.connectTo(inputPorts.get(0));
             } else if (mAutoBranchMode == AUTOBRANCH_OFF) {
-                throw new RuntimeException("Attempting to connect " + sourcePort + " to multiple "
+                throw new RuntimeException("Attempting to connect " + outputPort + " to multiple "
                                          + "filter ports! Enable auto-branching to allow this.");
             } else {
-                if (mLogVerbose) Log.v(TAG, "Creating branch for " + sourcePort + "!");
+                if (mLogVerbose) Log.v(TAG, "Creating branch for " + outputPort + "!");
                 FrameBranch branch = null;
                 if (mAutoBranchMode == AUTOBRANCH_SYNCED) {
                     branch = new FrameBranch("branch" + branchId++);
@@ -284,12 +284,12 @@ public class FilterGraph {
                     throw new RuntimeException("TODO: Unsynced branches not implemented yet!");
                 }
                 KeyValueMap branchParams = new KeyValueMap();
-                branch.initWithAssignmentList("outputs", targetPorts.size());
+                branch.initWithAssignmentList("outputs", inputPorts.size());
                 addFilter(branch);
-                sourcePort.connectTo(branch.getInputPort("in"));
-                Iterator<TargetPort> targetPortIter = targetPorts.iterator();
-                for (SourcePort branchOutPort : ((Filter)branch).getOutputPorts()) {
-                    branchOutPort.connectTo(targetPortIter.next());
+                outputPort.connectTo(branch.getInputPort("in"));
+                Iterator<InputPort> inputPortIter = inputPorts.iterator();
+                for (OutputPort branchOutPort : ((Filter)branch).getOutputPorts()) {
+                    branchOutPort.connectTo(inputPortIter.next());
                 }
             }
         }
index b7438d3..648cd3e 100644 (file)
 
 package android.filterfw.core;
 
-public class InputPort extends TargetPort {
+public abstract class InputPort extends FilterPort {
 
-    private Frame mFrame;
-    private boolean mPersistent;
+    protected OutputPort mSourcePort;
 
     public InputPort(Filter filter, String name) {
         super(filter, name);
     }
 
-    @Override
-    public void clear() {
-        if (mFrame != null) {
-            mFrame.release();
-            mFrame = null;
+    public void setSourcePort(OutputPort source) {
+        if (mSourcePort != null) {
+            throw new RuntimeException(this + " already connected to " + mSourcePort + "!");
         }
+        mSourcePort = source;
     }
 
-    @Override
-    public void setFrame(Frame frame) {
-        assignFrame(frame, true);
+    public boolean isConnected() {
+        return mSourcePort != null;
     }
 
-    @Override
-    public void pushFrame(Frame frame) {
-        assignFrame(frame, false);
+    public void open() {
+        super.open();
+        if (mSourcePort != null && !mSourcePort.isOpen()) {
+            mSourcePort.open();
+        }
     }
 
-    private void assignFrame(Frame frame, boolean persistent) {
-        assertPortIsOpen();
-        if (persistent) {
-            if (mFrame != null) {
-                mFrame.release();
-            }
-        } else if (mFrame != null) {
-            throw new RuntimeException(
-                "Attempting to push more than one frame on port: " + this + "!");
+    public void close() {
+        if (mSourcePort != null && mSourcePort.isOpen()) {
+            mSourcePort.close();
         }
-        mFrame = frame.retain();
-        mFrame.markReadOnly();
-        mPersistent = persistent;
+        super.close();
     }
 
-    @Override
-    public Frame pullFrame() {
-        // Make sure we have a frame
-        if (mFrame == null) {
-            throw new RuntimeException("No frame available to pull on port: " + this + "!");
-        }
+    public OutputPort getSourcePort() {
+        return mSourcePort;
+    }
 
-        // Return a retained result
-        Frame result = mFrame;
-        if (mPersistent) {
-            mFrame.retain();
-        } else {
-            mFrame = null;
-        }
-        return result;
+    public Filter getSourceFilter() {
+        return mSourcePort == null ? null : mSourcePort.getFilter();
+    }
+
+    public FrameFormat getSourceFormat() {
+        return mSourcePort != null ? mSourcePort.getPortFormat() : getPortFormat();
+    }
+
+    public boolean filterMustClose() {
+        return !isOpen() && isBlocking() && !hasFrame();
     }
 
-    @Override
-    public boolean hasFrame() {
-        return mFrame != null;
+    public boolean isReady() {
+        return hasFrame() || !isBlocking();
     }
 
-    @Override
-    public String toString() {
-        return "input " + super.toString();
+    public void transfer(FilterContext context) {
     }
 }
index 08859fd..8de0791 100644 (file)
 
 package android.filterfw.core;
 
-public class OutputPort extends SourcePort {
+public class OutputPort extends FilterPort {
+
+    protected InputPort mTargetPort;
+    protected InputPort mBasePort;
 
     public OutputPort(Filter filter, String name) {
         super(filter, name);
     }
 
+    public void connectTo(InputPort target) {
+        if (mTargetPort != null) {
+            throw new RuntimeException(this + " already connected to " + mTargetPort + "!");
+        }
+        mTargetPort = target;
+        mTargetPort.setSourcePort(this);
+    }
+
+    public boolean isConnected() {
+        return mTargetPort != null;
+    }
+
+    public void open() {
+        super.open();
+        if (mTargetPort != null && !mTargetPort.isOpen()) {
+            mTargetPort.open();
+        }
+    }
+
+    public void close() {
+        super.close();
+        if (mTargetPort != null && mTargetPort.isOpen()) {
+            mTargetPort.close();
+        }
+    }
+
+    public InputPort getTargetPort() {
+        return mTargetPort;
+    }
+
+    public Filter getTargetFilter() {
+        return mTargetPort == null ? null : mTargetPort.getFilter();
+    }
+
+    public void setBasePort(InputPort basePort) {
+        mBasePort = basePort;
+    }
+
+    public InputPort getBasePort() {
+        return mBasePort;
+    }
+
+    public boolean filterMustClose() {
+        return !isOpen() && isBlocking();
+    }
+
+    public boolean isReady() {
+        return (isOpen() && !hasFrame()) || !isBlocking();
+    }
+
     @Override
     public void clear() {
         if (mTargetPort != null) {
diff --git a/mca/filterfw/java/android/filterfw/core/SourcePort.java b/mca/filterfw/java/android/filterfw/core/SourcePort.java
deleted file mode 100644 (file)
index 3a7fa3f..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package android.filterfw.core;
-
-public abstract class SourcePort extends FilterPort {
-
-    protected TargetPort mTargetPort;
-    protected TargetPort mBasePort;
-
-    public SourcePort(Filter filter, String name) {
-        super(filter, name);
-    }
-
-    public void connectTo(TargetPort target) {
-        if (mTargetPort != null) {
-            throw new RuntimeException(this + " already connected to " + mTargetPort + "!");
-        }
-        mTargetPort = target;
-        mTargetPort.setSourcePort(this);
-    }
-
-    public boolean isConnected() {
-        return mTargetPort != null;
-    }
-
-    public void open() {
-        super.open();
-        if (mTargetPort != null && !mTargetPort.isOpen()) {
-            mTargetPort.open();
-        }
-    }
-
-    public void close() {
-        super.close();
-        if (mTargetPort != null && mTargetPort.isOpen()) {
-            mTargetPort.close();
-        }
-    }
-
-    public TargetPort getTargetPort() {
-        return mTargetPort;
-    }
-
-    public Filter getTargetFilter() {
-        return mTargetPort == null ? null : mTargetPort.getFilter();
-    }
-
-    public void setBasePort(TargetPort basePort) {
-        mBasePort = basePort;
-    }
-
-    public TargetPort getBasePort() {
-        return mBasePort;
-    }
-
-    public boolean filterMustClose() {
-        return !isOpen() && isBlocking();
-    }
-
-    public boolean isReady() {
-        return (isOpen() && !hasFrame()) || !isBlocking();
-    }
-
-}
diff --git a/mca/filterfw/java/android/filterfw/core/StreamPort.java b/mca/filterfw/java/android/filterfw/core/StreamPort.java
new file mode 100644 (file)
index 0000000..3bc6986
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package android.filterfw.core;
+
+public class StreamPort extends InputPort {
+
+    private Frame mFrame;
+    private boolean mPersistent;
+
+    public StreamPort(Filter filter, String name) {
+        super(filter, name);
+    }
+
+    @Override
+    public void clear() {
+        if (mFrame != null) {
+            mFrame.release();
+            mFrame = null;
+        }
+    }
+
+    @Override
+    public void setFrame(Frame frame) {
+        assignFrame(frame, true);
+    }
+
+    @Override
+    public void pushFrame(Frame frame) {
+        assignFrame(frame, false);
+    }
+
+    private void assignFrame(Frame frame, boolean persistent) {
+        assertPortIsOpen();
+        if (persistent) {
+            if (mFrame != null) {
+                mFrame.release();
+            }
+        } else if (mFrame != null) {
+            throw new RuntimeException(
+                "Attempting to push more than one frame on port: " + this + "!");
+        }
+        mFrame = frame.retain();
+        mFrame.markReadOnly();
+        mPersistent = persistent;
+    }
+
+    @Override
+    public Frame pullFrame() {
+        // Make sure we have a frame
+        if (mFrame == null) {
+            throw new RuntimeException("No frame available to pull on port: " + this + "!");
+        }
+
+        // Return a retained result
+        Frame result = mFrame;
+        if (mPersistent) {
+            mFrame.retain();
+        } else {
+            mFrame = null;
+        }
+        return result;
+    }
+
+    @Override
+    public boolean hasFrame() {
+        return mFrame != null;
+    }
+
+    @Override
+    public String toString() {
+        return "input " + super.toString();
+    }
+}
diff --git a/mca/filterfw/java/android/filterfw/core/TargetPort.java b/mca/filterfw/java/android/filterfw/core/TargetPort.java
deleted file mode 100644 (file)
index 1325ea7..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package android.filterfw.core;
-
-public abstract class TargetPort extends FilterPort {
-
-    protected SourcePort mSourcePort;
-
-    public TargetPort(Filter filter, String name) {
-        super(filter, name);
-    }
-
-    public void setSourcePort(SourcePort source) {
-        if (mSourcePort != null) {
-            throw new RuntimeException(this + " already connected to " + mSourcePort + "!");
-        }
-        mSourcePort = source;
-    }
-
-    public boolean isConnected() {
-        return mSourcePort != null;
-    }
-
-    public void open() {
-        super.open();
-        if (mSourcePort != null && !mSourcePort.isOpen()) {
-            mSourcePort.open();
-        }
-    }
-
-    public void close() {
-        if (mSourcePort != null && mSourcePort.isOpen()) {
-            mSourcePort.close();
-        }
-        super.close();
-    }
-
-    public SourcePort getSourcePort() {
-        return mSourcePort;
-    }
-
-    public Filter getSourceFilter() {
-        return mSourcePort == null ? null : mSourcePort.getFilter();
-    }
-
-    public FrameFormat getSourceFormat() {
-        return mSourcePort != null ? mSourcePort.getPortFormat() : getPortFormat();
-    }
-
-    public boolean filterMustClose() {
-        return !isOpen() && isBlocking() && !hasFrame();
-    }
-
-    public boolean isReady() {
-        return hasFrame() || !isBlocking();
-    }
-
-    public void transfer(FilterContext context) {
-    }
-}