Remove wpiutil and update to the new build system (#210)

This commit is contained in:
Thad House
2017-08-03 14:14:40 -07:00
committed by Peter Johnson
parent f43675e2bd
commit 5df7463663
168 changed files with 670 additions and 16084 deletions

View File

@@ -0,0 +1,17 @@
package edu.wpi.first.wpilibj.networktables;
public class ConnectionInfo {
public final String remote_id;
public final String remote_ip;
public final int remote_port;
public final long last_update;
public final int protocol_version;
public ConnectionInfo(String remote_id, String remote_ip, int remote_port, long last_update, int protocol_version) {
this.remote_id = remote_id;
this.remote_ip = remote_ip;
this.remote_port = remote_port;
this.last_update = last_update;
this.protocol_version = protocol_version;
}
}

View File

@@ -0,0 +1,15 @@
package edu.wpi.first.wpilibj.networktables;
public class EntryInfo {
public final String name;
public final int type;
public final int flags;
public final long last_change;
public EntryInfo(String name, int type, int flags, long last_change) {
this.name = name;
this.type = type;
this.flags = flags;
this.last_change = last_change;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,23 @@
package edu.wpi.first.wpilibj.networktables;
import edu.wpi.first.wpilibj.tables.TableKeyNotDefinedException;
/**
* An exception throw when the lookup a a key-value fails in a {@link NetworkTable}
*
* @deprecated to provide backwards compatability for new api
*
* @author Mitchell
*
*/
@Deprecated
public class NetworkTableKeyNotDefined extends TableKeyNotDefinedException {
/**
* @param key the key that was not defined in the table
*/
public NetworkTableKeyNotDefined(String key) {
super(key);
}
}

View File

@@ -0,0 +1,171 @@
package edu.wpi.first.wpilibj.networktables;
import edu.wpi.first.wpilibj.tables.*;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import edu.wpi.first.wpiutil.RuntimeDetector;
public class NetworkTablesJNI {
static boolean libraryLoaded = false;
static File jniLibrary = null;
static {
if (!libraryLoaded) {
try {
System.loadLibrary("ntcore");
} catch (UnsatisfiedLinkError e) {
try {
String resname = RuntimeDetector.getLibraryResource("ntcore");
InputStream is = NetworkTablesJNI.class.getResourceAsStream(resname);
if (is != null) {
// create temporary file
if (System.getProperty("os.name").startsWith("Windows"))
jniLibrary = File.createTempFile("NetworkTablesJNI", ".dll");
else if (System.getProperty("os.name").startsWith("Mac"))
jniLibrary = File.createTempFile("libNetworkTablesJNI", ".dylib");
else
jniLibrary = File.createTempFile("libNetworkTablesJNI", ".so");
// flag for delete on exit
jniLibrary.deleteOnExit();
OutputStream os = new FileOutputStream(jniLibrary);
byte[] buffer = new byte[1024];
int readBytes;
try {
while ((readBytes = is.read(buffer)) != -1) {
os.write(buffer, 0, readBytes);
}
} finally {
os.close();
is.close();
}
System.load(jniLibrary.getAbsolutePath());
} else {
System.loadLibrary("ntcore");
}
} catch (IOException ex) {
ex.printStackTrace();
System.exit(1);
}
}
libraryLoaded = true;
}
}
public static final int NT_NET_MODE_NONE = 0x00;
public static final int NT_NET_MODE_SERVER = 0x01;
public static final int NT_NET_MODE_CLIENT = 0x02;
public static final int NT_NET_MODE_STARTING = 0x04;
public static final int NT_NET_MODE_FAILURE = 0x08;
public static native boolean containsKey(String key);
public static native int getType(String key);
public static native boolean putBoolean(String key, boolean value);
public static native boolean putDouble(String key, double value);
public static native boolean putString(String key, String value);
public static native boolean putRaw(String key, byte[] value);
public static native boolean putRaw(String key, ByteBuffer value, int len);
public static native boolean putBooleanArray(String key, boolean[] value);
public static native boolean putDoubleArray(String key, double[] value);
public static native boolean putStringArray(String key, String[] value);
public static native void forcePutBoolean(String key, boolean value);
public static native void forcePutDouble(String key, double value);
public static native void forcePutString(String key, String value);
public static native void forcePutRaw(String key, byte[] value);
public static native void forcePutRaw(String key, ByteBuffer value, int len);
public static native void forcePutBooleanArray(String key, boolean[] value);
public static native void forcePutDoubleArray(String key, double[] value);
public static native void forcePutStringArray(String key, String[] value);
public static native Object getValue(String key) throws TableKeyNotDefinedException;
public static native boolean getBoolean(String key) throws TableKeyNotDefinedException;
public static native double getDouble(String key) throws TableKeyNotDefinedException;
public static native String getString(String key) throws TableKeyNotDefinedException;
public static native byte[] getRaw(String key) throws TableKeyNotDefinedException;
public static native boolean[] getBooleanArray(String key) throws TableKeyNotDefinedException;
public static native double[] getDoubleArray(String key) throws TableKeyNotDefinedException;
public static native String[] getStringArray(String key) throws TableKeyNotDefinedException;
public static native Object getValue(String key, Object defaultValue);
public static native boolean getBoolean(String key, boolean defaultValue);
public static native double getDouble(String key, double defaultValue);
public static native String getString(String key, String defaultValue);
public static native byte[] getRaw(String key, byte[] defaultValue);
public static native boolean[] getBooleanArray(String key, boolean[] defaultValue);
public static native double[] getDoubleArray(String key, double[] defaultValue);
public static native String[] getStringArray(String key, String[] defaultValue);
public static native boolean setDefaultBoolean(String key, boolean defaultValue);
public static native boolean setDefaultDouble(String key, double defaultValue);
public static native boolean setDefaultString(String key, String defaultValue);
public static native boolean setDefaultRaw(String key, byte[] defaultValue);
public static native boolean setDefaultBooleanArray(String key, boolean[] defaultValue);
public static native boolean setDefaultDoubleArray(String key, double[] defaultValue);
public static native boolean setDefaultStringArray(String key, String[] defaultValue);
public static native void setEntryFlags(String key, int flags);
public static native int getEntryFlags(String key);
public static native void deleteEntry(String key);
public static native void deleteAllEntries();
public static native EntryInfo[] getEntries(String prefix, int types);
public static native void flush();
@FunctionalInterface
public interface EntryListenerFunction {
void apply(int uid, String key, Object value, int flags);
}
public static native int addEntryListener(String prefix, EntryListenerFunction listener, int flags);
public static native void removeEntryListener(int entryListenerUid);
@FunctionalInterface
public interface ConnectionListenerFunction {
void apply(int uid, boolean connected, ConnectionInfo conn);
}
public static native int addConnectionListener(ConnectionListenerFunction listener, boolean immediateNotify);
public static native void removeConnectionListener(int connListenerUid);
// public static native void createRpc(String key, byte[] def, IRpc rpc);
// public static native void createRpc(String key, ByteBuffer def, int def_len, IRpc rpc);
public static native byte[] getRpc(String key) throws TableKeyNotDefinedException;
public static native byte[] getRpc(String key, byte[] defaultValue);
public static native int callRpc(String key, byte[] params);
public static native int callRpc(String key, ByteBuffer params, int params_len);
// public static native byte[] getRpcResultBlocking(int callUid);
// public static native byte[] getRpcResultNonblocking(int callUid) throws RpcNoResponseException;
public static native void setNetworkIdentity(String name);
public static native int getNetworkMode();
public static native void startServer(String persistFilename, String listenAddress, int port);
public static native void stopServer();
public static native void startClient();
public static native void startClient(String serverName, int port);
public static native void startClient(String[] serverNames, int[] ports);
public static native void stopClient();
public static native void setServer(String serverName, int port);
public static native void setServer(String[] serverNames, int[] ports);
public static native void startDSClient(int port);
public static native void stopDSClient();
public static native void setUpdateRate(double interval);
public static native ConnectionInfo[] getConnections();
public static native void savePersistent(String filename) throws PersistentException;
public static native String[] loadPersistent(String filename) throws PersistentException; // returns warnings
public static native long now();
@FunctionalInterface
public interface LoggerFunction {
void apply(int level, String file, int line, String msg);
}
public static native void setLogger(LoggerFunction func, int minLevel);
}

View File

@@ -0,0 +1,18 @@
package edu.wpi.first.wpilibj.networktables;
import java.io.IOException;
/**
* An exception thrown when persistent load/save fails in a {@link NetworkTable}
*
*/
public class PersistentException extends IOException {
/**
* @param message The error message
*/
public PersistentException(String message) {
super(message);
}
}

View File

@@ -0,0 +1,50 @@
package edu.wpi.first.wpilibj.networktables2.type;
/**
* @deprecated Use ArrayList instead.
*/
@Deprecated
public class ArrayData {
private Object[] data = new Object[0];
protected Object getAsObject(int index) {
return data[index];
}
protected void _set(int index, Object value) {
data[index] = value;
}
protected void _add(Object value) {
setSize(size() + 1);
data[size() - 1] = value;
}
public void remove(int index) {
if (index < 0 || index >= size())
throw new IndexOutOfBoundsException();
if (index < size() - 1)
System.arraycopy(data, index + 1, data, index, size() - index - 1);
setSize(size() - 1);
}
public void setSize(int size) {
if (size == data.length)
return;
Object[] newArray = new Object[size];
if (size < data.length)
System.arraycopy(data, 0, newArray, 0, size);
else {
System.arraycopy(data, 0, newArray, 0, data.length);
for (int i = data.length; i < newArray.length; ++i)
newArray[i] = null;
}
data = newArray;
}
public int size() {
return data.length;
}
public Object[] getDataArray() {
return data;
}
public void setDataArray(Object[] value) {
data = value;
}
}

View File

@@ -0,0 +1,17 @@
package edu.wpi.first.wpilibj.networktables2.type;
/**
* @deprecated Use {@literal ArrayList<Boolean>} instead.
*/
@Deprecated
public class BooleanArray extends ArrayData {
public boolean get(int index) {
return ((Boolean)getAsObject(index)).booleanValue();
}
public void set(int index, boolean value) {
_set(index, value?Boolean.TRUE:Boolean.FALSE);
}
public void add(boolean value) {
_add(value?Boolean.TRUE:Boolean.FALSE);
}
}

View File

@@ -0,0 +1,17 @@
package edu.wpi.first.wpilibj.networktables2.type;
/**
* @deprecated Use {@literal ArrayList<Double>} instead.
*/
@Deprecated
public class NumberArray extends ArrayData {
public double get(int index) {
return ((Double)getAsObject(index)).doubleValue();
}
public void set(int index, double value) {
_set(index, new Double(value));
}
public void add(double value) {
_add(new Double(value));
}
}

View File

@@ -0,0 +1,17 @@
package edu.wpi.first.wpilibj.networktables2.type;
/**
* @deprecated Use {@literal ArrayList<String>} instead.
*/
@Deprecated
public class StringArray extends ArrayData {
public String get(int index) {
return ((String)getAsObject(index));
}
public void set(int index, String value) {
_set(index, value);
}
public void add(String value) {
_add(value);
}
}

View File

@@ -0,0 +1,37 @@
package edu.wpi.first.wpilibj.tables;
/**
* Represents an object that has a remote connection
*
* @author Mitchell
*
*/
public interface IRemote {
/**
* Register an object to listen for connection and disconnection events
*
* @param listener the listener to be register
* @param immediateNotify if the listener object should be notified of the current connection state
*/
public void addConnectionListener(IRemoteConnectionListener listener, boolean immediateNotify);
/**
* Unregister a listener from connection events
*
* @param listener the listener to be unregistered
*/
public void removeConnectionListener(IRemoteConnectionListener listener);
/**
* Get the current state of the objects connection
* @return the current connection state
*/
public boolean isConnected();
/**
* If the object is acting as a server
* @return if the object is a server
*/
public boolean isServer();
}

View File

@@ -0,0 +1,40 @@
package edu.wpi.first.wpilibj.tables;
import edu.wpi.first.wpilibj.networktables.ConnectionInfo;
/**
* A listener that listens for connection changes in a {@link IRemote} object
*
* @author Mitchell
*
*/
public interface IRemoteConnectionListener {
/**
* Called when an IRemote is connected
* @param remote the object that connected
*/
public void connected(IRemote remote);
/**
* Called when an IRemote is disconnected
* @param remote the object that disconnected
*/
public void disconnected(IRemote remote);
/**
* Extended version of connected called when an IRemote is connected.
* Contains the connection info of the connected remote
* @param remote the object that connected
* @param info the connection info for the connected remote
*/
default public void connectedEx(IRemote remote, ConnectionInfo info) {
connected(remote);
}
/**
* Extended version of connected called when an IRemote is disconnected.
* Contains the connection info of the disconnected remote
* @param remote the object that disconnected
* @param info the connection info for the disconnected remote
*/
default public void disconnectedEx(IRemote remote, ConnectionInfo info) {
disconnected(remote);
}
}

View File

@@ -0,0 +1,634 @@
package edu.wpi.first.wpilibj.tables;
import java.nio.ByteBuffer;
import java.util.NoSuchElementException;
import java.util.Set;
/**
* A table whose values can be read and written to
*/
public interface ITable {
/**
* Checks the table and tells if it contains the specified key
*
* @param key the key to search for
* @return true if the table as a value assigned to the given key
*/
public boolean containsKey(String key);
/**
* @param key the key to search for
* @return true if there is a subtable with the key which contains at least
* one key/subtable of its own
*/
public boolean containsSubTable(String key);
/**
* Returns the table at the specified key. If there is no table at the
* specified key, it will create a new table
*
* @param key the name of the table relative to this one
* @return a sub table relative to this one
*/
public ITable getSubTable(String key);
/**
* @param types bitmask of types; 0 is treated as a "don't care".
* @return keys currently in the table
*/
public Set<String> getKeys(int types);
/**
* @return keys currently in the table
*/
public Set<String> getKeys();
/**
* @return subtables currently in the table
*/
public Set<String> getSubTables();
/**
* Makes a key's value persistent through program restarts.
* The key cannot be null.
*
* @param key the key name
*/
public void setPersistent(String key);
/**
* Stop making a key's value persistent through program restarts.
* The key cannot be null.
*
* @param key the key name
*/
public void clearPersistent(String key);
/**
* Returns whether the value is persistent through program restarts.
* The key cannot be null.
*
* @param key the key name
* @return True if the value is persistent.
*/
public boolean isPersistent(String key);
/**
* Sets flags on the specified key in this table. The key can
* not be null.
*
* @param key the key name
* @param flags the flags to set (bitmask)
*/
public void setFlags(String key, int flags);
/**
* Clears flags on the specified key in this table. The key can
* not be null.
*
* @param key the key name
* @param flags the flags to clear (bitmask)
*/
public void clearFlags(String key, int flags);
/**
* Returns the flags for the specified key.
*
* @param key the key name
* @return the flags, or 0 if the key is not defined
*/
public int getFlags(String key);
/**
* Deletes the specified key in this table. The key can
* not be null.
*
* @param key the key name
*/
public void delete(String key);
/**
* Gets the value associated with a key as an object. If the key does not
* exist, it will return the default value
* NOTE: If the value is a double, it will return a Double object,
* not a primitive. To get the primitive, use
* {@link #getDouble(String, double)}.
* @param key the key of the value to look up
* @return the value associated with the given key
* @throws TableKeyNotDefinedException if there is no value associated with
* the given key
* @deprecated This exception-raising method has been replaced by the
* default-taking method {@link #getValue(String, Object)}.
*/
@Deprecated
public Object getValue(String key) throws TableKeyNotDefinedException;
/**
* Gets the value associated with a key as an object.
* NOTE: If the value is a double, it will return a Double object,
* not a primitive. To get the primitive, use
* {@link #getDouble(String, double)}.
* @param key the key of the value to look up
* @param defaultValue the default value if the key is null
* @return the value associated with the given key
*/
public Object getValue(String key, Object defaultValue);
/**
* Put a value in the table
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
* @throws IllegalArgumentException when the value is not supported by the
* table
*/
public boolean putValue(String key, Object value)
throws IllegalArgumentException;
/**
* Retrieve an array data type from the table.
* @param key the key to be assigned to
* @param externalValue the array data type to retreive into
* @throws TableKeyNotDefinedException if there is no value associated with
* the given key
* @deprecated Use get*Array functions instead.
*/
@Deprecated
public void retrieveValue(String key, Object externalValue) throws TableKeyNotDefinedException;
/**
* Put a number in the table
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
public boolean putNumber(String key, double value);
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doens't exist.
* @return False if the table key exists with a different type
*/
public boolean setDefaultNumber(String key, double defaultValue);
/**
* Returns the number the key maps to.
* @param key the key to look up
* @return the value associated with the given key
* @throws TableKeyNotDefinedException if there is no value associated with
* the given key
* @deprecated This exception-raising method has been replaced by the
* default-taking method {@link #getNumber(String, double)}.
*/
@Deprecated
public double getNumber(String key) throws TableKeyNotDefinedException;
/**
* Returns the number the key maps to. If the key does not exist or is of
* different type, it will return the default value.
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
*/
public double getNumber(String key, double defaultValue);
/**
* Put a string in the table
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
public boolean putString(String key, String value);
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doens't exist.
* @return False if the table key exists with a different type
*/
public boolean setDefaultString(String key, String defaultValue);
/**
* Returns the string the key maps to.
* @param key the key to look up
* @return the value associated with the given key
* @throws TableKeyNotDefinedException if there is no value associated with
* the given key
* @deprecated This exception-raising method has been replaced by the
* default-taking method {@link #getString(String, String)}.
*/
@Deprecated
public String getString(String key) throws TableKeyNotDefinedException;
/**
* Returns the string the key maps to. If the key does not exist or is of
* different type, it will return the default value.
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
*/
public String getString(String key, String defaultValue);
/**
* Put a boolean in the table
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
public boolean putBoolean(String key, boolean value);
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doens't exist.
* @return False if the table key exists with a different type
*/
public boolean setDefaultBoolean(String key, boolean defaultValue);
/**
* Returns the boolean the key maps to.
* @param key the key to look up
* @return the value associated with the given key
* @throws TableKeyNotDefinedException if there is no value associated with
* the given key
* @deprecated This exception-raising method has been replaced by the
* default-taking method {@link #getBoolean(String, boolean)}.
*/
@Deprecated
public boolean getBoolean(String key) throws TableKeyNotDefinedException;
/**
* Returns the boolean the key maps to. If the key does not exist or is of
* different type, it will return the default value.
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
*/
public boolean getBoolean(String key, boolean defaultValue);
/**
* Put a boolean array in the table
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
public boolean putBooleanArray(String key, boolean[] value);
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doens't exist.
* @return False if the table key exists with a different type
*/
public boolean setDefaultBooleanArray(String key, boolean[] defaultValue);
/**
* Put a boolean array in the table
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
public boolean putBooleanArray(String key, Boolean[] value);
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doens't exist.
* @return False if the table key exists with a different type
*/
public boolean setDefaultBooleanArray(String key, Boolean[] defaultValue);
/**
* Returns the boolean array the key maps to.
* @param key the key to look up
* @return the value associated with the given key
* @throws TableKeyNotDefinedException if there is no value associated with
* the given key
* @deprecated This exception-raising method has been replaced by the
* default-taking method {@link #getBooleanArray(String, boolean[])}.
*/
@Deprecated
public boolean[] getBooleanArray(String key) throws TableKeyNotDefinedException;
/**
* Returns the boolean array the key maps to. If the key does not exist or is
* of different type, it will return the default value.
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
*/
public boolean[] getBooleanArray(String key, boolean[] defaultValue);
/**
* Returns the boolean array the key maps to. If the key does not exist or is
* of different type, it will return the default value.
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
*/
public Boolean[] getBooleanArray(String key, Boolean[] defaultValue);
/**
* Put a number array in the table
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
public boolean putNumberArray(String key, double[] value);
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doens't exist.
* @return False if the table key exists with a different type
*/
public boolean setDefaultNumberArray(String key, double[] defaultValue);
/**
* Put a number array in the table
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
public boolean putNumberArray(String key, Double[] value);
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doens't exist.
* @return False if the table key exists with a different type
*/
public boolean setDefaultNumberArray(String key, Double[] defaultValue);
/**
* Returns the number array the key maps to.
* @param key the key to look up
* @return the value associated with the given key
* @throws TableKeyNotDefinedException if there is no value associated with
* the given key
* @deprecated This exception-raising method has been replaced by the
* default-taking method {@link #getNumberArray(String, double[])}.
*/
@Deprecated
public double[] getNumberArray(String key) throws TableKeyNotDefinedException;
/**
* Returns the number array the key maps to. If the key does not exist or is
* of different type, it will return the default value.
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
*/
public double[] getNumberArray(String key, double[] defaultValue);
/**
* Returns the number array the key maps to. If the key does not exist or is
* of different type, it will return the default value.
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
*/
public Double[] getNumberArray(String key, Double[] defaultValue);
/**
* Put a string array in the table
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
public boolean putStringArray(String key, String[] value);
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doens't exist.
* @return False if the table key exists with a different type
*/
public boolean setDefaultStringArray(String key, String[] defaultValue);
/**
* Returns the string array the key maps to.
* @param key the key to look up
* @return the value associated with the given key
* @throws TableKeyNotDefinedException if there is no value associated with
* the given key
* @deprecated This exception-raising method has been replaced by the
* default-taking method {@link #getStringArray(String, String[])}.
*/
@Deprecated
public String[] getStringArray(String key) throws TableKeyNotDefinedException;
/**
* Returns the string array the key maps to. If the key does not exist or is
* of different type, it will return the default value.
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
*/
public String[] getStringArray(String key, String[] defaultValue);
/**
* Put a raw value (byte array) in the table
* @param key the key to be assigned to
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
public boolean putRaw(String key, byte[] value);
/**
* Gets the current value in the table, setting it if it does not exist.
* @param key the key
* @param defaultValue the default value to set if key doens't exist.
* @return False if the table key exists with a different type
*/
public boolean setDefaultRaw(String key, byte[] defaultValue);
/**
* Put a raw value (bytes from a byte buffer) in the table
* @param key the key to be assigned to
* @param value the value that will be assigned
* @param len the length of the value
* @return False if the table key already exists with a different type
*/
public boolean putRaw(String key, ByteBuffer value, int len);
/**
* Returns the raw value (byte array) the key maps to.
* @param key the key to look up
* @return the value associated with the given key
* @throws TableKeyNotDefinedException if there is no value associated with
* the given key
* @deprecated This exception-raising method has been replaced by the
* default-taking method {@link #getRaw(String, byte[])}.
*/
@Deprecated
public byte[] getRaw(String key) throws TableKeyNotDefinedException;
/**
* Returns the raw value (byte array) the key maps to. If the key does not
* exist or is of different type, it will return the default value.
* @param key the key to look up
* @param defaultValue the value to be returned if no value is found
* @return the value associated with the given key or the given default value
* if there is no value associated with the key
*/
public byte[] getRaw(String key, byte[] defaultValue);
/** Notifier flag values. */
public static final int NOTIFY_IMMEDIATE = 0x01;
public static final int NOTIFY_LOCAL = 0x02;
public static final int NOTIFY_NEW = 0x04;
public static final int NOTIFY_DELETE = 0x08;
public static final int NOTIFY_UPDATE = 0x10;
public static final int NOTIFY_FLAGS = 0x20;
/**
* Add a listener for changes to the table
* @param listener the listener to add
*/
public void addTableListener(ITableListener listener);
/**
* Add a listener for changes to the table
* @param listener the listener to add
* @param immediateNotify if true then this listener will be notified of all
* current entries (marked as new)
*/
public void addTableListener(ITableListener listener,
boolean immediateNotify);
/**
* Add a listener for changes to the table
* @param listener the listener to add
* @param flags bitmask specifying desired notifications
*/
public void addTableListenerEx(ITableListener listener, int flags);
/**
* Add a listener for changes to a specific key the table
* @param key the key to listen for
* @param listener the listener to add
* @param immediateNotify if true then this listener will be notified of all
* current entries (marked as new)
*/
public void addTableListener(String key, ITableListener listener,
boolean immediateNotify);
/**
* Add a listener for changes to a specific key the table
* @param key the key to listen for
* @param listener the listener to add
* @param flags bitmask specifying desired notifications
*/
public void addTableListenerEx(String key, ITableListener listener,
int flags);
/**
* This will immediately notify the listener of all current sub tables
* @param listener the listener to notify
*/
public void addSubTableListener(final ITableListener listener);
/**
* This will immediately notify the listener of all current sub tables
* @param listener the listener to notify
* @param localNotify if true then this listener will be notified of all
* local changes in addition to all remote changes
*/
public void addSubTableListener(final ITableListener listener,
boolean localNotify);
/**
* Remove a listener from receiving table events
* @param listener the listener to be removed
*/
public void removeTableListener(ITableListener listener);
/*
* Deprecated Methods
*/
/**
* Maps the specified key to the specified value in this table.
* The key can not be null.
* The value can be retrieved by calling the get method with a key that is
* equal to the original key.
* @param key the key
* @param value the value
* @return False if the table key already exists with a different type
* @throws IllegalArgumentException if key is null
* @deprecated Use {@link #putNumber(String, double)} instead.
*/
@Deprecated
public boolean putInt(String key, int value);
/**
* Returns the value at the specified key.
* @param key the key
* @return the value
* @throws TableKeyNotDefinedException if there is no value mapped to by the
* key
* @throws IllegalArgumentException if the value mapped to by the key is not
* an int
* @throws IllegalArgumentException if the key is null
* @deprecated Use {@link #getNumber(String, double)} instead.
*/
@Deprecated
public int getInt(String key) throws TableKeyNotDefinedException;
/**
* Returns the value at the specified key.
* @param key the key
* @param defaultValue the value returned if the key is undefined
* @return the value
* @throws IllegalArgumentException if the value mapped to by the key is not
* an int
* @throws IllegalArgumentException if the key is null
* @deprecated Use {@link #getNumber(String, double)} instead.
*/
@Deprecated
public int getInt(String key, int defaultValue)
throws TableKeyNotDefinedException;
/**
* Maps the specified key to the specified value in this table.
* The key can not be null.
* The value can be retrieved by calling the get method with a key that is
* equal to the original key.
* @param key the key
* @param value the value
* @return False if the table key already exists with a different type
* @throws IllegalArgumentException if key is null
* @deprecated Use {@link #putNumber(String, double)} instead.
*/
@Deprecated
public boolean putDouble(String key, double value);
/**
* Returns the value at the specified key.
* @param key the key
* @return the value
* @throws TableKeyNotDefinedException if there is no
* value mapped to by the key
* @throws IllegalArgumentException if the value mapped to by the key is not a
* double
* @throws IllegalArgumentException if the key is null
* @deprecated Use {@link #getNumber(String, double)} instead.
*/
@Deprecated
public double getDouble(String key) throws TableKeyNotDefinedException;
/**
* Returns the value at the specified key.
* @param key the key
* @param defaultValue the value returned if the key is undefined
* @return the value
* @throws IllegalArgumentException if the value mapped to by the key is not a
* double
* @throws IllegalArgumentException if the key is null
* @deprecated Use {@link #getNumber(String, double)} instead.
*/
@Deprecated
public double getDouble(String key, double defaultValue);
/**
* Gets the full path of this table.
*/
public String getPath();
}

View File

@@ -0,0 +1,35 @@
package edu.wpi.first.wpilibj.tables;
/**
* A listener that listens to changes in values in a {@link ITable}
*
* @author Mitchell
*
*/
@FunctionalInterface
public interface ITableListener {
/**
* Called when a key-value pair is changed in a {@link ITable}
* @param source the table the key-value pair exists in
* @param key the key associated with the value that changed
* @param value the new value
* @param isNew true if the key did not previously exist in the table, otherwise it is false
*/
public void valueChanged(ITable source, String key, Object value, boolean isNew);
/**
* Extended version of valueChanged. Called when a key-value pair is
* changed in a {@link ITable}. The default implementation simply calls
* valueChanged(). If this is overridden, valueChanged() will not be
* called.
* @param source the table the key-value pair exists in
* @param key the key associated with the value that changed
* @param value the new value
* @param flags update flags; for example, NOTIFY_NEW if the key did not
* previously exist in the table
*/
default public void valueChangedEx(ITable source, String key, Object value, int flags) {
// NOTIFY_NEW = 0x04
valueChanged(source, key, value, (flags & 0x04) != 0);
}
}

View File

@@ -0,0 +1,20 @@
package edu.wpi.first.wpilibj.tables;
import java.util.NoSuchElementException;
/**
* An exception throw when the lookup a a key-value fails in a {@link ITable}
*
* @author Mitchell
*
*/
public class TableKeyNotDefinedException extends NoSuchElementException {
/**
* @param key the key that was not defined in the table
*/
public TableKeyNotDefinedException(String key) {
super("Unknown Table Key: "+key);
}
}