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