📄 simpleinport.java
字号:
package name.lxm.robot.arch;
public class SimpleInPort implements Port
{
String port_name;
Object value;
long update_timestamp = System.currentTimeMillis();
long valid_duration = 0;
long update_level = 0;
boolean bReady = false;
Module module = null;
ValueUpdateListener listener = null;
public SimpleInPort(Module module, String port_name)
{
this.module = module;
this.port_name = port_name;
}
public String getPortName()
{
return port_name;
}
public int getPortType()
{
return PT_I;
}
public void setValue(Module m, Object v, long duration)
{
if(m.getLayer() >= update_level || (System.currentTimeMillis() - update_timestamp) > valid_duration)
{
//do not care about the valide duration
value = v;
valid_duration = duration;
update_timestamp = System.currentTimeMillis();
bReady = true;
if(listener != null)
listener.valueUpdated();
}
}
/**
* Get the value from the wire, ignoring the life limitation
* @return the value
*/
public Object getValue()
{
if(bReady)
{
bReady = false;
return value;
}
return null;
}
/**
* Get the value from the wire, considering the life limitation
* @return the value
*/
public Object getValue2()
{
if((System.currentTimeMillis()-update_timestamp)<=valid_duration)
{
return value;
}
return null;
}
/**
* Register a listener, so that when an value come in,
* the owner of the listener can be notified;
* No need to unregister this listener; however if you
* really want to remove it, please use null as the input
* parameter.
*
* @param l - ValueUpdateListener
*/
public void registerListener(ValueUpdateListener l)
{
listener = l;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -