WPILibC++ 2023.4.3
NetworkTableInstance.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <functional>
8#include <memory>
9#include <optional>
10#include <span>
11#include <string>
12#include <string_view>
13#include <utility>
14#include <vector>
15
18#include "ntcore_c.h"
19#include "ntcore_cpp.h"
20
21namespace nt {
22
23class BooleanArrayTopic;
24class BooleanTopic;
25class DoubleArrayTopic;
26class DoubleTopic;
27class FloatArrayTopic;
28class FloatTopic;
29class IntegerArrayTopic;
30class IntegerTopic;
31class MultiSubscriber;
32class RawTopic;
33class StringArrayTopic;
34class StringTopic;
35class Subscriber;
36class Topic;
37
38/**
39 * NetworkTables Instance.
40 *
41 * Instances are completely independent from each other. Table operations on
42 * one instance will not be visible to other instances unless the instances are
43 * connected via the network. The main limitation on instances is that you
44 * cannot have two servers on the same network port. The main utility of
45 * instances is for unit testing, but they can also enable one program to
46 * connect to two different NetworkTables networks.
47 *
48 * The global "default" instance (as returned by GetDefault()) is
49 * always available, and is intended for the common case when there is only
50 * a single NetworkTables instance being used in the program. The
51 * default instance cannot be destroyed.
52 *
53 * Additional instances can be created with the Create() function.
54 * Instances are not reference counted or RAII. Instead, they must be
55 * explicitly destroyed (with Destroy()).
56 *
57 * @ingroup ntcore_cpp_api
58 */
60 public:
61 /**
62 * Client/server mode flag values (as returned by GetNetworkMode()).
63 * This is a bitmask.
64 */
71 };
72
73 /**
74 * Logging levels (as used by SetLogger()).
75 */
76 enum LogLevel {
86 };
87
88 /**
89 * The default port that network tables operates on for NT3.
90 */
91 static constexpr unsigned int kDefaultPort3 = NT_DEFAULT_PORT3;
92
93 /**
94 * The default port that network tables operates on for NT4.
95 */
96 static constexpr unsigned int kDefaultPort4 = NT_DEFAULT_PORT4;
97
98 /**
99 * Construct invalid instance.
100 */
101 NetworkTableInstance() noexcept;
102
103 /**
104 * Construct from native handle.
105 *
106 * @param inst Native handle
107 */
108 explicit NetworkTableInstance(NT_Inst inst) noexcept;
109
110 /**
111 * Determines if the native handle is valid.
112 *
113 * @return True if the native handle is valid, false otherwise.
114 */
115 explicit operator bool() const { return m_handle != 0; }
116
117 /**
118 * Get global default instance.
119 *
120 * @return Global default instance
121 */
123
124 /**
125 * Create an instance.
126 *
127 * @return Newly created instance
128 */
130
131 /**
132 * Destroys an instance (note: this has global effect).
133 *
134 * @param inst Instance
135 */
136 static void Destroy(NetworkTableInstance& inst);
137
138 /**
139 * Gets the native handle for the entry.
140 *
141 * @return Native handle
142 */
143 NT_Inst GetHandle() const;
144
145 /**
146 * Gets a "generic" (untyped) topic.
147 *
148 * @param name topic name
149 * @return Topic
150 */
152
153 /**
154 * Gets a boolean topic.
155 *
156 * @param name topic name
157 * @return Topic
158 */
160
161 /**
162 * Gets an integer topic.
163 *
164 * @param name topic name
165 * @return Topic
166 */
168
169 /**
170 * Gets a float topic.
171 *
172 * @param name topic name
173 * @return Topic
174 */
176
177 /**
178 * Gets a double topic.
179 *
180 * @param name topic name
181 * @return Topic
182 */
184
185 /**
186 * Gets a string topic.
187 *
188 * @param name topic name
189 * @return Topic
190 */
192
193 /**
194 * Gets a raw topic.
195 *
196 * @param name topic name
197 * @return Topic
198 */
200
201 /**
202 * Gets a boolean array topic.
203 *
204 * @param name topic name
205 * @return Topic
206 */
208
209 /**
210 * Gets an integer array topic.
211 *
212 * @param name topic name
213 * @return Topic
214 */
216
217 /**
218 * Gets a float array topic.
219 *
220 * @param name topic name
221 * @return Topic
222 */
224
225 /**
226 * Gets a double array topic.
227 *
228 * @param name topic name
229 * @return Topic
230 */
232
233 /**
234 * Gets a string array topic.
235 *
236 * @param name topic name
237 * @return Topic
238 */
240
241 /**
242 * Get Published Topics.
243 *
244 * Returns an array of topics.
245 *
246 * @return Array of topics.
247 */
248 std::vector<Topic> GetTopics();
249
250 /**
251 * Get Published Topics.
252 *
253 * Returns an array of topics. The results are filtered by
254 * string prefix to only return a subset of all topics.
255 *
256 * @param prefix name required prefix; only topics whose name
257 * starts with this string are returned
258 * @return Array of topics.
259 */
260 std::vector<Topic> GetTopics(std::string_view prefix);
261
262 /**
263 * Get Published Topics.
264 *
265 * Returns an array of topics. The results are filtered by
266 * string prefix and type to only return a subset of all topics.
267 *
268 * @param prefix name required prefix; only topics whose name
269 * starts with this string are returned
270 * @param types bitmask of NT_Type values; 0 is treated specially
271 * as a "don't care"
272 * @return Array of topics.
273 */
274 std::vector<Topic> GetTopics(std::string_view prefix, unsigned int types);
275
276 /**
277 * Get Published Topics.
278 *
279 * Returns an array of topics. The results are filtered by
280 * string prefix and type to only return a subset of all topics.
281 *
282 * @param prefix name required prefix; only topics whose name
283 * starts with this string are returned
284 * @param types array of type strings
285 * @return Array of topic handles.
286 */
287 std::vector<Topic> GetTopics(std::string_view prefix,
288 std::span<std::string_view> types);
289
290 /**
291 * Get Topic Information about multiple topics.
292 *
293 * Returns an array of topic information (handle, name, type, and properties).
294 *
295 * @return Array of topic information.
296 */
297 std::vector<TopicInfo> GetTopicInfo();
298
299 /**
300 * Get Topic Information about multiple topics.
301 *
302 * Returns an array of topic information (handle, name, type, and properties).
303 * The results are filtered by string prefix to only
304 * return a subset of all topics.
305 *
306 * @param prefix name required prefix; only topics whose name
307 * starts with this string are returned
308 * @return Array of topic information.
309 */
310 std::vector<TopicInfo> GetTopicInfo(std::string_view prefix);
311
312 /**
313 * Get Topic Information about multiple topics.
314 *
315 * Returns an array of topic information (handle, name, type, and properties).
316 * The results are filtered by string prefix and type to only
317 * return a subset of all topics.
318 *
319 * @param prefix name required prefix; only topics whose name
320 * starts with this string are returned
321 * @param types bitmask of NT_Type values; 0 is treated specially
322 * as a "don't care"
323 * @return Array of topic information.
324 */
325 std::vector<TopicInfo> GetTopicInfo(std::string_view prefix,
326 unsigned int types);
327
328 /**
329 * Get Topic Information about multiple topics.
330 *
331 * Returns an array of topic information (handle, name, type, and properties).
332 * The results are filtered by string prefix and type to only
333 * return a subset of all topics.
334 *
335 * @param prefix name required prefix; only topics whose name
336 * starts with this string are returned
337 * @param types array of type strings
338 * @return Array of topic information.
339 */
340 std::vector<TopicInfo> GetTopicInfo(std::string_view prefix,
341 std::span<std::string_view> types);
342
343 /**
344 * Gets the entry for a key.
345 *
346 * @param name Key
347 * @return Network table entry.
348 */
350
351 /**
352 * Gets the table with the specified key.
353 *
354 * @param key the key name
355 * @return The network table
356 */
357 std::shared_ptr<NetworkTable> GetTable(std::string_view key) const;
358
359 /**
360 * @{
361 * @name Listener Functions
362 */
363
364 /**
365 * Remove a listener.
366 *
367 * @param listener Listener handle to remove
368 */
369 static void RemoveListener(NT_Listener listener);
370
371 /**
372 * Wait for the listener queue to be empty. This is primarily
373 * useful for deterministic testing. This blocks until either the
374 * listener queue is empty (e.g. there are no more events that need to be
375 * passed along to callbacks or poll queues) or the timeout expires.
376 *
377 * @param timeout timeout, in seconds. Set to 0 for non-blocking behavior, or
378 * a negative value to block indefinitely
379 * @return False if timed out, otherwise true.
380 */
381 bool WaitForListenerQueue(double timeout);
382
383 /**
384 * Add a connection listener. The callback function is called asynchronously
385 * on a separate thread, so it's important to use synchronization or atomics
386 * when accessing any shared state from the callback function.
387 *
388 * @param immediate_notify notify listener of all existing connections
389 * @param callback listener to add
390 * @return Listener handle
391 */
392 NT_Listener AddConnectionListener(bool immediate_notify,
393 ListenerCallback callback) const;
394
395 /**
396 * Add a time synchronization listener. The callback function is called
397 * asynchronously on a separate thread, so it's important to use
398 * synchronization or atomics when accessing any shared state from the
399 * callback function.
400 *
401 * @param immediate_notify notify listener of current time synchronization
402 * value
403 * @param callback listener to add
404 * @return Listener handle
405 */
406 NT_Listener AddTimeSyncListener(bool immediate_notify,
407 ListenerCallback callback) const;
408
409 /**
410 * Add a listener for changes on a particular topic. The callback
411 * function is called asynchronously on a separate thread, so it's important
412 * to use synchronization or atomics when accessing any shared state from the
413 * callback function.
414 *
415 * This creates a corresponding internal subscriber with the lifetime of the
416 * listener.
417 *
418 * @param topic Topic
419 * @param eventMask Bitmask of EventFlags values
420 * @param listener Listener function
421 * @return Listener handle
422 */
423 NT_Listener AddListener(Topic topic, unsigned int eventMask,
424 ListenerCallback listener);
425
426 /**
427 * Add a listener for changes on a subscriber. The callback
428 * function is called asynchronously on a separate thread, so it's important
429 * to use synchronization or atomics when accessing any shared state from the
430 * callback function. This does NOT keep the subscriber active.
431 *
432 * @param subscriber Subscriber
433 * @param eventMask Bitmask of EventFlags values
434 * @param listener Listener function
435 * @return Listener handle
436 */
437 NT_Listener AddListener(Subscriber& subscriber, unsigned int eventMask,
438 ListenerCallback listener);
439
440 /**
441 * Add a listener for changes on a subscriber. The callback
442 * function is called asynchronously on a separate thread, so it's important
443 * to use synchronization or atomics when accessing any shared state from the
444 * callback function. This does NOT keep the subscriber active.
445 *
446 * @param subscriber Subscriber
447 * @param eventMask Bitmask of EventFlags values
448 * @param listener Listener function
449 * @return Listener handle
450 */
451 NT_Listener AddListener(MultiSubscriber& subscriber, int eventMask,
452 ListenerCallback listener);
453
454 /**
455 * Add a listener for changes on an entry. The callback function
456 * is called asynchronously on a separate thread, so it's important to use
457 * synchronization or atomics when accessing any shared state from the
458 * callback function.
459 *
460 * @param entry Entry
461 * @param eventMask Bitmask of EventFlags values
462 * @param listener Listener function
463 * @return Listener handle
464 */
465 NT_Listener AddListener(const NetworkTableEntry& entry, int eventMask,
466 ListenerCallback listener);
467
468 /**
469 * Add a listener for changes to topics with names that start with any
470 * of the given prefixes. The callback function is called asynchronously on a
471 * separate thread, so it's important to use synchronization or atomics when
472 * accessing any shared state from the callback function.
473 *
474 * This creates a corresponding internal subscriber with the lifetime of the
475 * listener.
476 *
477 * @param prefixes Topic name string prefixes
478 * @param eventMask Bitmask of EventFlags values
479 * @param listener Listener function
480 * @return Listener handle
481 */
482 NT_Listener AddListener(std::span<const std::string_view> prefixes,
483 int eventMask, ListenerCallback listener);
484
485 /** @} */
486
487 /**
488 * @{
489 * @name Client/Server Functions
490 */
491
492 /**
493 * Get the current network mode.
494 *
495 * @return Bitmask of NetworkMode.
496 */
497 unsigned int GetNetworkMode() const;
498
499 /**
500 * Starts local-only operation. Prevents calls to StartServer or StartClient
501 * from taking effect. Has no effect if StartServer or StartClient
502 * has already been called.
503 */
504 void StartLocal();
505
506 /**
507 * Stops local-only operation. StartServer or StartClient can be called after
508 * this call to start a server or client.
509 */
510 void StopLocal();
511
512 /**
513 * Starts a server using the specified filename, listening address, and port.
514 *
515 * @param persist_filename the name of the persist file to use (UTF-8 string,
516 * null terminated)
517 * @param listen_address the address to listen on, or null to listen on any
518 * address (UTF-8 string, null terminated)
519 * @param port3 port to communicate over (NT3)
520 * @param port4 port to communicate over (NT4)
521 */
522 void StartServer(std::string_view persist_filename = "networktables.json",
523 const char* listen_address = "",
524 unsigned int port3 = kDefaultPort3,
525 unsigned int port4 = kDefaultPort4);
526
527 /**
528 * Stops the server if it is running.
529 */
530 void StopServer();
531
532 /**
533 * Starts a NT3 client. Use SetServer or SetServerTeam to set the server name
534 * and port.
535 *
536 * @param identity network identity to advertise (cannot be empty string)
537 */
538 void StartClient3(std::string_view identity);
539
540 /**
541 * Starts a NT4 client. Use SetServer or SetServerTeam to set the server name
542 * and port.
543 *
544 * @param identity network identity to advertise (cannot be empty string)
545 */
546 void StartClient4(std::string_view identity);
547
548 /**
549 * Stops the client if it is running.
550 */
551 void StopClient();
552
553 /**
554 * Sets server address and port for client (without restarting client).
555 *
556 * @param server_name server name (UTF-8 string, null terminated)
557 * @param port port to communicate over (0 = default)
558 */
559 void SetServer(const char* server_name, unsigned int port = 0);
560
561 /**
562 * Sets server addresses and ports for client (without restarting client).
563 * The client will attempt to connect to each server in round robin fashion.
564 *
565 * @param servers array of server address and port pairs
566 */
567 void SetServer(
568 std::span<const std::pair<std::string_view, unsigned int>> servers);
569
570 /**
571 * Sets server addresses and port for client (without restarting client).
572 * The client will attempt to connect to each server in round robin fashion.
573 *
574 * @param servers array of server names
575 * @param port port to communicate over (0 = default)
576 */
577 void SetServer(std::span<const std::string_view> servers,
578 unsigned int port = 0);
579
580 /**
581 * Sets server addresses and port for client (without restarting client).
582 * Connects using commonly known robot addresses for the specified team.
583 *
584 * @param team team number
585 * @param port port to communicate over (0 = default)
586 */
587 void SetServerTeam(unsigned int team, unsigned int port = 0);
588
589 /**
590 * Disconnects the client if it's running and connected. This will
591 * automatically start reconnection attempts to the current server list.
592 */
593 void Disconnect();
594
595 /**
596 * Starts requesting server address from Driver Station.
597 * This connects to the Driver Station running on localhost to obtain the
598 * server IP address.
599 *
600 * @param port server port to use in combination with IP from DS (0 = default)
601 */
602 void StartDSClient(unsigned int port = 0);
603
604 /**
605 * Stops requesting server address from Driver Station.
606 */
607 void StopDSClient();
608
609 /**
610 * Flushes all updated values immediately to the local client/server. This
611 * does not flush to the network.
612 */
613 void FlushLocal() const;
614
615 /**
616 * Flushes all updated values immediately to the network.
617 * @note This is rate-limited to protect the network from flooding.
618 * This is primarily useful for synchronizing network updates with
619 * user code.
620 */
621 void Flush() const;
622
623 /**
624 * Get information on the currently established network connections.
625 * If operating as a client, this will return either zero or one values.
626 *
627 * @return array of connection information
628 */
629 std::vector<ConnectionInfo> GetConnections() const;
630
631 /**
632 * Return whether or not the instance is connected to another node.
633 *
634 * @return True if connected.
635 */
636 bool IsConnected() const;
637
638 /**
639 * Get the time offset between server time and local time. Add this value to
640 * local time to get the estimated equivalent server time. In server mode,
641 * this always returns 0. In client mode, this returns the time offset only if
642 * the client and server are connected and have exchanged synchronization
643 * messages. Note the time offset may change over time as it is periodically
644 * updated; to receive updates as events, add a listener to the "time sync"
645 * event.
646 *
647 * @return Time offset in microseconds (optional)
648 */
649 std::optional<int64_t> GetServerTimeOffset() const;
650
651 /** @} */
652
653 /**
654 * @{
655 * @name Data Logger Functions
656 */
657
658 /**
659 * Starts logging entry changes to a DataLog.
660 *
661 * @param log data log object; lifetime must extend until StopEntryDataLog is
662 * called or the instance is destroyed
663 * @param prefix only store entries with names that start with this prefix;
664 * the prefix is not included in the data log entry name
665 * @param logPrefix prefix to add to data log entry names
666 * @return Data logger handle
667 */
669 std::string_view prefix,
670 std::string_view logPrefix);
671
672 /**
673 * Stops logging entry changes to a DataLog.
674 *
675 * @param logger data logger handle
676 */
677 static void StopEntryDataLog(NT_DataLogger logger);
678
679 /**
680 * Starts logging connection changes to a DataLog.
681 *
682 * @param log data log object; lifetime must extend until
683 * StopConnectionDataLog is called or the instance is destroyed
684 * @param name data log entry name
685 * @return Data logger handle
686 */
688 std::string_view name);
689
690 /**
691 * Stops logging connection changes to a DataLog.
692 *
693 * @param logger data logger handle
694 */
696
697 /** @} */
698
699 /**
700 * @{
701 * @name Logger Functions
702 */
703
704 /**
705 * Add logger callback function. By default, log messages are sent to stderr;
706 * this function sends log messages with the specified levels to the provided
707 * callback function instead. The callback function will only be called for
708 * log messages with level greater than or equal to minLevel and less than or
709 * equal to maxLevel; messages outside this range will be silently ignored.
710 *
711 * @param minLevel minimum log level
712 * @param maxLevel maximum log level
713 * @param func callback function
714 * @return Listener handle
715 */
716 NT_Listener AddLogger(unsigned int minLevel, unsigned int maxLevel,
717 ListenerCallback func);
718
719 /** @} */
720
721 /**
722 * Equality operator. Returns true if both instances refer to the same
723 * native handle.
724 */
725 bool operator==(const NetworkTableInstance&) const = default;
726
727 private:
728 /* Native handle */
729 NT_Inst m_handle{0};
730};
731
732} // namespace nt
733
NetworkTables BooleanArray topic.
Definition: BooleanArrayTopic.h:263
NetworkTables Boolean topic.
Definition: BooleanTopic.h:210
NetworkTables DoubleArray topic.
Definition: DoubleArrayTopic.h:263
NetworkTables Double topic.
Definition: DoubleTopic.h:210
NetworkTables FloatArray topic.
Definition: FloatArrayTopic.h:263
NetworkTables Float topic.
Definition: FloatTopic.h:210
NetworkTables IntegerArray topic.
Definition: IntegerArrayTopic.h:263
NetworkTables Integer topic.
Definition: IntegerTopic.h:210
Subscribe to multiple topics based on one or more topic name prefixes.
Definition: MultiSubscriber.h:20
NetworkTables Entry.
Definition: NetworkTableEntry.h:36
NetworkTables Instance.
Definition: NetworkTableInstance.h:59
void StartClient4(std::string_view identity)
Starts a NT4 client.
Definition: NetworkTableInstance.inc:143
static NetworkTableInstance GetDefault()
Get global default instance.
Definition: NetworkTableInstance.inc:22
IntegerArrayTopic GetIntegerArrayTopic(std::string_view name) const
Gets an integer array topic.
NetworkMode
Client/server mode flag values (as returned by GetNetworkMode()).
Definition: NetworkTableInstance.h:65
@ kNetModeClient4
Definition: NetworkTableInstance.h:69
@ kNetModeServer
Definition: NetworkTableInstance.h:67
@ kNetModeLocal
Definition: NetworkTableInstance.h:70
@ kNetModeClient3
Definition: NetworkTableInstance.h:68
@ kNetModeNone
Definition: NetworkTableInstance.h:66
static NetworkTableInstance Create()
Create an instance.
Definition: NetworkTableInstance.inc:26
BooleanTopic GetBooleanTopic(std::string_view name) const
Gets a boolean topic.
FloatTopic GetFloatTopic(std::string_view name) const
Gets a float topic.
bool IsConnected() const
Return whether or not the instance is connected to another node.
Definition: NetworkTableInstance.inc:191
NetworkTableInstance() noexcept
Construct invalid instance.
Definition: NetworkTableInstance.inc:17
NT_Listener AddListener(const NetworkTableEntry &entry, int eventMask, ListenerCallback listener)
Add a listener for changes on an entry.
NT_Listener AddConnectionListener(bool immediate_notify, ListenerCallback callback) const
Add a connection listener.
Definition: NetworkTableInstance.inc:95
void StartLocal()
Starts local-only operation.
Definition: NetworkTableInstance.inc:120
static void StopEntryDataLog(NT_DataLogger logger)
Stops logging entry changes to a DataLog.
Definition: NetworkTableInstance.inc:206
bool WaitForListenerQueue(double timeout)
Wait for the listener queue to be empty.
Definition: NetworkTableInstance.inc:87
DoubleArrayTopic GetDoubleArrayTopic(std::string_view name) const
Gets a double array topic.
NT_Listener AddLogger(unsigned int minLevel, unsigned int maxLevel, ListenerCallback func)
Add logger callback function.
Definition: NetworkTableInstance.inc:220
void StartDSClient(unsigned int port=0)
Starts requesting server address from Driver Station.
Definition: NetworkTableInstance.inc:170
NT_Listener AddListener(MultiSubscriber &subscriber, int eventMask, ListenerCallback listener)
Add a listener for changes on a subscriber.
void FlushLocal() const
Flushes all updated values immediately to the local client/server.
Definition: NetworkTableInstance.inc:178
StringArrayTopic GetStringArrayTopic(std::string_view name) const
Gets a string array topic.
FloatArrayTopic GetFloatArrayTopic(std::string_view name) const
Gets a float array topic.
NT_ConnectionDataLogger StartConnectionDataLog(wpi::log::DataLog &log, std::string_view name)
Starts logging connection changes to a DataLog.
Definition: NetworkTableInstance.inc:210
unsigned int GetNetworkMode() const
Get the current network mode.
Definition: NetworkTableInstance.inc:116
NT_Inst GetHandle() const
Gets the native handle for the entry.
Definition: NetworkTableInstance.inc:37
static constexpr unsigned int kDefaultPort4
The default port that network tables operates on for NT4.
Definition: NetworkTableInstance.h:96
NT_DataLogger StartEntryDataLog(wpi::log::DataLog &log, std::string_view prefix, std::string_view logPrefix)
Starts logging entry changes to a DataLog.
Definition: NetworkTableInstance.inc:200
NetworkTableEntry GetEntry(std::string_view name)
Gets the entry for a key.
Definition: NetworkTableInstance.inc:83
NT_Listener AddListener(Subscriber &subscriber, unsigned int eventMask, ListenerCallback listener)
Add a listener for changes on a subscriber.
BooleanArrayTopic GetBooleanArrayTopic(std::string_view name) const
Gets a boolean array topic.
StringTopic GetStringTopic(std::string_view name) const
Gets a string topic.
static constexpr unsigned int kDefaultPort3
The default port that network tables operates on for NT3.
Definition: NetworkTableInstance.h:91
void StopServer()
Stops the server if it is running.
Definition: NetworkTableInstance.inc:135
void SetServer(const char *server_name, unsigned int port=0)
Sets server address and port for client (without restarting client).
Definition: NetworkTableInstance.inc:151
void SetServerTeam(unsigned int team, unsigned int port=0)
Sets server addresses and port for client (without restarting client).
Definition: NetworkTableInstance.inc:161
bool operator==(const NetworkTableInstance &) const =default
Equality operator.
void StopDSClient()
Stops requesting server address from Driver Station.
Definition: NetworkTableInstance.inc:174
LogLevel
Logging levels (as used by SetLogger()).
Definition: NetworkTableInstance.h:76
@ kLogInfo
Definition: NetworkTableInstance.h:80
@ kLogError
Definition: NetworkTableInstance.h:78
@ kLogWarning
Definition: NetworkTableInstance.h:79
@ kLogDebug4
Definition: NetworkTableInstance.h:85
@ kLogDebug3
Definition: NetworkTableInstance.h:84
@ kLogCritical
Definition: NetworkTableInstance.h:77
@ kLogDebug
Definition: NetworkTableInstance.h:81
@ kLogDebug1
Definition: NetworkTableInstance.h:82
@ kLogDebug2
Definition: NetworkTableInstance.h:83
void Disconnect()
Disconnects the client if it's running and connected.
Definition: NetworkTableInstance.inc:166
void Flush() const
Flushes all updated values immediately to the network.
Definition: NetworkTableInstance.inc:182
NT_Listener AddListener(Topic topic, unsigned int eventMask, ListenerCallback listener)
Add a listener for changes on a particular topic.
std::shared_ptr< NetworkTable > GetTable(std::string_view key) const
Gets the table with the specified key.
NT_Listener AddTimeSyncListener(bool immediate_notify, ListenerCallback callback) const
Add a time synchronization listener.
Definition: NetworkTableInstance.inc:103
static void RemoveListener(NT_Listener listener)
Remove a listener.
Definition: NetworkTableInstance.inc:91
RawTopic GetRawTopic(std::string_view name) const
Gets a raw topic.
std::vector< TopicInfo > GetTopicInfo()
Get Topic Information about multiple topics.
Definition: NetworkTableInstance.inc:64
DoubleTopic GetDoubleTopic(std::string_view name) const
Gets a double topic.
Topic GetTopic(std::string_view name) const
Gets a "generic" (untyped) topic.
void StartServer(std::string_view persist_filename="networktables.json", const char *listen_address="", unsigned int port3=kDefaultPort3, unsigned int port4=kDefaultPort4)
Starts a server using the specified filename, listening address, and port.
Definition: NetworkTableInstance.inc:128
void StopLocal()
Stops local-only operation.
Definition: NetworkTableInstance.inc:124
std::vector< ConnectionInfo > GetConnections() const
Get information on the currently established network connections.
Definition: NetworkTableInstance.inc:186
static void Destroy(NetworkTableInstance &inst)
Destroys an instance (note: this has global effect).
Definition: NetworkTableInstance.inc:30
void StopClient()
Stops the client if it is running.
Definition: NetworkTableInstance.inc:147
static void StopConnectionDataLog(NT_ConnectionDataLogger logger)
Stops logging connection changes to a DataLog.
Definition: NetworkTableInstance.inc:215
std::optional< int64_t > GetServerTimeOffset() const
Get the time offset between server time and local time.
Definition: NetworkTableInstance.inc:195
IntegerTopic GetIntegerTopic(std::string_view name) const
Gets an integer topic.
std::vector< Topic > GetTopics()
Get Published Topics.
Definition: NetworkTableInstance.inc:41
void SetServer(std::span< const std::string_view > servers, unsigned int port=0)
Sets server addresses and port for client (without restarting client).
void StartClient3(std::string_view identity)
Starts a NT3 client.
Definition: NetworkTableInstance.inc:139
NetworkTables Raw topic.
Definition: RawTopic.h:263
NetworkTables StringArray topic.
Definition: StringArrayTopic.h:210
NetworkTables String topic.
Definition: StringTopic.h:265
NetworkTables subscriber.
Definition: Topic.h:290
NetworkTables Topic.
Definition: Topic.h:30
A data log.
Definition: DataLog.h:66
basic_string_view< char > string_view
Definition: core.h:520
dimensionless::scalar_t log(const ScalarUnit x) noexcept
Compute natural logarithm.
Definition: math.h:349
NT_Handle NT_ConnectionDataLogger
Definition: ntcore_c.h:31
NT_Handle NT_Listener
Definition: ntcore_c.h:35
#define NT_DEFAULT_PORT3
Default network tables port number (NT3)
Definition: ntcore_c.h:43
NT_Handle NT_Inst
Definition: ntcore_c.h:34
#define NT_DEFAULT_PORT4
Default network tables port number (NT4)
Definition: ntcore_c.h:46
NT_Handle NT_DataLogger
Definition: ntcore_c.h:32
@ NT_LOG_DEBUG4
Definition: ntcore_c.h:78
@ NT_LOG_WARNING
Definition: ntcore_c.h:72
@ NT_LOG_INFO
Definition: ntcore_c.h:73
@ NT_LOG_DEBUG2
Definition: ntcore_c.h:76
@ NT_LOG_DEBUG
Definition: ntcore_c.h:74
@ NT_LOG_CRITICAL
Definition: ntcore_c.h:70
@ NT_LOG_ERROR
Definition: ntcore_c.h:71
@ NT_LOG_DEBUG3
Definition: ntcore_c.h:77
@ NT_LOG_DEBUG1
Definition: ntcore_c.h:75
@ NT_NET_MODE_LOCAL
Definition: ntcore_c.h:88
@ NT_NET_MODE_CLIENT4
Definition: ntcore_c.h:86
@ NT_NET_MODE_CLIENT3
Definition: ntcore_c.h:85
@ NT_NET_MODE_SERVER
Definition: ntcore_c.h:84
@ NT_NET_MODE_NONE
Definition: ntcore_c.h:83
std::function< void(const Event &)> ListenerCallback
Definition: ntcore_cpp.h:860
NetworkTables (ntcore) namespace.
Definition: ntcore_cpp.h:35