mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Adds SetDefault methods to NetworkTables (#54)
There was no way to atomically check for a key in the table, and then setting if it if non existant. Back before persistent this was not a problem, however now it is, as its possible for values to be added before team's robot programs start. This makes the old method of calling Put*** methods in RobotInit invalid. This adds SetDefault methods, which do this atomically.
This commit is contained in:
committed by
Peter Johnson
parent
6615a34e99
commit
58092c5190
@@ -915,6 +915,90 @@ JNIEXPORT jobjectArray JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkT
|
||||
return ToJavaStringArray(env, val->GetStringArray());
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_networktables_NetworkTablesJNI
|
||||
* Method: setDefaultBoolean
|
||||
* Signature: (Ljava/lang/String;Z)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_setDefaultBoolean
|
||||
(JNIEnv *env, jclass, jstring key, jboolean defaultValue)
|
||||
{
|
||||
return nt::SetDefaultEntryValue(JavaStringRef(env, key),
|
||||
nt::Value::MakeBoolean(defaultValue != JNI_FALSE));
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_networktables_NetworkTablesJNI
|
||||
* Method: setDefaultDouble
|
||||
* Signature: (Ljava/lang/String;D)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_setDefaultDouble
|
||||
(JNIEnv *env, jclass, jstring key, jdouble defaultValue)
|
||||
{
|
||||
return nt::SetDefaultEntryValue(JavaStringRef(env, key),
|
||||
nt::Value::MakeDouble(defaultValue));
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_networktables_NetworkTablesJNI
|
||||
* Method: setDefaultString
|
||||
* Signature: (Ljava/lang/String;Ljava/lang/String;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_setDefaultString
|
||||
(JNIEnv *env, jclass, jstring key, jstring defaultValue)
|
||||
{
|
||||
return nt::SetDefaultEntryValue(JavaStringRef(env, key),
|
||||
nt::Value::MakeString(JavaStringRef(env, defaultValue)));
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_networktables_NetworkTablesJNI
|
||||
* Method: setDefaultRaw
|
||||
* Signature: (Ljava/lang/String;[B)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_setDefaultRaw
|
||||
(JNIEnv *env, jclass, jstring key, jbyteArray defaultValue)
|
||||
{
|
||||
auto v = FromJavaRaw(env, defaultValue);
|
||||
return nt::SetDefaultEntryValue(JavaStringRef(env, key), v);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_networktables_NetworkTablesJNI
|
||||
* Method: setDefaultBooleanArray
|
||||
* Signature: (Ljava/lang/String;[Z)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_setDefaultBooleanArray
|
||||
(JNIEnv *env, jclass, jstring key, jbooleanArray defaultValue)
|
||||
{
|
||||
auto v = FromJavaBooleanArray(env, defaultValue);
|
||||
return nt::SetDefaultEntryValue(JavaStringRef(env, key), v);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_networktables_NetworkTablesJNI
|
||||
* Method: setDefaultDoubleArray
|
||||
* Signature: (Ljava/lang/String;[D)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_setDefaultDoubleArray
|
||||
(JNIEnv *env, jclass, jstring key, jdoubleArray defaultValue)
|
||||
{
|
||||
auto v = FromJavaDoubleArray(env, defaultValue);
|
||||
return nt::SetDefaultEntryValue(JavaStringRef(env, key), v);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_networktables_NetworkTablesJNI
|
||||
* Method: setDefaultStringArray
|
||||
* Signature: (Ljava/lang/String;[Ljava/lang/String;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI_setDefaultStringArray
|
||||
(JNIEnv *env, jclass, jstring key, jobjectArray defaultValue)
|
||||
{
|
||||
auto v = FromJavaStringArray(env, defaultValue);
|
||||
return nt::SetDefaultEntryValue(JavaStringRef(env, key), v);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_networktables_NetworkTablesJNI
|
||||
* Method: setEntryFlags
|
||||
|
||||
@@ -502,6 +502,14 @@ public class NetworkTable implements ITable, IRemote {
|
||||
public boolean putNumber(String key, double value) {
|
||||
return NetworkTablesJNI.putDouble(path + PATH_SEPARATOR + key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean setDefaultNumber(String key, double defaultValue) {
|
||||
return NetworkTablesJNI.setDefaultDouble(path + PATH_SEPARATOR + key,
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@@ -529,6 +537,14 @@ public class NetworkTable implements ITable, IRemote {
|
||||
public boolean putString(String key, String value) {
|
||||
return NetworkTablesJNI.putString(path + PATH_SEPARATOR + key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean setDefaultString(String key, String defaultValue) {
|
||||
return NetworkTablesJNI.setDefaultString(path + PATH_SEPARATOR + key,
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@@ -556,6 +572,14 @@ public class NetworkTable implements ITable, IRemote {
|
||||
public boolean putBoolean(String key, boolean value) {
|
||||
return NetworkTablesJNI.putBoolean(path + PATH_SEPARATOR + key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean setDefaultBoolean(String key, boolean defaultValue) {
|
||||
return NetworkTablesJNI.setDefaultBoolean(path + PATH_SEPARATOR + key,
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@@ -591,6 +615,22 @@ public class NetworkTable implements ITable, IRemote {
|
||||
public boolean putBooleanArray(String key, Boolean[] value) {
|
||||
return putBooleanArray(key, toNative(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean setDefaultBooleanArray(String key, boolean[] defaultValue) {
|
||||
return NetworkTablesJNI.setDefaultBooleanArray(path + PATH_SEPARATOR + key,
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean setDefaultBooleanArray(String key, Boolean[] defaultValue) {
|
||||
return NetworkTablesJNI.setDefaultBooleanArray(path + PATH_SEPARATOR + key,
|
||||
toNative(defaultValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@@ -638,6 +678,22 @@ public class NetworkTable implements ITable, IRemote {
|
||||
public boolean putNumberArray(String key, Double[] value) {
|
||||
return putNumberArray(key, toNative(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean setDefaultNumberArray(String key, double[] defaultValue) {
|
||||
return NetworkTablesJNI.setDefaultDoubleArray(path + PATH_SEPARATOR + key,
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean setDefaultNumberArray(String key, Double[] defaultValue) {
|
||||
return NetworkTablesJNI.setDefaultDoubleArray(path + PATH_SEPARATOR + key,
|
||||
toNative(defaultValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@@ -677,7 +733,15 @@ public class NetworkTable implements ITable, IRemote {
|
||||
public boolean putStringArray(String key, String[] value) {
|
||||
return NetworkTablesJNI.putStringArray(path + PATH_SEPARATOR + key, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean setDefaultStringArray(String key, String[] defaultValue) {
|
||||
return NetworkTablesJNI.setDefaultStringArray(path + PATH_SEPARATOR + key,
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @deprecated This exception-raising method has been replaced by the
|
||||
@@ -704,6 +768,14 @@ public class NetworkTable implements ITable, IRemote {
|
||||
public boolean putRaw(String key, byte[] value) {
|
||||
return NetworkTablesJNI.putRaw(path + PATH_SEPARATOR + key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean setDefaultRaw(String key, byte[] defaultValue) {
|
||||
return NetworkTablesJNI.setDefaultRaw(path + PATH_SEPARATOR + key,
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
||||
@@ -106,6 +106,14 @@ public class NetworkTablesJNI {
|
||||
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);
|
||||
|
||||
|
||||
@@ -165,6 +165,15 @@ public interface ITable {
|
||||
* @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
|
||||
@@ -193,6 +202,15 @@ public interface ITable {
|
||||
* @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
|
||||
@@ -221,6 +239,15 @@ public interface ITable {
|
||||
* @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
|
||||
@@ -249,6 +276,15 @@ public interface ITable {
|
||||
* @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
|
||||
@@ -256,6 +292,15 @@ public interface ITable {
|
||||
* @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
|
||||
@@ -293,6 +338,15 @@ public interface ITable {
|
||||
* @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
|
||||
@@ -300,6 +354,15 @@ public interface ITable {
|
||||
* @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
|
||||
@@ -337,6 +400,15 @@ public interface ITable {
|
||||
* @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
|
||||
@@ -365,6 +437,15 @@ public interface ITable {
|
||||
* @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
|
||||
|
||||
Reference in New Issue
Block a user