8 #ifndef NETWORKTABLE_H_ 9 #define NETWORKTABLE_H_ 15 #include "llvm/StringMap.h" 16 #include "networktables/NetworkTableEntry.h" 17 #include "networktables/TableEntryListener.h" 18 #include "networktables/TableListener.h" 20 #include "tables/ITable.h" 27 class NetworkTableInstance;
30 #pragma GCC diagnostic push 31 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 41 mutable std::mutex m_mutex;
43 typedef std::pair<ITableListener*, NT_EntryListener> Listener;
44 std::vector<Listener> m_listeners;
46 static std::vector<std::string> s_ip_addresses;
47 static std::string s_persistent_filename;
49 static bool s_enable_ds;
50 static bool s_running;
51 static unsigned int s_port;
72 "use NetworkTableInstance::StartServer() or " 73 "NetworkTableInstance::StartClient() instead")
74 static
void Initialize();
82 static
void Shutdown();
107 static
void SetTeam(
int team);
116 static
void SetIPAddress(
StringRef address);
125 static
void SetIPAddress(
ArrayRef<
std::
string> addresses);
137 static
void SetPort(
unsigned int port);
146 static
void SetDSClientEnabled(
bool enabled);
156 static
void SetPersistentFilename(
StringRef filename);
209 std::function<
void(
size_t line, const
char* msg)> warn);
239 unsigned int flags) const;
249 unsigned int flags) const;
266 bool localNotify = false) const;
277 void AddTableListener(ITableListener* listener) override;
281 "NT_NOTIFY_UPDATE | NT_NOTIFY_IMMEDIATE")
282 void AddTableListener(ITableListener* listener,
283 bool immediateNotify) override;
286 void AddTableListenerEx(ITableListener* listener,
287 unsigned int flags) override;
290 void AddTableListener(
StringRef key, ITableListener* listener,
291 bool immediateNotify) override;
294 void AddTableListenerEx(
StringRef key, ITableListener* listener,
295 unsigned int flags) override;
338 std::vector<
std::
string>
GetKeys(
int types = 0) const override;
504 ArrayRef<
int> defaultValue) override;
522 ArrayRef<
int> defaultValue) const override;
539 ArrayRef<
double> defaultValue) override;
631 std::shared_ptr<
Value> defaultValue) override;
665 std::function<
void(
size_t line, const
char* msg)> warn);
669 #pragma GCC diagnostic pop 675 #ifndef NAMESPACED_NT 679 #endif // NETWORKTABLE_H_ std::shared_ptr< Value > GetValue(StringRef key) const override
Gets the value associated with a key as an object.
Definition: NetworkTable.cpp:458
void RemoveEntryListener(NT_EntryListener listener) const
Remove an entry listener.
Definition: NetworkTable.cpp:180
bool PutNumberArray(StringRef key, ArrayRef< double > value) override
Put a number array in the table.
Definition: NetworkTable.cpp:406
std::vector< double > GetNumberArray(StringRef key, ArrayRef< double > defaultValue) const override
Returns the number array the key maps to.
Definition: NetworkTable.cpp:416
void SetServer(const char *server_name, unsigned int port)
Sets server address and port for client (without restarting client).
Definition: ntcore_cpp.cpp:821
bool SetDefaultString(StringRef key, StringRef defaultValue) override
Gets the current value in the table, setting it if it does not exist.
Definition: NetworkTable.cpp:370
static void SetServerMode()
set that network tables should be a server This must be called before initialize or GetTable ...
Definition: NetworkTable.cpp:49
static void SetNetworkIdentity(StringRef name)
Sets the network identity.
Definition: NetworkTable.cpp:98
void SetPersistent(StringRef key) override
Makes a key's value persistent through program restarts.
Definition: NetworkTable.cpp:328
double GetNumber(StringRef key, double defaultValue) const override
Gets the number associated with the given name.
Definition: NetworkTable.cpp:362
void RemoveTableListener(NT_EntryListener listener) const
Remove a sub-table listener.
bool PutRaw(StringRef key, StringRef value) override
Put a raw value (byte array) in the table.
Definition: NetworkTable.cpp:436
Definition: json.cpp:1170
static void SetUpdateRate(double interval)
Set the periodic update rate.
Definition: NetworkTable.cpp:108
bool SetDefaultNumberArray(StringRef key, ArrayRef< double > defaultValue) override
Gets the current value in the table, setting it if it does not exist.
Definition: NetworkTable.cpp:411
bool ContainsSubTable(StringRef key) const override
Determines whether there exists a non-empty subtable for this key in this table.
Definition: NetworkTable.cpp:292
bool PutString(StringRef key, StringRef value) override
Put a string in the table.
Definition: NetworkTable.cpp:366
static void Flush()
Flushes all updated values immediately to the network.
Definition: NetworkTable.cpp:106
static const char PATH_SEPARATOR_CHAR
The path separator for sub-tables and keys.
Definition: NetworkTable.h:66
std::string GetString(StringRef key, StringRef defaultValue) const override
Gets the string associated with the given name.
Definition: NetworkTable.cpp:374
bool ContainsKey(StringRef key) const override
Determines whether the given key is in this table.
Definition: NetworkTable.cpp:288
NetworkTableInstance GetInstance() const
Gets the instance for the table.
Definition: NetworkTable.cpp:134
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:32
NetworkTables Instance.
Definition: NetworkTableInstance.h:59
bool SetDefaultBoolean(StringRef key, bool defaultValue) override
Gets the current value in the table, setting it if it does not exist.
Definition: NetworkTable.cpp:383
NT_EntryListener AddSubTableListener(TableListener listener, bool localNotify=false) const
Listen for sub-table creation.
static void GlobalDeleteAll()
Deletes ALL keys in ALL subtables.
Definition: NetworkTable.cpp:102
void ClearPersistent(StringRef key) override
Stop making a key's value persistent through program restarts.
Definition: NetworkTable.cpp:332
std::vector< int > GetBooleanArray(StringRef key, ArrayRef< int > defaultValue) const override
Returns the boolean array the key maps to.
Definition: NetworkTable.cpp:401
void StopServer()
Stops the server if it is running.
Definition: ntcore_cpp.cpp:757
static void SetClientMode()
set that network tables should be a client This must be called before initialize or GetTable ...
Definition: NetworkTable.cpp:47
NT_Entry GetEntry(NT_Inst inst, StringRef name)
Get Entry Handle.
Definition: ntcore_cpp.cpp:55
void StartDSClient(unsigned int port)
Starts requesting server address from Driver Station.
Definition: ntcore_cpp.cpp:851
void StopDSClient()
Stops requesting server address from Driver Station.
Definition: ntcore_cpp.cpp:862
std::vector< std::string > GetStringArray(StringRef key, ArrayRef< std::string > defaultValue) const override
Returns the string array the key maps to.
Definition: NetworkTable.cpp:431
Definition: IEntryNotifier.h:15
NT_EntryListener AddEntryListener(TableEntryListener listener, unsigned int flags) const
Listen to keys only within this table.
Definition: NetworkTable.cpp:150
unsigned int GetFlags(StringRef key) const override
Returns the flags for the specified key.
Definition: NetworkTable.cpp:348
const char * LoadEntries(StringRef filename, std::function< void(size_t line, const char *msg)> warn)
Load table values from a file.
Definition: NetworkTable.cpp:470
bool PutStringArray(StringRef key, ArrayRef< std::string > value) override
Put a string array in the table.
Definition: NetworkTable.cpp:421
StringRef GetPath() const override
Gets the full path of this table.
Definition: NetworkTable.cpp:462
std::shared_ptr< NetworkTable > GetSubTable(StringRef key) const override
Returns the table at the specified key.
Definition: NetworkTable.cpp:281
std::vector< std::string > GetSubTables() const override
Gets the names of all subtables in the table.
Definition: NetworkTable.cpp:315
void SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port)
Sets server addresses and port for client (without restarting client).
Definition: ntcore_cpp.cpp:844
void StartServer(StringRef persist_filename, const char *listen_address, unsigned int port)
Starts a server using the specified filename, listening address, and port.
Definition: ntcore_cpp.cpp:743
bool SetDefaultRaw(StringRef key, StringRef defaultValue) override
Gets the current value in the table, setting it if it does not exist.
Definition: NetworkTable.cpp:440
const char * SaveEntries(StringRef filename) const
Save table values to a file.
Definition: NetworkTable.cpp:464
static const char * SavePersistent(StringRef filename)
Saves persistent keys to a file.
Definition: NetworkTable.cpp:112
WPI_DEPRECATED("use NetworkTableInstance::StartServer() or ""NetworkTableInstance::StartClient() instead") static void Initialize()
Initializes network tables.
void DeleteAllEntries()
Delete All Entries.
Definition: ntcore_cpp.cpp:195
bool PutBooleanArray(StringRef key, ArrayRef< int > value) override
Put a boolean array in the table.
Definition: NetworkTable.cpp:391
bool GetBoolean(StringRef key, bool defaultValue) const override
Gets the boolean associated with the given name.
Definition: NetworkTable.cpp:387
bool IsPersistent(StringRef key) const override
Returns whether the value is persistent through program restarts.
Definition: NetworkTable.cpp:336
std::string GetRaw(StringRef key, StringRef defaultValue) const override
Returns the raw value (byte array) the key maps to.
Definition: NetworkTable.cpp:444
bool SetDefaultNumber(StringRef key, double defaultValue) override
Gets the current value in the table, setting it if it does not exist.
Definition: NetworkTable.cpp:358
NetworkTables Entry.
Definition: NetworkTableEntry.h:30
bool PutValue(StringRef key, std::shared_ptr< Value > value) override
Put a value in the table.
Definition: NetworkTable.cpp:449
std::vector< std::string > GetKeys(int types=0) const override
Gets all keys in the table (not including sub-tables).
Definition: NetworkTable.cpp:300
void ClearFlags(StringRef key, unsigned int flags) override
Clears flags on the specified key in this table.
Definition: NetworkTable.cpp:344
static const char * LoadPersistent(StringRef filename, std::function< void(size_t line, const char *msg)> warn)
Loads persistent keys from a file.
Definition: NetworkTable.cpp:116
bool PutNumber(StringRef key, double value) override
Put a number in the table.
Definition: NetworkTable.cpp:354
bool SetDefaultBooleanArray(StringRef key, ArrayRef< int > defaultValue) override
Gets the current value in the table, setting it if it does not exist.
Definition: NetworkTable.cpp:396
void SetFlags(StringRef key, unsigned int flags) override
Sets flags on the specified key in this table.
Definition: NetworkTable.cpp:340
void Delete(StringRef key) override
Deletes the specified key in this table.
Definition: NetworkTable.cpp:352
A network table entry value.
Definition: NetworkTableValue.h:30
A network table that knows its subtable path.
Definition: NetworkTable.h:37
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:42
bool PutBoolean(StringRef key, bool value) override
Put a boolean in the table.
Definition: NetworkTable.cpp:379
bool SetDefaultStringArray(StringRef key, ArrayRef< std::string > defaultValue) override
Gets the current value in the table, setting it if it does not exist.
Definition: NetworkTable.cpp:426
void StopClient()
Stops the client if it is running.
Definition: ntcore_cpp.cpp:812
void StartClient()
Starts a client.
Definition: ntcore_cpp.cpp:766
void StartClientTeam(NT_Inst inst, unsigned int team, unsigned int port)
Starts a client using commonly known robot addresses for the specified team.
Definition: ntcore_cpp.cpp:804
bool SetDefaultValue(StringRef key, std::shared_ptr< Value > defaultValue) override
Gets the current value in the table, setting it if it does not exist.
Definition: NetworkTable.cpp:453