Add SaveEntries() and LoadEntries(). (#233)

These allow saving and loading non-persistent entries in the persistent
file format.
This commit is contained in:
Peter Johnson
2017-10-01 09:13:43 -07:00
committed by GitHub
parent e68a71022c
commit 1f18cc5416
17 changed files with 352 additions and 26 deletions

View File

@@ -264,6 +264,27 @@ public final class NetworkTable {
return path;
}
/**
* Save table values to a file. The file format used is identical to
* that used for SavePersistent.
* @param filename filename
* @throws PersistentException if error saving file
*/
public void saveEntries(String filename) throws PersistentException {
inst.saveEntries(filename, pathWithSep);
}
/**
* Load table values from a file. The file format used is identical to
* that used for SavePersistent / LoadPersistent.
* @param filename filename
* @return List of warnings (errors result in an exception instead)
* @throws PersistentException if error saving file
*/
public String[] loadEntries(String filename) throws PersistentException {
return inst.loadEntries(filename, pathWithSep);
}
@Override
public boolean equals(Object o) {
if (o == this) {

View File

@@ -935,6 +935,29 @@ public final class NetworkTableInstance {
return NetworkTablesJNI.loadPersistent(m_handle, filename);
}
/**
* Save table values to a file. The file format used is identical to
* that used for SavePersistent.
* @param filename filename
* @param prefix save only keys starting with this prefix
* @throws PersistentException if error saving file
*/
public void saveEntries(String filename, String prefix) throws PersistentException {
NetworkTablesJNI.saveEntries(m_handle, filename, prefix);
}
/**
* Load table values from a file. The file format used is identical to
* that used for SavePersistent / LoadPersistent.
* @param filename filename
* @param prefix load only keys starting with this prefix
* @return List of warnings (errors result in an exception instead)
* @throws PersistentException if error saving file
*/
public String[] loadEntries(String filename, String prefix) throws PersistentException {
return NetworkTablesJNI.loadEntries(m_handle, filename, prefix);
}
private final ReentrantLock m_loggerLock = new ReentrantLock();
private final Map<Integer, Consumer<LogMessage>> m_loggers = new HashMap<>();
private Thread m_loggerThread;

View File

@@ -169,6 +169,9 @@ public final class NetworkTablesJNI {
public static native void savePersistent(int inst, String filename) throws PersistentException;
public static native String[] loadPersistent(int inst, String filename) throws PersistentException; // returns warnings
public static native void saveEntries(int inst, String filename, String prefix) throws PersistentException;
public static native String[] loadEntries(int inst, String filename, String prefix) throws PersistentException; // returns warnings
public static native long now();
public static native int createLoggerPoller(int inst);