8 #ifndef NETWORKTABLE_H_
9 #define NETWORKTABLE_H_
15 #include "tables/ITable.h"
22 struct private_init {};
26 typedef std::pair<ITableListener*, unsigned int> Listener;
27 std::vector<Listener> m_listeners;
29 static std::string s_ip_address;
30 static std::string s_persistent_filename;
32 static bool s_running;
33 static unsigned int s_port;
49 static void Shutdown();
81 static void SetPort(
unsigned int port);
134 std::function<
void(
size_t line,
const char* msg)> warn);
150 bool immediateNotify)
override;
152 unsigned int flags)
override;
154 bool immediateNotify)
override;
156 unsigned int flags)
override;
193 std::vector<std::string>
GetKeys(
int types = 0)
const override;
275 NT_DEPRECATED(
"Raises an exception if key not found; "
276 "use GetNumber(StringRef key, double defaultValue) instead")
277 virtual
double GetNumber(llvm::StringRef key) const override;
287 virtual
double GetNumber(llvm::StringRef key,
288 double defaultValue) const override;
297 virtual
bool PutString(llvm::StringRef key, llvm::StringRef value) override;
309 NT_DEPRECATED("Raises an exception if key not found; "
310 "use GetString(StringRef key, StringRef defaultValue) instead")
311 virtual std::
string GetString(llvm::StringRef key) const override;
322 virtual std::
string GetString(llvm::StringRef key,
323 llvm::StringRef defaultValue) const override;
332 virtual
bool PutBoolean(llvm::StringRef key,
bool value) override;
344 NT_DEPRECATED("Raises an exception if key not found; "
345 "use GetBoolean(StringRef key,
bool defaultValue) instead")
346 virtual
bool GetBoolean(llvm::StringRef key) const override;
357 virtual
bool GetBoolean(llvm::StringRef key,
358 bool defaultValue) const override;
371 llvm::ArrayRef<
int> value) override;
389 llvm::StringRef key, llvm::ArrayRef<
int> defaultValue) const override;
398 llvm::ArrayRef<
double> value) override;
412 llvm::StringRef key, llvm::ArrayRef<
double> defaultValue) const override;
421 llvm::ArrayRef<std::
string> value) override;
436 llvm::ArrayRef<std::
string> defaultValue) const override;
444 virtual
bool PutRaw(llvm::StringRef key, llvm::StringRef value) override;
457 virtual std::
string GetRaw(llvm::StringRef key,
458 llvm::StringRef defaultValue) const override;
467 bool PutValue(llvm::StringRef key, std::shared_ptr<nt::Value> value) override;
476 std::shared_ptr<nt::Value>
GetValue(llvm::StringRef key) const override;
479 #endif // NETWORKTABLE_H_
static void SetPort(unsigned int port)
Definition: NetworkTable.cpp:55
A table whose values can be read and written to.
Definition: ITable.h:43
virtual bool PutNumberArray(llvm::StringRef key, llvm::ArrayRef< double > value) override
Put a number array in the table.
Definition: NetworkTable.cpp:391
static const char PATH_SEPARATOR_CHAR
The path separator for sub-tables and keys.
Definition: NetworkTable.h:43
virtual std::vector< std::string > GetStringArray(llvm::StringRef key, llvm::ArrayRef< std::string > defaultValue) const override
Returns the string array the key maps to.
Definition: NetworkTable.cpp:418
std::vector< std::string > GetSubTables() const override
Definition: NetworkTable.cpp:237
static void SetServerMode()
set that network tables should be a server This must be called before initialize or GetTable ...
Definition: NetworkTable.cpp:40
static void SetTeam(int team)
set the team the robot is configured for (this will set the mdns address that network tables will con...
Definition: NetworkTable.cpp:42
void Delete(llvm::StringRef key) override
Deletes the specified key in this table.
Definition: NetworkTable.cpp:283
A network table that knows its subtable path.
Definition: NetworkTable.h:20
static void GlobalDeleteAll()
Deletes ALL keys in ALL subtables.
Definition: NetworkTable.cpp:65
virtual std::string GetRaw(llvm::StringRef key, llvm::StringRef defaultValue) const override
Returns the raw value (byte array) the key maps to.
Definition: NetworkTable.cpp:436
void AddTableListenerEx(ITableListener *listener, unsigned int flags) override
Add a listener for changes to the table.
Definition: NetworkTable.cpp:114
static void SetNetworkIdentity(llvm::StringRef name)
Sets the network identity.
Definition: NetworkTable.cpp:61
bool PutNumber(llvm::StringRef key, double value) override
Put a number in the table.
Definition: NetworkTable.cpp:290
std::vector< std::string > GetKeys(int types=0) const override
Definition: NetworkTable.cpp:224
static void Initialize()
Definition: NetworkTable.cpp:20
bool IsPersistent(llvm::StringRef key) const override
Returns whether the value is persistent through program restarts.
Definition: NetworkTable.cpp:258
static std::shared_ptr< NetworkTable > GetTable(llvm::StringRef key)
Gets the table with the specified key.
Definition: NetworkTable.cpp:83
void ClearFlags(llvm::StringRef key, unsigned int flags) override
Clears flags on the specified key in this table.
Definition: NetworkTable.cpp:269
void SetFlags(llvm::StringRef key, unsigned int flags) override
Sets flags on the specified key in this table.
Definition: NetworkTable.cpp:262
static void SetUpdateRate(double interval)
Set the periodic update rate.
Definition: NetworkTable.cpp:69
static const char * LoadPersistent(llvm::StringRef filename, std::function< void(size_t line, const char *msg)> warn)
Loads persistent keys from a file.
Definition: NetworkTable.cpp:77
A listener that listens to changes in values in a ITable.
Definition: ITableListener.h:18
bool ContainsSubTable(llvm::StringRef key) const override
Determines whether there exists a non-empty subtable for this key in this table.
Definition: NetworkTable.cpp:216
static void Flush()
Flushes all updated values immediately to the network.
Definition: NetworkTable.cpp:67
void AddSubTableListener(ITableListener *listener) override
This will immediately notify the listener of all current sub tables.
Definition: NetworkTable.cpp:157
virtual bool PutStringArray(llvm::StringRef key, llvm::ArrayRef< std::string > value) override
Put a string array in the table.
Definition: NetworkTable.cpp:410
virtual bool PutBoolean(llvm::StringRef key, bool value) override
Put a boolean in the table.
Definition: NetworkTable.cpp:345
unsigned int GetFlags(llvm::StringRef key) const override
Returns the flags for the specified key.
Definition: NetworkTable.cpp:276
std::shared_ptr< ITable > GetSubTable(llvm::StringRef key) const override
Returns the table at the specified key.
Definition: NetworkTable.cpp:202
std::shared_ptr< nt::Value > GetValue(llvm::StringRef key) const override
Gets the value associated with a key as an object.
Definition: NetworkTable.cpp:454
bool PutValue(llvm::StringRef key, std::shared_ptr< nt::Value > value) override
Put a value in the table.
Definition: NetworkTable.cpp:447
static void SetIPAddress(llvm::StringRef address)
Definition: NetworkTable.cpp:53
void SetPersistent(llvm::StringRef key) override
Makes a key's value persistent through program restarts.
Definition: NetworkTable.cpp:250
void ClearPersistent(llvm::StringRef key) override
Stop making a key's value persistent through program restarts.
Definition: NetworkTable.cpp:254
void AddTableListener(ITableListener *listener) override
Add a listener for changes to the table.
Definition: NetworkTable.cpp:103
virtual bool PutRaw(llvm::StringRef key, llvm::StringRef value) override
Put a raw value (byte array) in the table.
Definition: NetworkTable.cpp:429
virtual std::vector< double > GetNumberArray(llvm::StringRef key, llvm::ArrayRef< double > defaultValue) const override
Returns the number array the key maps to.
Definition: NetworkTable.cpp:399
virtual std::vector< int > GetBooleanArray(llvm::StringRef key, llvm::ArrayRef< int > defaultValue) const override
Returns the boolean array the key maps to.
Definition: NetworkTable.cpp:380
virtual bool PutBooleanArray(llvm::StringRef key, llvm::ArrayRef< int > value) override
Put a boolean array in the table.
Definition: NetworkTable.cpp:372
void RemoveTableListener(ITableListener *listener) override
Remove a listener from receiving table events.
Definition: NetworkTable.cpp:191
static void SetPersistentFilename(llvm::StringRef filename)
Sets the persistent filename.
Definition: NetworkTable.cpp:57
static const char * SavePersistent(llvm::StringRef filename)
Saves persistent keys to a file.
Definition: NetworkTable.cpp:73
virtual bool PutString(llvm::StringRef key, llvm::StringRef value) override
Put a string in the table.
Definition: NetworkTable.cpp:317
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:39
bool ContainsKey(llvm::StringRef key) const override
Determines whether the given key is in this table.
Definition: NetworkTable.cpp:209
static void SetClientMode()
set that network tables should be a client This must be called before initialize or GetTable ...
Definition: NetworkTable.cpp:38