Methods Summary |
---|
private final void | addAndSetFinalPorts(android.filterfw.core.KeyValueMap values)
Class filterClass = getClass();
Annotation annotation;
for (Field field : filterClass.getDeclaredFields()) {
if ((annotation = field.getAnnotation(GenerateFinalPort.class)) != null) {
GenerateFinalPort generator = (GenerateFinalPort)annotation;
String name = generator.name().isEmpty() ? field.getName() : generator.name();
boolean hasDefault = generator.hasDefault();
addFieldPort(name, field, hasDefault, true);
if (values.containsKey(name)) {
setImmediateInputValue(name, values.get(name));
values.remove(name);
} else if (!generator.hasDefault()) {
throw new RuntimeException("No value specified for final input port '"
+ name + "' of filter " + this + "!");
}
}
}
|
private final void | addAnnotatedPorts()
Class filterClass = getClass();
Annotation annotation;
for (Field field : filterClass.getDeclaredFields()) {
if ((annotation = field.getAnnotation(GenerateFieldPort.class)) != null) {
GenerateFieldPort generator = (GenerateFieldPort)annotation;
addFieldGenerator(generator, field);
} else if ((annotation = field.getAnnotation(GenerateProgramPort.class)) != null) {
GenerateProgramPort generator = (GenerateProgramPort)annotation;
addProgramGenerator(generator, field);
} else if ((annotation = field.getAnnotation(GenerateProgramPorts.class)) != null) {
GenerateProgramPorts generators = (GenerateProgramPorts)annotation;
for (GenerateProgramPort generator : generators.value()) {
addProgramGenerator(generator, field);
}
}
}
|
private final void | addFieldGenerator(GenerateFieldPort generator, java.lang.reflect.Field field)
String name = generator.name().isEmpty() ? field.getName() : generator.name();
boolean hasDefault = generator.hasDefault();
addFieldPort(name, field, hasDefault, false);
|
protected void | addFieldPort(java.lang.String name, java.lang.reflect.Field field, boolean hasDefault, boolean isFinal)
// Make sure field is accessible
field.setAccessible(true);
// Create port for this input
InputPort fieldPort = isFinal
? new FinalPort(this, name, field, hasDefault)
: new FieldPort(this, name, field, hasDefault);
// Create format for this input
if (mLogVerbose) Log.v(TAG, "Filter " + this + " adding " + fieldPort);
MutableFrameFormat format = ObjectFormat.fromClass(field.getType(),
FrameFormat.TARGET_SIMPLE);
fieldPort.setPortFormat(format);
// Add port
mInputPorts.put(name, fieldPort);
|
protected void | addInputPort(java.lang.String name)Adds an input port to the filter. You should call this from within setupPorts, if your
filter has input ports. No type-checking is performed on the input. If you would like to
check against a type mask, use
{@link #addMaskedInputPort(String, FrameFormat) addMaskedInputPort} instead.
addMaskedInputPort(name, null);
|
protected void | addMaskedInputPort(java.lang.String name, FrameFormat formatMask)Adds an input port to the filter. You should call this from within setupPorts, if your
filter has input ports. When type-checking is performed, the input format is
checked against the provided format mask. An exception is thrown in case of a conflict.
InputPort port = new StreamPort(this, name);
if (mLogVerbose) Log.v(TAG, "Filter " + this + " adding " + port);
mInputPorts.put(name, port);
port.setPortFormat(formatMask);
|
protected void | addOutputBasedOnInput(java.lang.String outputName, java.lang.String inputName)Adds an output port to the filter. You should call this from within setupPorts, if your
filter has output ports. Using this method indicates that the output format for this
particular port, depends on the format of an input port. You MUST also override
{@link #getOutputFormat(String, FrameFormat) getOutputFormat} to specify what format your
filter will output for a given input. If the output format of your filter port does not
depend on the input, use {@link #addOutputPort(String, FrameFormat) addOutputPort} instead.
OutputPort port = new OutputPort(this, outputName);
if (mLogVerbose) Log.v(TAG, "Filter " + this + " adding " + port);
port.setBasePort(getInputPort(inputName));
mOutputPorts.put(outputName, port);
|
protected void | addOutputPort(java.lang.String name, FrameFormat format)Adds an output port to the filter with a fixed output format. You should call this from
within setupPorts, if your filter has output ports. You cannot use this method, if your
output format depends on the input format (e.g. in a pass-through filter). In this case, use
{@link #addOutputBasedOnInput(String, String) addOutputBasedOnInput} instead.
OutputPort port = new OutputPort(this, name);
if (mLogVerbose) Log.v(TAG, "Filter " + this + " adding " + port);
port.setPortFormat(format);
mOutputPorts.put(name, port);
|
private final void | addProgramGenerator(GenerateProgramPort generator, java.lang.reflect.Field field)
String name = generator.name();
String varName = generator.variableName().isEmpty() ? name
: generator.variableName();
Class varType = generator.type();
boolean hasDefault = generator.hasDefault();
addProgramPort(name, varName, field, varType, hasDefault);
|
protected void | addProgramPort(java.lang.String name, java.lang.String varName, java.lang.reflect.Field field, java.lang.Class varType, boolean hasDefault)
// Make sure field is accessible
field.setAccessible(true);
// Create port for this input
InputPort programPort = new ProgramPort(this, name, varName, field, hasDefault);
// Create format for this input
if (mLogVerbose) Log.v(TAG, "Filter " + this + " adding " + programPort);
MutableFrameFormat format = ObjectFormat.fromClass(varType,
FrameFormat.TARGET_SIMPLE);
programPort.setPortFormat(format);
// Add port
mInputPorts.put(name, programPort);
|
final synchronized boolean | canProcess()
if (mLogVerbose) Log.v(TAG, "Checking if can process: " + this + " (" + mStatus + ").");
if (mStatus <= STATUS_PROCESSING) {
return inputConditionsMet() && outputConditionsMet();
} else {
return false;
}
|
final void | clearInputs()
for (InputPort inputPort : mInputPorts.values()) {
inputPort.clear();
}
|
final void | clearOutputs()
for (OutputPort outputPort : mOutputPorts.values()) {
outputPort.clear();
}
|
public void | close(android.filterfw.core.FilterContext context)
|
protected void | closeOutputPort(java.lang.String name)
getOutputPort(name).close();
|
private final void | closePorts()
if (mLogVerbose) Log.v(TAG, "Closing all ports on " + this + "!");
for (InputPort inputPort : mInputPorts.values()) {
inputPort.close();
}
for (OutputPort outputPort : mOutputPorts.values()) {
outputPort.close();
}
|
protected void | delayNextProcess(int millisecs)
mSleepDelay = millisecs;
mStatus = STATUS_SLEEPING;
|
public void | fieldPortValueUpdated(java.lang.String name, android.filterfw.core.FilterContext context)
|
private final boolean | filterMustClose()
for (InputPort inputPort : mInputPorts.values()) {
if (inputPort.filterMustClose()) {
if (mLogVerbose) Log.v(TAG, "Filter " + this + " must close due to port " + inputPort);
return true;
}
}
for (OutputPort outputPort : mOutputPorts.values()) {
if (outputPort.filterMustClose()) {
if (mLogVerbose) Log.v(TAG, "Filter " + this + " must close due to port " + outputPort);
return true;
}
}
return false;
|
public java.lang.String | getFilterClassName()
return getClass().getSimpleName();
|
public final FrameFormat | getInputFormat(java.lang.String portName)
InputPort inputPort = getInputPort(portName);
return inputPort.getSourceFormat();
|
public final InputPort | getInputPort(java.lang.String portName)
if (mInputPorts == null) {
throw new NullPointerException("Attempting to access input port '" + portName
+ "' of " + this + " before Filter has been initialized!");
}
InputPort result = mInputPorts.get(portName);
if (result == null) {
throw new IllegalArgumentException("Unknown input port '" + portName + "' on filter "
+ this + "!");
}
return result;
|
final java.util.Collection | getInputPorts()
return mInputPorts.values();
|
public final java.lang.String | getName()
return mName;
|
public final int | getNumberOfConnectedInputs()
int c = 0;
for (InputPort inputPort : mInputPorts.values()) {
if (inputPort.isConnected()) {
++c;
}
}
return c;
|
public final int | getNumberOfConnectedOutputs()
int c = 0;
for (OutputPort outputPort : mOutputPorts.values()) {
if (outputPort.isConnected()) {
++c;
}
}
return c;
|
public final int | getNumberOfInputs()
return mOutputPorts == null ? 0 : mInputPorts.size();
|
public final int | getNumberOfOutputs()
return mInputPorts == null ? 0 : mOutputPorts.size();
|
public FrameFormat | getOutputFormat(java.lang.String portName, FrameFormat inputFormat)
return null;
|
public final OutputPort | getOutputPort(java.lang.String portName)
if (mInputPorts == null) {
throw new NullPointerException("Attempting to access output port '" + portName
+ "' of " + this + " before Filter has been initialized!");
}
OutputPort result = mOutputPorts.get(portName);
if (result == null) {
throw new IllegalArgumentException("Unknown output port '" + portName + "' on filter "
+ this + "!");
}
return result;
|
final java.util.Collection | getOutputPorts()
return mOutputPorts.values();
|
public final int | getSleepDelay()
return 250;
|
final synchronized int | getStatus()
return mStatus;
|
public final void | init()
KeyValueMap valueMap = new KeyValueMap();
initWithValueMap(valueMap);
|
private final void | initFinalPorts(android.filterfw.core.KeyValueMap values)
mInputPorts = new HashMap<String, InputPort>();
mOutputPorts = new HashMap<String, OutputPort>();
addAndSetFinalPorts(values);
|
protected void | initProgramInputs(Program program, android.filterfw.core.FilterContext context)Assigns all program variables to the ports they are connected to. Call this after
constructing a Program instance with attached ProgramPorts.
if (program != null) {
for (InputPort inputPort : mInputPorts.values()) {
if (inputPort.getTarget() == program) {
inputPort.transfer(context);
}
}
}
|
private final void | initRemainingPorts(android.filterfw.core.KeyValueMap values)
addAnnotatedPorts();
setupPorts(); // TODO: rename to addFilterPorts() ?
setInitialInputValues(values);
|
public final void | initWithAssignmentList(java.lang.Object keyValues)
KeyValueMap valueMap = new KeyValueMap();
valueMap.setKeyValues(keyValues);
initWithValueMap(valueMap);
|
public final void | initWithAssignmentString(java.lang.String assignments)
try {
KeyValueMap valueMap = new TextGraphReader().readKeyValueAssignments(assignments);
initWithValueMap(valueMap);
} catch (GraphIOException e) {
throw new IllegalArgumentException(e.getMessage());
}
|
public final void | initWithValueMap(android.filterfw.core.KeyValueMap valueMap)
// Initialization
initFinalPorts(valueMap);
// Setup remaining ports
initRemainingPorts(valueMap);
// This indicates that final ports can no longer be set
mStatus = STATUS_UNPREPARED;
|
private final boolean | inputConditionsMet()
for (FilterPort port : mInputPorts.values()) {
if (!port.isReady()) {
if (mLogVerbose) Log.v(TAG, "Input condition not met: " + port + "!");
return false;
}
}
return true;
|
public static final boolean | isAvailable(java.lang.String filterName)Tests to see if a given filter is installed on the system. Requires
full filter package name, including filterpack.
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
Class filterClass;
// First see if a class of that name exists
try {
filterClass = contextClassLoader.loadClass(filterName);
} catch (ClassNotFoundException e) {
return false;
}
// Then make sure it's a subclass of Filter.
try {
filterClass.asSubclass(Filter.class);
} catch (ClassCastException e) {
return false;
}
return true;
|
public boolean | isOpen()
return mIsOpen;
|
final void | notifyFieldPortValueUpdated(java.lang.String name, android.filterfw.core.FilterContext context)
if (mStatus == STATUS_PROCESSING || mStatus == STATUS_PREPARED) {
fieldPortValueUpdated(name, context);
}
|
public void | open(android.filterfw.core.FilterContext context)
|
final void | openOutputs()
if (mLogVerbose) Log.v(TAG, "Opening all output ports on " + this + "!");
for (OutputPort outputPort : mOutputPorts.values()) {
if (!outputPort.isOpen()) {
outputPort.open();
}
}
|
private final boolean | outputConditionsMet()
for (FilterPort port : mOutputPorts.values()) {
if (!port.isReady()) {
if (mLogVerbose) Log.v(TAG, "Output condition not met: " + port + "!");
return false;
}
}
return true;
|
protected void | parametersUpdated(java.util.Set updated)
|
final synchronized void | performClose(android.filterfw.core.FilterContext context)
if (mIsOpen) {
if (mLogVerbose) Log.v(TAG, "Closing " + this);
mIsOpen = false;
mStatus = STATUS_PREPARED;
close(context);
closePorts();
}
|
final synchronized void | performOpen(android.filterfw.core.FilterContext context)
if (!mIsOpen) {
if (mStatus == STATUS_UNPREPARED) {
if (mLogVerbose) Log.v(TAG, "Preparing " + this);
prepare(context);
mStatus = STATUS_PREPARED;
}
if (mStatus == STATUS_PREPARED) {
if (mLogVerbose) Log.v(TAG, "Opening " + this);
open(context);
mStatus = STATUS_PROCESSING;
}
if (mStatus != STATUS_PROCESSING) {
throw new RuntimeException("Filter " + this + " was brought into invalid state during "
+ "opening (state: " + mStatus + ")!");
}
mIsOpen = true;
}
|
final synchronized void | performProcess(android.filterfw.core.FilterContext context)
if (mStatus == STATUS_RELEASED) {
throw new RuntimeException("Filter " + this + " is already torn down!");
}
transferInputFrames(context);
if (mStatus < STATUS_PROCESSING) {
performOpen(context);
}
if (mLogVerbose) Log.v(TAG, "Processing " + this);
mCurrentTimestamp = Frame.TIMESTAMP_UNKNOWN;
process(context);
releasePulledFrames(context);
if (filterMustClose()) {
performClose(context);
}
|
final synchronized void | performTearDown(android.filterfw.core.FilterContext context)
performClose(context);
if (mStatus != STATUS_RELEASED) {
tearDown(context);
mStatus = STATUS_RELEASED;
}
|
protected void | prepare(android.filterfw.core.FilterContext context)
|
public abstract void | process(android.filterfw.core.FilterContext context)
|
protected final Frame | pullInput(java.lang.String name)
Frame result = getInputPort(name).pullFrame();
if (mCurrentTimestamp == Frame.TIMESTAMP_UNKNOWN) {
mCurrentTimestamp = result.getTimestamp();
if (mLogVerbose) Log.v(TAG, "Default-setting current timestamp from input port " + name + " to " + mCurrentTimestamp);
}
// As result is retained, we add it to the release pool here
mFramesToRelease.add(result);
return result;
|
final synchronized void | pushInputFrame(java.lang.String inputName, Frame frame)
FilterPort port = getInputPort(inputName);
if (!port.isOpen()) {
port.open();
}
port.pushFrame(frame);
|
final synchronized void | pushInputValue(java.lang.String inputName, java.lang.Object value)
pushInputFrame(inputName, wrapInputValue(inputName, value));
|
protected final void | pushOutput(java.lang.String name, Frame frame)
if (frame.getTimestamp() == Frame.TIMESTAMP_NOT_SET) {
if (mLogVerbose) Log.v(TAG, "Default-setting output Frame timestamp on port " + name + " to " + mCurrentTimestamp);
frame.setTimestamp(mCurrentTimestamp);
}
getOutputPort(name).pushFrame(frame);
|
private final void | releasePulledFrames(android.filterfw.core.FilterContext context)
for (Frame frame : mFramesToRelease) {
context.getFrameManager().releaseFrame(frame);
}
mFramesToRelease.clear();
|
private final void | setImmediateInputValue(java.lang.String name, java.lang.Object value)
if (mLogVerbose) Log.v(TAG, "Setting immediate value " + value + " for port " + name + "!");
FilterPort port = getInputPort(name);
port.open();
port.setFrame(SimpleFrame.wrapObject(value, null));
|
private final void | setInitialInputValues(android.filterfw.core.KeyValueMap values)
for (Entry<String, Object> entry : values.entrySet()) {
setInputValue(entry.getKey(), entry.getValue());
}
|
public void | setInputFrame(java.lang.String inputName, Frame frame)
FilterPort port = getInputPort(inputName);
if (!port.isOpen()) {
port.open();
}
port.setFrame(frame);
|
public final void | setInputValue(java.lang.String inputName, java.lang.Object value)
setInputFrame(inputName, wrapInputValue(inputName, value));
|
protected void | setWaitsOnInputPort(java.lang.String portName, boolean waits)Specifies whether the filter should not be scheduled until a frame is available on that
input port. Note, that setting this to false, does not block a new frame from coming in
(though there is no necessity to pull that frame for processing).
getInputPort(portName).setBlocking(waits);
|
protected void | setWaitsOnOutputPort(java.lang.String portName, boolean waits)Specifies whether the filter should not be scheduled until the output port is free, i.e.
there is no frame waiting on that output.
getOutputPort(portName).setBlocking(waits);
|
public abstract void | setupPorts()
|
public void | tearDown(android.filterfw.core.FilterContext context)
|
public java.lang.String | toString()
return "'" + getName() + "' (" + getFilterClassName() + ")";
|
private final void | transferInputFrames(android.filterfw.core.FilterContext context)
for (InputPort inputPort : mInputPorts.values()) {
inputPort.transfer(context);
}
|
protected void | transferInputPortFrame(java.lang.String name, android.filterfw.core.FilterContext context)Transfers any frame from an input port to its destination. This is useful to force a
transfer from a FieldPort or ProgramPort to its connected target (field or program variable).
getInputPort(name).transfer(context);
|
final synchronized void | unsetStatus(int flag)
mStatus &= ~flag;
|
private final Frame | wrapInputValue(java.lang.String inputName, java.lang.Object value)
MutableFrameFormat inputFormat = ObjectFormat.fromObject(value, FrameFormat.TARGET_SIMPLE);
if (value == null) {
// If the value is null, the format cannot guess the class, so we adjust it to the
// class of the input port here
FrameFormat portFormat = getInputPort(inputName).getPortFormat();
Class portClass = (portFormat == null) ? null : portFormat.getObjectClass();
inputFormat.setObjectClass(portClass);
}
// Serialize if serializable, and type is not an immutable primitive.
boolean shouldSerialize = !(value instanceof Number)
&& !(value instanceof Boolean)
&& !(value instanceof String)
&& value instanceof Serializable;
// Create frame wrapper
Frame frame = shouldSerialize
? new SerializedFrame(inputFormat, null)
: new SimpleFrame(inputFormat, null);
frame.setObjectValue(value);
return frame;
|