diff --git a/include/networktables/NetworkTable.h b/include/networktables/NetworkTable.h index e4ef8daa5c..b14dcd6458 100644 --- a/include/networktables/NetworkTable.h +++ b/include/networktables/NetworkTable.h @@ -17,6 +17,7 @@ class NetworkTable : public ITable { std::vector m_listeners; static std::string s_ip_address; + static std::string s_persistent_filename; static bool s_client; static bool s_running; @@ -62,6 +63,13 @@ class NetworkTable : public ITable { */ static void SetIPAddress(llvm::StringRef address); + /** + * Sets the persistent filename. + * @param filename the filename that the network tables server uses for + * automatic loading and saving of persistent values + */ + static void SetPersistentFilename(llvm::StringRef filename); + /** * Sets the network identity. * This is provided in the connection info on the remote end. diff --git a/java/src/edu/wpi/first/wpilibj/networktables/NetworkTable.java b/java/src/edu/wpi/first/wpilibj/networktables/NetworkTable.java index 0c4430a2d1..3918635464 100644 --- a/java/src/edu/wpi/first/wpilibj/networktables/NetworkTable.java +++ b/java/src/edu/wpi/first/wpilibj/networktables/NetworkTable.java @@ -112,6 +112,18 @@ public class NetworkTable implements ITable, IRemote { port = aport; } + /** + * Sets the persistent filename. + * @param filename the filename that the network tables server uses for + * automatic loading and saving of persistent values + */ + public synchronized static void setPersistentFilename(final String filename) { + if (persistentFilename == filename) + return; + checkInit(); + persistentFilename = filename; + } + /** * Sets the network identity. * This is provided in the connection info on the remote end. diff --git a/src/networktables/NetworkTable.cpp b/src/networktables/NetworkTable.cpp index 11347e07ce..94ef4c9202 100644 --- a/src/networktables/NetworkTable.cpp +++ b/src/networktables/NetworkTable.cpp @@ -10,6 +10,7 @@ using llvm::StringRef; const char NetworkTable::PATH_SEPARATOR_CHAR = '/'; std::string NetworkTable::s_ip_address; +std::string NetworkTable::s_persistent_filename = "networktables.ini"; bool NetworkTable::s_client = false; bool NetworkTable::s_running = false; @@ -18,7 +19,7 @@ void NetworkTable::Initialize() { if (s_client) nt::StartClient(s_ip_address.c_str(), NT_DEFAULT_PORT); else - nt::StartServer("networktables.ini", "", NT_DEFAULT_PORT); + nt::StartServer(s_persistent_filename, "", NT_DEFAULT_PORT); s_running = true; } @@ -47,6 +48,10 @@ void NetworkTable::SetTeam(int team) { void NetworkTable::SetIPAddress(StringRef address) { s_ip_address = address; } +void NetworkTable::SetPersistentFilename(StringRef filename) { + s_persistent_filename = filename; +} + void NetworkTable::SetNetworkIdentity(StringRef name) { nt::SetNetworkIdentity(name); }