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::vector<std::string> s_ip_addresses;
30 static std::string s_persistent_filename;
32 static bool s_enable_ds;
33 static bool s_running;
34 static unsigned int s_port;
50 static void Shutdown();
82 static void SetIPAddress(llvm::ArrayRef<std::string> addresses);
88 static void SetPort(
unsigned int port);
146 llvm::StringRef filename,
147 std::function<
void(
size_t line,
const char* msg)> warn);
159 static std::shared_ptr<NetworkTable>
GetTable(llvm::StringRef key);
163 bool immediateNotify)
override;
165 unsigned int flags)
override;
167 bool immediateNotify)
override;
169 unsigned int flags)
override;
182 std::shared_ptr<ITable>
GetSubTable(llvm::StringRef key)
const override;
190 bool ContainsKey(llvm::StringRef key)
const override;
206 std::vector<std::string>
GetKeys(
int types = 0)
const override;
243 void SetFlags(llvm::StringRef key,
unsigned int flags)
override;
252 void ClearFlags(llvm::StringRef key,
unsigned int flags)
override;
260 unsigned int GetFlags(llvm::StringRef key)
const override;
267 void Delete(llvm::StringRef key)
override;
276 bool PutNumber(llvm::StringRef key,
double value)
override;
285 double defaultValue)
override;
298 "Raises an exception if key not found; "
299 "use GetNumber(StringRef key, double defaultValue) instead")
300 virtual
double GetNumber(llvm::StringRef key) const override;
310 virtual
double GetNumber(llvm::StringRef key,
311 double defaultValue) const override;
320 virtual
bool PutString(llvm::StringRef key, llvm::StringRef value) override;
329 llvm::StringRef defaultValue) override;
342 "Raises an exception if key not found; "
343 "use GetString(StringRef key, StringRef defaultValue) instead")
344 virtual std::
string GetString(llvm::StringRef key) const override;
355 virtual std::
string GetString(llvm::StringRef key,
356 llvm::StringRef defaultValue) const override;
365 virtual
bool PutBoolean(llvm::StringRef key,
bool value) override;
374 bool defaultValue) override;
387 "Raises an exception if key not found; "
388 "use GetBoolean(StringRef key,
bool defaultValue) instead")
389 virtual
bool GetBoolean(llvm::StringRef key) const override;
400 virtual
bool GetBoolean(llvm::StringRef key,
401 bool defaultValue) const override;
414 llvm::ArrayRef<
int> value) override;
423 llvm::StringRef key, llvm::ArrayRef<
int> defaultValue) override;
441 llvm::StringRef key, llvm::ArrayRef<
int> defaultValue) const override;
450 llvm::ArrayRef<
double> value) override;
459 llvm::StringRef key, llvm::ArrayRef<
double> defaultValue) override;
473 llvm::StringRef key, llvm::ArrayRef<
double> defaultValue) const override;
482 llvm::ArrayRef<std::
string> value) override;
491 llvm::StringRef key, llvm::ArrayRef<std::
string> defaultValue) override;
506 llvm::ArrayRef<std::
string> defaultValue) const override;
514 virtual
bool PutRaw(llvm::StringRef key, llvm::StringRef value) override;
523 llvm::StringRef defaultValue) override;
536 virtual std::
string GetRaw(llvm::StringRef key,
537 llvm::StringRef defaultValue) const override;
546 bool PutValue(llvm::StringRef key, std::shared_ptr<nt::Value> value) override;
555 llvm::StringRef key, std::shared_ptr<nt::Value> defaultValue) override;
564 std::shared_ptr<nt::Value>
GetValue(llvm::StringRef key) const override;
567 #endif // NETWORKTABLE_H_
static void SetIPAddress(llvm::StringRef address)
static void SetPort(unsigned int port)
Definition: NetworkTable.cpp:104
A table whose values can be read and written to.
Definition: ITable.h:22
virtual bool PutNumberArray(llvm::StringRef key, llvm::ArrayRef< double > value) override
Put a number array in the table.
Definition: NetworkTable.cpp:472
virtual bool SetDefaultStringArray(llvm::StringRef key, llvm::ArrayRef< std::string > defaultValue) override
Gets the current value in the table, setting it if it does not exist.
Definition: NetworkTable.cpp:507
virtual bool SetDefaultNumber(llvm::StringRef key, double defaultValue) override
Gets the current value in the table, setting it if it does not exist.
Definition: NetworkTable.cpp:352
virtual bool SetDefaultNumberArray(llvm::StringRef key, llvm::ArrayRef< double > defaultValue) override
Gets the current value in the table, setting it if it does not exist.
Definition: NetworkTable.cpp:480
static const char PATH_SEPARATOR_CHAR
The path separator for sub-tables and keys.
Definition: NetworkTable.h:44
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:516
std::vector< std::string > GetSubTables() const override
Definition: NetworkTable.cpp:292
static void SetServerMode()
set that network tables should be a server This must be called before initialize or GetTable ...
Definition: NetworkTable.cpp:43
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:45
void Delete(llvm::StringRef key) override
Deletes the specified key in this table.
Definition: NetworkTable.cpp:338
A network table that knows its subtable path.
Definition: NetworkTable.h:20
static void GlobalDeleteAll()
Deletes ALL keys in ALL subtables.
Definition: NetworkTable.cpp:122
virtual bool SetDefaultRaw(llvm::StringRef key, llvm::StringRef defaultValue) override
Gets the current value in the table, setting it if it does not exist.
Definition: NetworkTable.cpp:533
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:540
void AddTableListenerEx(ITableListener *listener, unsigned int flags) override
Add a listener for changes to the table.
Definition: NetworkTable.cpp:170
static void SetNetworkIdentity(llvm::StringRef name)
Sets the network identity.
Definition: NetworkTable.cpp:118
bool PutNumber(llvm::StringRef key, double value) override
Put a number in the table.
Definition: NetworkTable.cpp:345
std::vector< std::string > GetKeys(int types=0) const override
Definition: NetworkTable.cpp:280
static void Initialize()
Definition: NetworkTable.cpp:21
static void SetDSClientEnabled(bool enabled)
Definition: NetworkTable.cpp:106
bool IsPersistent(llvm::StringRef key) const override
Returns whether the value is persistent through program restarts.
Definition: NetworkTable.cpp:313
static std::shared_ptr< NetworkTable > GetTable(llvm::StringRef key)
Gets the table with the specified key.
Definition: NetworkTable.cpp:140
void ClearFlags(llvm::StringRef key, unsigned int flags) override
Clears flags on the specified key in this table.
Definition: NetworkTable.cpp:324
virtual bool SetDefaultBooleanArray(llvm::StringRef key, llvm::ArrayRef< int > defaultValue) override
Gets the current value in the table, setting it if it does not exist.
Definition: NetworkTable.cpp:453
void SetFlags(llvm::StringRef key, unsigned int flags) override
Sets flags on the specified key in this table.
Definition: NetworkTable.cpp:317
static void SetUpdateRate(double interval)
Set the periodic update rate.
Definition: NetworkTable.cpp:126
virtual bool SetDefaultBoolean(llvm::StringRef key, bool defaultValue) override
Gets the current value in the table, setting it if it does not exist.
Definition: NetworkTable.cpp:419
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:134
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:272
static void Flush()
Flushes all updated values immediately to the network.
Definition: NetworkTable.cpp:124
void AddSubTableListener(ITableListener *listener) override
This will immediately notify the listener of all current sub tables.
Definition: NetworkTable.cpp:213
virtual bool PutStringArray(llvm::StringRef key, llvm::ArrayRef< std::string > value) override
Put a string array in the table.
Definition: NetworkTable.cpp:499
virtual bool PutBoolean(llvm::StringRef key, bool value) override
Put a boolean in the table.
Definition: NetworkTable.cpp:412
virtual bool SetDefaultString(llvm::StringRef key, llvm::StringRef defaultValue) override
Gets the current value in the table, setting it if it does not exist.
Definition: NetworkTable.cpp:385
unsigned int GetFlags(llvm::StringRef key) const override
Returns the flags for the specified key.
Definition: NetworkTable.cpp:331
std::shared_ptr< ITable > GetSubTable(llvm::StringRef key) const override
Returns the table at the specified key.
Definition: NetworkTable.cpp:258
std::shared_ptr< nt::Value > GetValue(llvm::StringRef key) const override
Gets the value associated with a key as an object.
Definition: NetworkTable.cpp:565
bool PutValue(llvm::StringRef key, std::shared_ptr< nt::Value > value) override
Put a value in the table.
Definition: NetworkTable.cpp:550
void SetPersistent(llvm::StringRef key) override
Makes a key's value persistent through program restarts.
Definition: NetworkTable.cpp:305
void ClearPersistent(llvm::StringRef key) override
Stop making a key's value persistent through program restarts.
Definition: NetworkTable.cpp:309
void AddTableListener(ITableListener *listener) override
Add a listener for changes to the table.
Definition: NetworkTable.cpp:159
virtual bool PutRaw(llvm::StringRef key, llvm::StringRef value) override
Put a raw value (byte array) in the table.
Definition: NetworkTable.cpp:526
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:489
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:462
virtual bool PutBooleanArray(llvm::StringRef key, llvm::ArrayRef< int > value) override
Put a boolean array in the table.
Definition: NetworkTable.cpp:445
void RemoveTableListener(ITableListener *listener) override
Remove a listener from receiving table events.
Definition: NetworkTable.cpp:247
static void SetPersistentFilename(llvm::StringRef filename)
Sets the persistent filename.
Definition: NetworkTable.cpp:114
static const char * SavePersistent(llvm::StringRef filename)
Saves persistent keys to a file.
Definition: NetworkTable.cpp:130
virtual bool PutString(llvm::StringRef key, llvm::StringRef value) override
Put a string in the table.
Definition: NetworkTable.cpp:378
virtual bool SetDefaultValue(llvm::StringRef key, std::shared_ptr< nt::Value > defaultValue) override
Gets the current value in the table, setting it if it does not exist.
Definition: NetworkTable.cpp:557
bool ContainsKey(llvm::StringRef key) const override
Determines whether the given key is in this table.
Definition: NetworkTable.cpp:265
static void SetClientMode()
set that network tables should be a client This must be called before initialize or GetTable ...
Definition: NetworkTable.cpp:41