• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 package android.filterfw.core;
19 
20 /**
21  * @hide
22  */
23 public abstract class InputPort extends FilterPort {
24 
25     protected OutputPort mSourcePort;
26 
InputPort(Filter filter, String name)27     public InputPort(Filter filter, String name) {
28         super(filter, name);
29     }
30 
setSourcePort(OutputPort source)31     public void setSourcePort(OutputPort source) {
32         if (mSourcePort != null) {
33             throw new RuntimeException(this + " already connected to " + mSourcePort + "!");
34         }
35         mSourcePort = source;
36     }
37 
isConnected()38     public boolean isConnected() {
39         return mSourcePort != null;
40     }
41 
open()42     public void open() {
43         super.open();
44         if (mSourcePort != null && !mSourcePort.isOpen()) {
45             mSourcePort.open();
46         }
47     }
48 
close()49     public void close() {
50         if (mSourcePort != null && mSourcePort.isOpen()) {
51             mSourcePort.close();
52         }
53         super.close();
54     }
55 
getSourcePort()56     public OutputPort getSourcePort() {
57         return mSourcePort;
58     }
59 
getSourceFilter()60     public Filter getSourceFilter() {
61         return mSourcePort == null ? null : mSourcePort.getFilter();
62     }
63 
getSourceFormat()64     public FrameFormat getSourceFormat() {
65         return mSourcePort != null ? mSourcePort.getPortFormat() : getPortFormat();
66     }
67 
getTarget()68     public Object getTarget() {
69         return null;
70     }
71 
filterMustClose()72     public boolean filterMustClose() {
73         return !isOpen() && isBlocking() && !hasFrame();
74     }
75 
isReady()76     public boolean isReady() {
77         return hasFrame() || !isBlocking();
78     }
79 
acceptsFrame()80     public boolean acceptsFrame() {
81         return !hasFrame();
82     }
83 
transfer(FilterContext context)84     public abstract void transfer(FilterContext context);
85 }
86