WPILibC++ 2023.4.3
ntcore_cpp.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 <stdint.h>
8
9#include <cassert>
10#include <functional>
11#include <memory>
12#include <optional>
13#include <span>
14#include <string>
15#include <string_view>
16#include <utility>
17#include <variant>
18#include <vector>
19
21#include "ntcore_c.h"
22#include "ntcore_cpp_types.h"
23
24namespace wpi {
25template <typename T>
26class SmallVectorImpl;
27class json;
28} // namespace wpi
29
30namespace wpi::log {
31class DataLog;
32} // namespace wpi::log
33
34/** NetworkTables (ntcore) namespace */
35namespace nt {
36
37/**
38 * @defgroup ntcore_cpp_handle_api ntcore C++ API
39 *
40 * Handle-based interface for C++.
41 *
42 * @{
43 */
44
45/**
46 * Event notification flags.
47 *
48 * The flags are a bitmask and must be OR'ed together to indicate the
49 * combination of events desired to be received.
50 *
51 */
52struct EventFlags {
53 EventFlags() = delete;
54
55 static constexpr unsigned int kNone = NT_EVENT_NONE;
56 /**
57 * Initial listener addition.
58 * Set this flag to receive immediate notification of matches to the
59 * flag criteria.
60 */
61 static constexpr unsigned int kImmediate = NT_EVENT_IMMEDIATE;
62 /** Client connected (on server, any client connected). */
63 static constexpr unsigned int kConnected = NT_EVENT_CONNECTED;
64 /** Client disconnected (on server, any client disconnected). */
65 static constexpr unsigned int kDisconnected = NT_EVENT_DISCONNECTED;
66 /** Any connection event (connect or disconnect). */
67 static constexpr unsigned int kConnection = kConnected | kDisconnected;
68 /** New topic published. */
69 static constexpr unsigned int kPublish = NT_EVENT_PUBLISH;
70 /** Topic unpublished. */
71 static constexpr unsigned int kUnpublish = NT_EVENT_UNPUBLISH;
72 /** Topic properties changed. */
73 static constexpr unsigned int kProperties = NT_EVENT_PROPERTIES;
74 /** Any topic event (publish, unpublish, or properties changed). */
75 static constexpr unsigned int kTopic = kPublish | kUnpublish | kProperties;
76 /** Topic value updated (via network). */
77 static constexpr unsigned int kValueRemote = NT_EVENT_VALUE_REMOTE;
78 /** Topic value updated (local). */
79 static constexpr unsigned int kValueLocal = NT_EVENT_VALUE_LOCAL;
80 /** Topic value updated (network or local). */
81 static constexpr unsigned int kValueAll = kValueRemote | kValueLocal;
82 /** Log message. */
83 static constexpr unsigned int kLogMessage = NT_EVENT_LOGMESSAGE;
84 /** Time synchronized with server. */
85 static constexpr unsigned int kTimeSync = NT_EVENT_TIMESYNC;
86};
87
88/** NetworkTables Topic Information */
89struct TopicInfo {
90 /** Topic handle */
92
93 /** Topic name */
94 std::string name;
95
96 /** Topic type */
98
99 /** Topic type string */
100 std::string type_str;
101
102 /** Topic properties JSON string */
103 std::string properties;
104
105 /** Get topic properties as a JSON object. */
107
108 friend void swap(TopicInfo& first, TopicInfo& second) {
109 using std::swap;
110 swap(first.topic, second.topic);
111 swap(first.name, second.name);
112 swap(first.type, second.type);
113 swap(first.type_str, second.type_str);
114 swap(first.properties, second.properties);
115 }
116};
117
118/** NetworkTables Connection Information */
120 /**
121 * The remote identifier (as set on the remote node by
122 * NetworkTableInstance::StartClient4() or nt::StartClient4()).
123 */
124 std::string remote_id;
125
126 /** The IP address of the remote node. */
127 std::string remote_ip;
128
129 /** The port number of the remote node. */
130 unsigned int remote_port{0};
131
132 /**
133 * The last time any update was received from the remote node (same scale as
134 * returned by nt::Now()).
135 */
137
138 /**
139 * The protocol version being used for this connection. This in protocol
140 * layer format, so 0x0200 = 2.0, 0x0300 = 3.0).
141 */
142 unsigned int protocol_version{0};
143
144 friend void swap(ConnectionInfo& first, ConnectionInfo& second) {
145 using std::swap;
146 swap(first.remote_id, second.remote_id);
147 swap(first.remote_ip, second.remote_ip);
148 swap(first.remote_port, second.remote_port);
149 swap(first.last_update, second.last_update);
150 swap(first.protocol_version, second.protocol_version);
151 }
152};
153
154/** NetworkTables Value Event Data */
156 public:
157 ValueEventData() = default;
159 : topic{topic}, subentry{subentry}, value{std::move(value)} {}
160
161 /** Topic handle. */
163
164 /** Subscriber/entry handle. */
166
167 /** The new value. */
169};
170
171/** NetworkTables log message. */
173 public:
174 LogMessage() = default;
175 LogMessage(unsigned int level, std::string_view filename, unsigned int line,
178
179 /** Log level of the message. See NT_LogLevel. */
180 unsigned int level{0};
181
182 /** The filename of the source file that generated the message. */
183 std::string filename;
184
185 /** The line number in the source file that generated the message. */
186 unsigned int line{0};
187
188 /** The message. */
189 std::string message;
190};
191
192/** NetworkTables time sync event data. */
194 public:
195 TimeSyncEventData() = default;
198
199 /**
200 * Offset between local time and server time, in microseconds. Add this value
201 * to local time to get the estimated equivalent server time.
202 */
204
205 /** Measured round trip time divided by 2, in microseconds. */
207
208 /**
209 * If serverTimeOffset and RTT are valid. An event with this set to false is
210 * sent when the client disconnects.
211 */
212 bool valid;
213};
214
215/** NetworkTables event */
216class Event {
217 public:
218 Event() = default;
220 : listener{listener}, flags{flags}, data{std::move(info)} {}
222 : listener{listener}, flags{flags}, data{std::move(info)} {}
224 : listener{listener}, flags{flags}, data{std::move(data)} {}
226 : listener{listener}, flags{flags}, data{std::move(msg)} {}
228 NT_Handle subentry, Value value)
230 flags{flags},
231 data{ValueEventData{topic, subentry, std::move(value)}} {}
232 Event(NT_Listener listener, unsigned int flags, unsigned int level,
233 std::string_view filename, unsigned int line, std::string_view message)
235 flags{flags},
236 data{LogMessage{level, filename, line, message}} {}
237 Event(NT_Listener listener, unsigned int flags, int64_t serverTimeOffset,
238 int64_t rtt2, bool valid)
240 flags{flags},
241 data{TimeSyncEventData{serverTimeOffset, rtt2, valid}} {}
242
243 /** Listener that triggered this event. */
245
246 /**
247 * Event flags (NT_EventFlags). Also indicates the data included with the
248 * event:
249 * - NT_EVENT_CONNECTED or NT_EVENT_DISCONNECTED: GetConnectionInfo()
250 * - NT_EVENT_PUBLISH, NT_EVENT_UNPUBLISH, or NT_EVENT_PROPERTIES:
251 * GetTopicInfo()
252 * - NT_EVENT_VALUE, NT_EVENT_VALUE_LOCAL: GetValueData()
253 * - NT_EVENT_LOGMESSAGE: GetLogMessage()
254 * - NT_EVENT_TIMESYNC: GetTimeSyncEventData()
255 */
256 unsigned int flags{0};
257
258 /**
259 * Test event flags.
260 *
261 * @param kind event flag(s) to test
262 * @return True if flags matches kind
263 */
264 bool Is(unsigned int kind) const { return (flags & kind) != 0; }
265
266 /** Event data; content depends on flags. */
270
272 return std::get_if<ConnectionInfo>(&data);
273 }
275 return std::get_if<ConnectionInfo>(&data);
276 }
277
278 const TopicInfo* GetTopicInfo() const {
279 return std::get_if<TopicInfo>(&data);
280 }
281 TopicInfo* GetTopicInfo() { return std::get_if<TopicInfo>(&data); }
282
284 return std::get_if<ValueEventData>(&data);
285 }
287 return std::get_if<ValueEventData>(&data);
288 }
289
290 const LogMessage* GetLogMessage() const {
291 return std::get_if<LogMessage>(&data);
292 }
293 LogMessage* GetLogMessage() { return std::get_if<LogMessage>(&data); }
294
296 return std::get_if<TimeSyncEventData>(&data);
297 }
299 return std::get_if<TimeSyncEventData>(&data);
300 }
301};
302
303/** NetworkTables publish/subscribe options. */
305 /**
306 * Default value of periodic.
307 */
308 static constexpr double kDefaultPeriodic = 0.1;
309
310 /**
311 * Structure size. Must be set to sizeof(PubSubOptions).
312 */
313 unsigned int structSize = sizeof(PubSubOptions);
314
315 /**
316 * Polling storage size for a subscription. Specifies the maximum number of
317 * updates NetworkTables should store between calls to the subscriber's
318 * ReadQueue() function. If zero, defaults to 1 if sendAll is false, 20 if
319 * sendAll is true.
320 */
321 unsigned int pollStorage = 0;
322
323 /**
324 * How frequently changes will be sent over the network, in seconds.
325 * NetworkTables may send more frequently than this (e.g. use a combined
326 * minimum period for all values) or apply a restricted range to this value.
327 * The default is 100 ms.
328 */
330
331 /**
332 * For subscriptions, if non-zero, value updates for ReadQueue() are not
333 * queued for this publisher.
334 */
336
337 /**
338 * Send all value changes over the network.
339 */
340 bool sendAll = false;
341
342 /**
343 * For subscriptions, don't ask for value changes (only topic announcements).
344 */
345 bool topicsOnly = false;
346
347 /**
348 * Preserve duplicate value changes (rather than ignoring them).
349 */
350 bool keepDuplicates = false;
351
352 /**
353 * Perform prefix match on subscriber topic names. Is ignored/overridden by
354 * Subscribe() functions; only present in struct for the purposes of getting
355 * information about subscriptions.
356 */
357 bool prefixMatch = false;
358
359 /**
360 * For subscriptions, if remote value updates should not be queued for
361 * ReadQueue(). See also disableLocal.
362 */
363 bool disableRemote = false;
364
365 /**
366 * For subscriptions, if local value updates should not be queued for
367 * ReadQueue(). See also disableRemote.
368 */
369 bool disableLocal = false;
370
371 /**
372 * For entries, don't queue (for ReadQueue) value updates for the entry's
373 * internal publisher.
374 */
375 bool excludeSelf = false;
376};
377
378/**
379 * Default publish/subscribe options.
380 */
382
383/**
384 * @defgroup ntcore_instance_func Instance Functions
385 * @{
386 */
387
388/**
389 * Get default instance.
390 * This is the instance used by non-handle-taking functions.
391 *
392 * @return Instance handle
393 */
395
396/**
397 * Create an instance.
398 *
399 * @return Instance handle
400 */
402
403/**
404 * Reset the internals of an instance. Every handle previously associated
405 * with this instance will no longer be valid, except for the instance
406 * handle.
407 */
409
410/**
411 * Destroy an instance.
412 * The default instance cannot be destroyed.
413 *
414 * @param inst Instance handle
415 */
417
418/**
419 * Get instance handle from another handle.
420 *
421 * @param handle entry/instance/etc. handle
422 * @return Instance handle
423 */
425
426/** @} */
427
428/**
429 * @defgroup ntcore_table_func Table Functions
430 * @{
431 */
432
433/**
434 * Get Entry Handle.
435 *
436 * @param inst instance handle
437 * @param name entry name (UTF-8 string)
438 * @return entry handle
439 */
441
442/**
443 * Gets the name of the specified entry.
444 * Returns an empty string if the handle is invalid.
445 *
446 * @param entry entry handle
447 * @return Entry name
448 */
449std::string GetEntryName(NT_Entry entry);
450
451/**
452 * Gets the type for the specified entry, or unassigned if non existent.
453 *
454 * @param entry entry handle
455 * @return Entry type
456 */
458
459/**
460 * Gets the last time the entry was changed.
461 * Returns 0 if the handle is invalid.
462 *
463 * @param subentry subscriber or entry handle
464 * @return Entry last change time
465 */
467
468/**
469 * Get Entry Value.
470 *
471 * Returns copy of current entry value.
472 * Note that one of the type options is "unassigned".
473 *
474 * @param subentry subscriber or entry handle
475 * @return entry value
476 */
478
479/**
480 * Set Default Entry Value
481 *
482 * Returns copy of current entry value if it exists.
483 * Otherwise, sets passed in value, and returns set value.
484 * Note that one of the type options is "unassigned".
485 *
486 * @param entry entry handle
487 * @param value value to be set if name does not exist
488 * @return False on error (value not set), True on success
489 */
491
492/**
493 * Set Entry Value.
494 *
495 * Sets new entry value. If type of new value differs from the type of the
496 * currently stored entry, returns error and does not update value.
497 *
498 * @param entry entry handle
499 * @param value new entry value
500 * @return False on error (type mismatch), True on success
501 */
502bool SetEntryValue(NT_Entry entry, const Value& value);
503
504/**
505 * Set Entry Flags.
506 *
507 * @param entry entry handle
508 * @param flags flags value (bitmask of NT_EntryFlags)
509 */
510void SetEntryFlags(NT_Entry entry, unsigned int flags);
511
512/**
513 * Get Entry Flags.
514 *
515 * @param entry entry handle
516 * @return Flags value (bitmask of NT_EntryFlags)
517 */
518unsigned int GetEntryFlags(NT_Entry entry);
519
520/**
521 * Read Entry Queue.
522 *
523 * Returns new entry values since last call.
524 *
525 * @param subentry subscriber or entry handle
526 * @return entry value array
527 */
528std::vector<Value> ReadQueueValue(NT_Handle subentry);
529
530/** @} */
531
532/**
533 * @defgroup ntcore_topic_func Topic Functions
534 * @{
535 */
536
537/**
538 * Get Published Topics.
539 *
540 * Returns an array of topic handles. The results are optionally filtered by
541 * string prefix and type to only return a subset of all topics.
542 *
543 * @param inst instance handle
544 * @param prefix name required prefix; only topics whose name
545 * starts with this string are returned
546 * @param types bitmask of NT_Type values; 0 is treated specially
547 * as a "don't care"
548 * @return Array of topic handles.
549 */
550std::vector<NT_Topic> GetTopics(NT_Inst inst, std::string_view prefix,
551 unsigned int types);
552
553/**
554 * Get Published Topics.
555 *
556 * Returns an array of topic handles. The results are optionally filtered by
557 * string prefix and type to only return a subset of all topics.
558 *
559 * @param inst instance handle
560 * @param prefix name required prefix; only topics whose name
561 * starts with this string are returned
562 * @param types array of type strings
563 * @return Array of topic handles.
564 */
565std::vector<NT_Topic> GetTopics(NT_Inst inst, std::string_view prefix,
566 std::span<const std::string_view> types);
567
568/**
569 * Get Topic Information about multiple topics.
570 *
571 * Returns an array of topic information (handle, name, type, and properties).
572 * The results are optionally filtered by string prefix and type to only
573 * return a subset of all topics.
574 *
575 * @param inst instance handle
576 * @param prefix name required prefix; only topics whose name
577 * starts with this string are returned
578 * @param types bitmask of NT_Type values; 0 is treated specially
579 * as a "don't care"
580 * @return Array of topic information.
581 */
582std::vector<TopicInfo> GetTopicInfo(NT_Inst inst, std::string_view prefix,
583 unsigned int types);
584
585/**
586 * Get Topic Information about multiple topics.
587 *
588 * Returns an array of topic information (handle, name, type, and properties).
589 * The results are optionally filtered by string prefix and type to only
590 * return a subset of all topics.
591 *
592 * @param inst instance handle
593 * @param prefix name required prefix; only topics whose name
594 * starts with this string are returned
595 * @param types array of type strings
596 * @return Array of topic information.
597 */
598std::vector<TopicInfo> GetTopicInfo(NT_Inst inst, std::string_view prefix,
599 std::span<const std::string_view> types);
600
601/**
602 * Gets Topic Information.
603 *
604 * Returns information about a topic (name, type, and properties).
605 *
606 * @param topic handle
607 * @return Topic information.
608 */
610
611/**
612 * Gets Topic Handle.
613 *
614 * Returns topic handle.
615 *
616 * @param inst instance handle
617 * @param name topic name
618 * @return Topic handle.
619 */
621
622/**
623 * Gets the name of the specified topic.
624 * Returns an empty string if the handle is invalid.
625 *
626 * @param topic topic handle
627 * @return Topic name
628 */
629std::string GetTopicName(NT_Topic topic);
630
631/**
632 * Gets the type for the specified topic, or unassigned if non existent.
633 *
634 * @param topic topic handle
635 * @return Topic type
636 */
638
639/**
640 * Gets the type string for the specified topic, or empty string if non
641 * existent. This may have more information than the numeric type (especially
642 * for raw values).
643 *
644 * @param topic topic handle
645 * @return Topic type string
646 */
647std::string GetTopicTypeString(NT_Topic topic);
648
649/**
650 * Sets the persistent property of a topic. If true, the stored value is
651 * persistent through server restarts.
652 *
653 * @param topic topic handle
654 * @param value True for persistent, false for not persistent.
655 */
657
658/**
659 * Gets the persistent property of a topic. If true, the server retains the
660 * topic even when there are no publishers.
661 *
662 * @param topic topic handle
663 * @return persistent property value
664 */
666
667/**
668 * Sets the retained property of a topic.
669 *
670 * @param topic topic handle
671 * @param value new retained property value
672 */
674
675/**
676 * Gets the retained property of a topic.
677 *
678 * @param topic topic handle
679 * @return retained property value
680 */
682
683/**
684 * Determine if topic exists (e.g. has at least one publisher).
685 *
686 * @param handle Topic, entry, or subscriber handle.
687 * @return True if topic exists.
688 */
690
691/**
692 * Gets the current value of a property (as a JSON object).
693 *
694 * @param topic topic handle
695 * @param name property name
696 * @return JSON object; null object if the property does not exist.
697 */
699
700/**
701 * Sets a property value.
702 *
703 * @param topic topic handle
704 * @param name property name
705 * @param value property value
706 */
708 const wpi::json& value);
709
710/**
711 * Deletes a property. Has no effect if the property does not exist.
712 *
713 * @param topic topic handle
714 * @param name property name
715 */
717
718/**
719 * Gets all topic properties as a JSON object. Each key in the object
720 * is the property name, and the corresponding value is the property value.
721 *
722 * @param topic topic handle
723 * @return JSON object
724 */
726
727/**
728 * Updates multiple topic properties. Each key in the passed-in object is
729 * the name of the property to add/update, and the corresponding value is the
730 * property value to set for that property. Null values result in deletion
731 * of the corresponding property.
732 *
733 * @param topic topic handle
734 * @param update JSON object with keys to add/update/delete
735 * @return False if update is not a JSON object
736 */
737bool SetTopicProperties(NT_Topic topic, const wpi::json& update);
738
739/**
740 * Creates a new subscriber to value changes on a topic.
741 *
742 * @param topic topic handle
743 * @param type expected type
744 * @param typeStr expected type string
745 * @param options subscription options
746 * @return Subscriber handle
747 */
749 const PubSubOptions& options = kDefaultPubSubOptions);
750
751/**
752 * Stops subscriber.
753 *
754 * @param sub subscriber handle
755 */
757
758/**
759 * Creates a new publisher to a topic.
760 *
761 * @param topic topic handle
762 * @param type type
763 * @param typeStr type string
764 * @param options publish options
765 * @return Publisher handle
766 */
768 const PubSubOptions& options = kDefaultPubSubOptions);
769
770/**
771 * Creates a new publisher to a topic.
772 *
773 * @param topic topic handle
774 * @param type type
775 * @param typeStr type string
776 * @param properties initial properties
777 * @param options publish options
778 * @return Publisher handle
779 */
781 const wpi::json& properties,
782 const PubSubOptions& options = kDefaultPubSubOptions);
783
784/**
785 * Stops publisher.
786 *
787 * @param pubentry publisher/entry handle
788 */
789void Unpublish(NT_Handle pubentry);
790
791/**
792 * @brief Creates a new entry (subscriber and weak publisher) to a topic.
793 *
794 * @param topic topic handle
795 * @param type type
796 * @param typeStr type string
797 * @param options publish options
798 * @return Entry handle
799 */
801 const PubSubOptions& options = kDefaultPubSubOptions);
802
803/**
804 * Stops entry subscriber/publisher.
805 *
806 * @param entry entry handle
807 */
809
810/**
811 * Stops entry/subscriber/publisher.
812 *
813 * @param pubsubentry entry/subscriber/publisher handle
814 */
815void Release(NT_Handle pubsubentry);
816
817/**
818 * Gets the topic handle from an entry/subscriber/publisher handle.
819 *
820 * @param pubsubentry entry/subscriber/publisher handle
821 * @return Topic handle
822 */
824
825/** @} */
826
827/**
828 * @defgroup ntcore_advancedsub_func Advanced Subscriber Functions
829 * @{
830 */
831
832/**
833 * Subscribes to multiple topics based on one or more topic name prefixes. Can
834 * be used in combination with a Value Listener or ReadQueueValue() to get value
835 * changes across all matching topics.
836 *
837 * @param inst instance handle
838 * @param prefixes topic name prefixes
839 * @param options subscriber options
840 * @return subscriber handle
841 */
843 NT_Inst inst, std::span<const std::string_view> prefixes,
844 const PubSubOptions& options = kDefaultPubSubOptions);
845
846/**
847 * Unsubscribes a multi-subscriber.
848 *
849 * @param sub multi-subscriber handle
850 */
852
853/** @} */
854
855/**
856 * @defgroup ntcore_listener_func Listener Functions
857 * @{
858 */
859
860using ListenerCallback = std::function<void(const Event&)>;
861
862/**
863 * Creates a listener poller.
864 *
865 * A poller provides a single queue of poll events. Events linked to this
866 * poller (using AddPolledListener()) will be stored in the queue and
867 * must be collected by calling ReadListenerQueue().
868 * The returned handle must be destroyed with DestroyListenerPoller().
869 *
870 * @param inst instance handle
871 * @return poller handle
872 */
874
875/**
876 * Destroys a listener poller. This will abort any blocked polling
877 * call and prevent additional events from being generated for this poller.
878 *
879 * @param poller poller handle
880 */
882
883/**
884 * Read notifications.
885 *
886 * @param poller poller handle
887 * @return Array of events. Returns empty array if no events since last call.
888 */
889std::vector<Event> ReadListenerQueue(NT_ListenerPoller poller);
890
891/**
892 * Removes a listener.
893 *
894 * @param listener Listener handle to remove
895 */
897
898/**
899 * Wait for the listener queue to be empty. This is primarily useful
900 * for deterministic testing. This blocks until either the listener
901 * queue is empty (e.g. there are no more events that need to be passed along to
902 * callbacks or poll queues) or the timeout expires.
903 *
904 * @param handle handle
905 * @param timeout timeout, in seconds. Set to 0 for non-blocking behavior, or a
906 * negative value to block indefinitely
907 * @return False if timed out, otherwise true.
908 */
909bool WaitForListenerQueue(NT_Handle handle, double timeout);
910
911/**
912 * Create a listener for changes to topics with names that start with any of
913 * the given prefixes. This creates a corresponding internal subscriber with the
914 * lifetime of the listener.
915 *
916 * @param inst Instance handle
917 * @param prefixes Topic name string prefixes
918 * @param mask Bitmask of NT_EventFlags values (only topic and value events will
919 * be generated)
920 * @param callback Listener function
921 */
923 std::span<const std::string_view> prefixes,
924 unsigned int mask, ListenerCallback callback);
925
926/**
927 * Create a listener.
928 *
929 * Some combinations of handle and mask have no effect:
930 * - connection and log message events are only generated on instances
931 * - topic and value events are only generated on non-instances
932 *
933 * Adding value and topic events on a topic will create a corresponding internal
934 * subscriber with the lifetime of the listener.
935 *
936 * Adding a log message listener through this function will only result in
937 * events at NT_LOG_INFO or higher; for more customized settings, use
938 * AddLogger().
939 *
940 * @param handle Instance, topic, subscriber, multi-subscriber, or entry handle
941 * @param mask Bitmask of NT_EventFlags values
942 * @param callback Listener function
943 */
944NT_Listener AddListener(NT_Handle handle, unsigned int mask,
945 ListenerCallback callback);
946
947/**
948 * Creates a polled listener. This creates a corresponding internal subscriber
949 * with the lifetime of the listener.
950 * The caller is responsible for calling ReadListenerQueue() to poll.
951 *
952 * @param poller poller handle
953 * @param prefixes array of UTF-8 string prefixes
954 * @param mask Bitmask of NT_EventFlags values (only topic and value events will
955 * be generated)
956 * @return Listener handle
957 */
959 std::span<const std::string_view> prefixes,
960 unsigned int mask);
961
962/**
963 * Creates a polled listener.
964 * The caller is responsible for calling ReadListenerQueue() to poll.
965 *
966 * Some combinations of handle and mask have no effect:
967 * - connection and log message events are only generated on instances
968 * - topic and value events are only generated on non-instances
969 *
970 * Adding value and topic events on a topic will create a corresponding internal
971 * subscriber with the lifetime of the listener.
972 *
973 * Adding a log message listener through this function will only result in
974 * events at NT_LOG_INFO or higher; for more customized settings, use
975 * AddPolledLogger().
976 *
977 * @param poller poller handle
978 * @param handle instance, topic, subscriber, multi-subscriber, or entry handle
979 * @param mask NT_EventFlags bitmask
980 * @return Listener handle
981 */
983 unsigned int mask);
984
985/** @} */
986
987/**
988 * @defgroup ntcore_network_func Client/Server Functions
989 * @{
990 */
991
992/**
993 * Get the current network mode.
994 *
995 * @param inst instance handle
996 * @return Bitmask of NT_NetworkMode.
997 */
998unsigned int GetNetworkMode(NT_Inst inst);
999
1000/**
1001 * Starts local-only operation. Prevents calls to StartServer or StartClient
1002 * from taking effect. Has no effect if StartServer or StartClient
1003 * has already been called.
1004 */
1006
1007/**
1008 * Stops local-only operation. StartServer or StartClient can be called after
1009 * this call to start a server or client.
1010 */
1012
1013/**
1014 * Starts a server using the specified filename, listening address, and port.
1015 *
1016 * @param inst instance handle
1017 * @param persist_filename the name of the persist file to use (UTF-8 string,
1018 * null terminated)
1019 * @param listen_address the address to listen on, or null to listen on any
1020 * address. (UTF-8 string, null terminated)
1021 * @param port3 port to communicate over (NT3)
1022 * @param port4 port to communicate over (NT4)
1023 */
1024void StartServer(NT_Inst inst, std::string_view persist_filename,
1025 const char* listen_address, unsigned int port3,
1026 unsigned int port4);
1027
1028/**
1029 * Stops the server if it is running.
1030 *
1031 * @param inst instance handle
1032 */
1034
1035/**
1036 * Starts a NT3 client. Use SetServer or SetServerTeam to set the server name
1037 * and port.
1038 *
1039 * @param inst instance handle
1040 * @param identity network identity to advertise (cannot be empty string)
1041 */
1043
1044/**
1045 * Starts a NT4 client. Use SetServer or SetServerTeam to set the server name
1046 * and port.
1047 *
1048 * @param inst instance handle
1049 * @param identity network identity to advertise (cannot be empty string)
1050 */
1052
1053/**
1054 * Stops the client if it is running.
1055 *
1056 * @param inst instance handle
1057 */
1059
1060/**
1061 * Sets server address and port for client (without restarting client).
1062 *
1063 * @param inst instance handle
1064 * @param server_name server name (UTF-8 string, null terminated)
1065 * @param port port to communicate over
1066 */
1067void SetServer(NT_Inst inst, const char* server_name, unsigned int port);
1068
1069/**
1070 * Sets server addresses for client (without restarting client).
1071 * The client will attempt to connect to each server in round robin fashion.
1072 *
1073 * @param inst instance handle
1074 * @param servers array of server name and port pairs
1075 */
1077 NT_Inst inst,
1078 std::span<const std::pair<std::string_view, unsigned int>> servers);
1079
1080/**
1081 * Sets server addresses and port for client (without restarting client).
1082 * Connects using commonly known robot addresses for the specified team.
1083 *
1084 * @param inst instance handle
1085 * @param team team number
1086 * @param port port to communicate over
1087 */
1088void SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port);
1089
1090/**
1091 * Disconnects the client if it's running and connected. This will automatically
1092 * start reconnection attempts to the current server list.
1093 *
1094 * @param inst instance handle
1095 */
1097
1098/**
1099 * Starts requesting server address from Driver Station.
1100 * This connects to the Driver Station running on localhost to obtain the
1101 * server IP address.
1102 *
1103 * @param inst instance handle
1104 * @param port server port to use in combination with IP from DS
1105 */
1106void StartDSClient(NT_Inst inst, unsigned int port);
1107
1108/**
1109 * Stops requesting server address from Driver Station.
1110 *
1111 * @param inst instance handle
1112 */
1114
1115/**
1116 * Flush local updates.
1117 *
1118 * Forces an immediate flush of all local changes to the client/server.
1119 * This does not flush to the network.
1120 *
1121 * Normally this is done on a regularly scheduled interval.
1122 *
1123 * @param inst instance handle
1124 */
1126
1127/**
1128 * Flush to network.
1129 *
1130 * Forces an immediate flush of all local entry changes to network.
1131 * Normally this is done on a regularly scheduled interval (set
1132 * by update rates on individual publishers).
1133 *
1134 * Note: flushes are rate limited to avoid excessive network traffic. If
1135 * the time between calls is too short, the flush will occur after the minimum
1136 * time elapses (rather than immediately).
1137 *
1138 * @param inst instance handle
1139 */
1140void Flush(NT_Inst inst);
1141
1142/**
1143 * Get information on the currently established network connections.
1144 * If operating as a client, this will return either zero or one values.
1145 *
1146 * @param inst instance handle
1147 * @return array of connection information
1148 */
1149std::vector<ConnectionInfo> GetConnections(NT_Inst inst);
1150
1151/**
1152 * Return whether or not the instance is connected to another node.
1153 *
1154 * @param inst instance handle
1155 * @return True if connected.
1156 */
1158
1159/**
1160 * Get the time offset between server time and local time. Add this value to
1161 * local time to get the estimated equivalent server time. In server mode, this
1162 * always returns 0. In client mode, this returns the time offset only if the
1163 * client and server are connected and have exchanged synchronization messages.
1164 * Note the time offset may change over time as it is periodically updated; to
1165 * receive updates as events, add a listener to the "time sync" event.
1166 *
1167 * @param inst instance handle
1168 * @return Time offset in microseconds (optional)
1169 */
1170std::optional<int64_t> GetServerTimeOffset(NT_Inst inst);
1171
1172/** @} */
1173
1174/**
1175 * @defgroup ntcore_utility_func Utility Functions
1176 * @{
1177 */
1178
1179/**
1180 * Returns monotonic current time in 1 us increments.
1181 * This is the same time base used for value and connection timestamps.
1182 * This function by default simply wraps wpi::Now(), but if SetNow() is
1183 * called, this function instead returns the value passed to SetNow();
1184 * this can be used to reduce overhead.
1185 *
1186 * @return Timestamp
1187 */
1189
1190/**
1191 * Sets the current timestamp used for timestamping values that do not
1192 * provide a timestamp (e.g. a value of 0 is passed). For consistency,
1193 * it also results in Now() returning the set value. This should generally
1194 * be used only if the overhead of calling wpi::Now() is a concern.
1195 * If used, it should be called periodically with the value of wpi::Now().
1196 *
1197 * @param timestamp timestamp (1 us increments)
1198 */
1199void SetNow(int64_t timestamp);
1200
1201/**
1202 * Turns a type string into a type enum value.
1203 *
1204 * @param typeString type string
1205 * @return Type value
1206 */
1208
1209/**
1210 * Turns a type enum value into a type string.
1211 *
1212 * @param type type enum
1213 * @return Type string
1214 */
1216
1217/** @} */
1218
1219/**
1220 * @defgroup ntcore_data_logger_func Data Logger Functions
1221 * @{
1222 */
1223
1224/**
1225 * Starts logging entry changes to a DataLog.
1226 *
1227 * @param inst instance handle
1228 * @param log data log object; lifetime must extend until StopEntryDataLog is
1229 * called or the instance is destroyed
1230 * @param prefix only store entries with names that start with this prefix;
1231 * the prefix is not included in the data log entry name
1232 * @param logPrefix prefix to add to data log entry names
1233 * @return Data logger handle
1234 */
1236 std::string_view prefix,
1237 std::string_view logPrefix);
1238
1239/**
1240 * Stops logging entry changes to a DataLog.
1241 *
1242 * @param logger data logger handle
1243 */
1245
1246/**
1247 * Starts logging connection changes to a DataLog.
1248 *
1249 * @param inst instance handle
1250 * @param log data log object; lifetime must extend until StopConnectionDataLog
1251 * is called or the instance is destroyed
1252 * @param name data log entry name
1253 * @return Data logger handle
1254 */
1257 std::string_view name);
1258
1259/**
1260 * Stops logging connection changes to a DataLog.
1261 *
1262 * @param logger data logger handle
1263 */
1265
1266/** @} */
1267
1268/**
1269 * @defgroup ntcore_logger_func Logger Functions
1270 * @{
1271 */
1272
1273/**
1274 * Add logger callback function. By default, log messages are sent to stderr;
1275 * this function sends log messages to the provided callback function instead.
1276 * The callback function will only be called for log messages with level
1277 * greater than or equal to min_level and less than or equal to max_level;
1278 * messages outside this range will be silently ignored.
1279 *
1280 * @param inst instance handle
1281 * @param min_level minimum log level
1282 * @param max_level maximum log level
1283 * @param func listener callback function
1284 * @return Listener handle
1285 */
1286NT_Listener AddLogger(NT_Inst inst, unsigned int min_level,
1287 unsigned int max_level, ListenerCallback func);
1288
1289/**
1290 * Set the log level for a log poller. Events will only be generated for
1291 * log messages with level greater than or equal to min_level and less than or
1292 * equal to max_level; messages outside this range will be silently ignored.
1293 *
1294 * @param poller poller handle
1295 * @param min_level minimum log level
1296 * @param max_level maximum log level
1297 * @return Logger handle
1298 */
1299NT_Listener AddPolledLogger(NT_ListenerPoller poller, unsigned int min_level,
1300 unsigned int max_level);
1301
1302/** @} */
1303/** @} */
1304
1305/**
1306 * NetworkTables meta-topic decoding functions.
1307 */
1308namespace meta {
1309
1310/**
1311 * @defgroup ntcore_cpp_meta_api ntcore C++ meta-topic API
1312 *
1313 * Meta-topic decoders for C++.
1314 *
1315 * @{
1316 */
1317
1318/**
1319 * Subscriber options. Different from PubSubOptions in this reflects only
1320 * options that are sent over the network.
1321 */
1323 double periodic = 0.1;
1324 bool topicsOnly = false;
1325 bool sendAll = false;
1326 bool prefixMatch = false;
1327 // std::string otherStr;
1328};
1329
1330/**
1331 * Topic publisher (as published via `$pub$<topic>`).
1332 */
1334 std::string client;
1336};
1337
1338/**
1339 * Topic subscriber (as published via `$sub$<topic>`).
1340 */
1342 std::string client;
1345};
1346
1347/**
1348 * Client publisher (as published via `$clientpub$<client>` or `$serverpub`).
1349 */
1352 std::string topic;
1353};
1354
1355/**
1356 * Client subscriber (as published via `$clientsub$<client>` or `$serversub`).
1357 */
1360 std::vector<std::string> topics;
1362};
1363
1364/**
1365 * Client (as published via `$clients`).
1366 */
1367struct Client {
1368 std::string id;
1369 std::string conn;
1371};
1372
1373/**
1374 * Decodes `$pub$<topic>` meta-topic data.
1375 *
1376 * @param data data contents
1377 * @return Vector of TopicPublishers, or empty optional on decoding error.
1378 */
1379std::optional<std::vector<TopicPublisher>> DecodeTopicPublishers(
1380 std::span<const uint8_t> data);
1381
1382/**
1383 * Decodes `$sub$<topic>` meta-topic data.
1384 *
1385 * @param data data contents
1386 * @return Vector of TopicSubscribers, or empty optional on decoding error.
1387 */
1388std::optional<std::vector<TopicSubscriber>> DecodeTopicSubscribers(
1389 std::span<const uint8_t> data);
1390
1391/**
1392 * Decodes `$clientpub$<topic>` meta-topic data.
1393 *
1394 * @param data data contents
1395 * @return Vector of ClientPublishers, or empty optional on decoding error.
1396 */
1397std::optional<std::vector<ClientPublisher>> DecodeClientPublishers(
1398 std::span<const uint8_t> data);
1399
1400/**
1401 * Decodes `$clientsub$<topic>` meta-topic data.
1402 *
1403 * @param data data contents
1404 * @return Vector of ClientSubscribers, or empty optional on decoding error.
1405 */
1406std::optional<std::vector<ClientSubscriber>> DecodeClientSubscribers(
1407 std::span<const uint8_t> data);
1408
1409/**
1410 * Decodes `$clients` meta-topic data.
1411 *
1412 * @param data data contents
1413 * @return Vector of Clients, or empty optional on decoding error.
1414 */
1415std::optional<std::vector<Client>> DecodeClients(std::span<const uint8_t> data);
1416
1417/** @} */
1418
1419} // namespace meta
1420} // namespace nt
NetworkTables event.
Definition: ntcore_cpp.h:216
Event(NT_Listener listener, unsigned int flags, ValueEventData data)
Definition: ntcore_cpp.h:223
Event(NT_Listener listener, unsigned int flags, ConnectionInfo info)
Definition: ntcore_cpp.h:219
const LogMessage * GetLogMessage() const
Definition: ntcore_cpp.h:290
const TimeSyncEventData * GetTimeSyncEventData() const
Definition: ntcore_cpp.h:295
Event(NT_Listener listener, unsigned int flags, int64_t serverTimeOffset, int64_t rtt2, bool valid)
Definition: ntcore_cpp.h:237
TopicInfo * GetTopicInfo()
Definition: ntcore_cpp.h:281
ValueEventData * GetValueEventData()
Definition: ntcore_cpp.h:286
const ValueEventData * GetValueEventData() const
Definition: ntcore_cpp.h:283
LogMessage * GetLogMessage()
Definition: ntcore_cpp.h:293
Event(NT_Listener listener, unsigned int flags, unsigned int level, std::string_view filename, unsigned int line, std::string_view message)
Definition: ntcore_cpp.h:232
std::variant< ConnectionInfo, TopicInfo, ValueEventData, LogMessage, TimeSyncEventData > data
Event data; content depends on flags.
Definition: ntcore_cpp.h:269
bool Is(unsigned int kind) const
Test event flags.
Definition: ntcore_cpp.h:264
Event(NT_Listener listener, unsigned int flags, NT_Topic topic, NT_Handle subentry, Value value)
Definition: ntcore_cpp.h:227
unsigned int flags
Event flags (NT_EventFlags).
Definition: ntcore_cpp.h:256
const ConnectionInfo * GetConnectionInfo() const
Definition: ntcore_cpp.h:271
ConnectionInfo * GetConnectionInfo()
Definition: ntcore_cpp.h:274
Event()=default
Event(NT_Listener listener, unsigned int flags, TopicInfo info)
Definition: ntcore_cpp.h:221
NT_Listener listener
Listener that triggered this event.
Definition: ntcore_cpp.h:244
TimeSyncEventData * GetTimeSyncEventData()
Definition: ntcore_cpp.h:298
Event(NT_Listener listener, unsigned int flags, LogMessage msg)
Definition: ntcore_cpp.h:225
const TopicInfo * GetTopicInfo() const
Definition: ntcore_cpp.h:278
NetworkTables log message.
Definition: ntcore_cpp.h:172
unsigned int line
The line number in the source file that generated the message.
Definition: ntcore_cpp.h:186
LogMessage()=default
LogMessage(unsigned int level, std::string_view filename, unsigned int line, std::string_view message)
Definition: ntcore_cpp.h:175
unsigned int level
Log level of the message.
Definition: ntcore_cpp.h:180
std::string message
The message.
Definition: ntcore_cpp.h:189
std::string filename
The filename of the source file that generated the message.
Definition: ntcore_cpp.h:183
NetworkTables time sync event data.
Definition: ntcore_cpp.h:193
int64_t rtt2
Measured round trip time divided by 2, in microseconds.
Definition: ntcore_cpp.h:206
TimeSyncEventData()=default
int64_t serverTimeOffset
Offset between local time and server time, in microseconds.
Definition: ntcore_cpp.h:203
bool valid
If serverTimeOffset and RTT are valid.
Definition: ntcore_cpp.h:212
TimeSyncEventData(int64_t serverTimeOffset, int64_t rtt2, bool valid)
Definition: ntcore_cpp.h:196
NetworkTables Value Event Data.
Definition: ntcore_cpp.h:155
NT_Handle subentry
Subscriber/entry handle.
Definition: ntcore_cpp.h:165
ValueEventData()=default
ValueEventData(NT_Topic topic, NT_Handle subentry, Value value)
Definition: ntcore_cpp.h:158
NT_Topic topic
Topic handle.
Definition: ntcore_cpp.h:162
Value value
The new value.
Definition: ntcore_cpp.h:168
A network table entry value.
Definition: NetworkTableValue.h:27
Definition: core.h:1240
a class to store JSON values
Definition: json.h:2655
A data log.
Definition: DataLog.h:66
basic_string_view< char > string_view
Definition: core.h:520
type
Definition: core.h:575
dimensionless::scalar_t log(const ScalarUnit x) noexcept
Compute natural logarithm.
Definition: math.h:349
NT_MultiSubscriber SubscribeMultiple(NT_Inst inst, std::span< const std::string_view > prefixes, const PubSubOptions &options=kDefaultPubSubOptions)
Subscribes to multiple topics based on one or more topic name prefixes.
void UnsubscribeMultiple(NT_MultiSubscriber sub)
Unsubscribes a multi-subscriber.
NT_Handle NT_Topic
Definition: ntcore_c.h:38
NT_Handle NT_ConnectionDataLogger
Definition: ntcore_c.h:31
NT_Handle NT_Listener
Definition: ntcore_c.h:35
NT_Handle NT_Subscriber
Definition: ntcore_c.h:39
unsigned int NT_Handle
Definition: ntcore_c.h:30
NT_Type
NetworkTables data types.
Definition: ntcore_c.h:49
NT_Handle NT_Inst
Definition: ntcore_c.h:34
NT_Handle NT_Publisher
Definition: ntcore_c.h:40
NT_Handle NT_ListenerPoller
Definition: ntcore_c.h:36
NT_Handle NT_MultiSubscriber
Definition: ntcore_c.h:37
NT_Handle NT_Entry
Definition: ntcore_c.h:33
NT_Handle NT_DataLogger
Definition: ntcore_c.h:32
@ NT_UNASSIGNED
Definition: ntcore_c.h:50
@ NT_EVENT_LOGMESSAGE
Log message.
Definition: ntcore_c.h:117
@ NT_EVENT_NONE
Definition: ntcore_c.h:93
@ NT_EVENT_UNPUBLISH
Topic unpublished.
Definition: ntcore_c.h:105
@ NT_EVENT_PROPERTIES
Topic properties changed.
Definition: ntcore_c.h:107
@ NT_EVENT_CONNECTED
Client connected (on server, any client connected).
Definition: ntcore_c.h:97
@ NT_EVENT_TIMESYNC
Time synchronized with server.
Definition: ntcore_c.h:119
@ NT_EVENT_VALUE_REMOTE
Topic value updated (via network).
Definition: ntcore_c.h:111
@ NT_EVENT_PUBLISH
New topic published.
Definition: ntcore_c.h:103
@ NT_EVENT_DISCONNECTED
Client disconnected (on server, any client disconnected).
Definition: ntcore_c.h:99
@ NT_EVENT_IMMEDIATE
Initial listener addition.
Definition: ntcore_c.h:95
@ NT_EVENT_VALUE_LOCAL
Topic value updated (local).
Definition: ntcore_c.h:113
constexpr PubSubOptions kDefaultPubSubOptions
Default publish/subscribe options.
Definition: ntcore_cpp.h:381
std::optional< std::vector< ClientSubscriber > > DecodeClientSubscribers(std::span< const uint8_t > data)
Decodes $clientsub$<topic> meta-topic data.
std::optional< std::vector< TopicSubscriber > > DecodeTopicSubscribers(std::span< const uint8_t > data)
Decodes $sub$<topic> meta-topic data.
std::optional< std::vector< ClientPublisher > > DecodeClientPublishers(std::span< const uint8_t > data)
Decodes $clientpub$<topic> meta-topic data.
std::optional< std::vector< TopicPublisher > > DecodeTopicPublishers(std::span< const uint8_t > data)
Decodes $pub$<topic> meta-topic data.
std::optional< std::vector< Client > > DecodeClients(std::span< const uint8_t > data)
Decodes $clients meta-topic data.
NT_ConnectionDataLogger StartConnectionDataLog(NT_Inst inst, wpi::log::DataLog &log, std::string_view name)
Starts logging connection changes to a DataLog.
void StopConnectionDataLog(NT_ConnectionDataLogger logger)
Stops logging connection changes to a DataLog.
NT_DataLogger StartEntryDataLog(NT_Inst inst, wpi::log::DataLog &log, std::string_view prefix, std::string_view logPrefix)
Starts logging entry changes to a DataLog.
void StopEntryDataLog(NT_DataLogger logger)
Stops logging entry changes to a DataLog.
NT_Inst GetInstanceFromHandle(NT_Handle handle)
Get instance handle from another handle.
void ResetInstance(NT_Inst inst)
Reset the internals of an instance.
NT_Inst CreateInstance()
Create an instance.
NT_Inst GetDefaultInstance()
Get default instance.
void DestroyInstance(NT_Inst inst)
Destroy an instance.
std::function< void(const Event &)> ListenerCallback
Definition: ntcore_cpp.h:860
NT_Listener AddPolledListener(NT_ListenerPoller poller, std::span< const std::string_view > prefixes, unsigned int mask)
Creates a polled listener.
NT_ListenerPoller CreateListenerPoller(NT_Inst inst)
Creates a listener poller.
bool WaitForListenerQueue(NT_Handle handle, double timeout)
Wait for the listener queue to be empty.
NT_Listener AddListener(NT_Inst inst, std::span< const std::string_view > prefixes, unsigned int mask, ListenerCallback callback)
Create a listener for changes to topics with names that start with any of the given prefixes.
void DestroyListenerPoller(NT_ListenerPoller poller)
Destroys a listener poller.
void RemoveListener(NT_Listener listener)
Removes a listener.
std::vector< Event > ReadListenerQueue(NT_ListenerPoller poller)
Read notifications.
NT_Listener AddPolledLogger(NT_ListenerPoller poller, unsigned int min_level, unsigned int max_level)
Set the log level for a log poller.
NT_Listener AddLogger(NT_Inst inst, unsigned int min_level, unsigned int max_level, ListenerCallback func)
Add logger callback function.
void StartClient4(NT_Inst inst, std::string_view identity)
Starts a NT4 client.
void Disconnect(NT_Inst inst)
Disconnects the client if it's running and connected.
std::optional< int64_t > GetServerTimeOffset(NT_Inst inst)
Get the time offset between server time and local time.
unsigned int GetNetworkMode(NT_Inst inst)
Get the current network mode.
void StopLocal(NT_Inst inst)
Stops local-only operation.
void StopDSClient(NT_Inst inst)
Stops requesting server address from Driver Station.
bool IsConnected(NT_Inst inst)
Return whether or not the instance is connected to another node.
void StopServer(NT_Inst inst)
Stops the server if it is running.
void StartLocal(NT_Inst inst)
Starts local-only operation.
void Flush(NT_Inst inst)
Flush to network.
void SetServer(NT_Inst inst, const char *server_name, unsigned int port)
Sets server address and port for client (without restarting client).
void StartClient3(NT_Inst inst, std::string_view identity)
Starts a NT3 client.
void StartDSClient(NT_Inst inst, unsigned int port)
Starts requesting server address from Driver Station.
void StopClient(NT_Inst inst)
Stops the client if it is running.
void SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port)
Sets server addresses and port for client (without restarting client).
void StartServer(NT_Inst inst, std::string_view persist_filename, const char *listen_address, unsigned int port3, unsigned int port4)
Starts a server using the specified filename, listening address, and port.
std::vector< ConnectionInfo > GetConnections(NT_Inst inst)
Get information on the currently established network connections.
void FlushLocal(NT_Inst inst)
Flush local updates.
NT_Type GetEntryType(NT_Entry entry)
Gets the type for the specified entry, or unassigned if non existent.
Value GetEntryValue(NT_Handle subentry)
Get Entry Value.
void SetEntryFlags(NT_Entry entry, unsigned int flags)
Set Entry Flags.
NT_Entry GetEntry(NT_Inst inst, std::string_view name)
Get Entry Handle.
int64_t GetEntryLastChange(NT_Handle subentry)
Gets the last time the entry was changed.
unsigned int GetEntryFlags(NT_Entry entry)
Get Entry Flags.
std::vector< Value > ReadQueueValue(NT_Handle subentry)
Read Entry Queue.
std::string GetEntryName(NT_Entry entry)
Gets the name of the specified entry.
bool SetEntryValue(NT_Entry entry, const Value &value)
Set Entry Value.
bool SetDefaultEntryValue(NT_Entry entry, const Value &value)
Set Default Entry Value.
NT_Topic GetTopicFromHandle(NT_Handle pubsubentry)
Gets the topic handle from an entry/subscriber/publisher handle.
void Unsubscribe(NT_Subscriber sub)
Stops subscriber.
void Release(NT_Handle pubsubentry)
Stops entry/subscriber/publisher.
bool GetTopicRetained(NT_Topic topic)
Gets the retained property of a topic.
bool GetTopicExists(NT_Handle handle)
Determine if topic exists (e.g.
wpi::json GetTopicProperties(NT_Topic topic)
Gets all topic properties as a JSON object.
NT_Type GetTopicType(NT_Topic topic)
Gets the type for the specified topic, or unassigned if non existent.
std::string GetTopicTypeString(NT_Topic topic)
Gets the type string for the specified topic, or empty string if non existent.
std::string GetTopicName(NT_Topic topic)
Gets the name of the specified topic.
NT_Topic GetTopic(NT_Inst inst, std::string_view name)
Gets Topic Handle.
void SetTopicProperty(NT_Topic topic, std::string_view name, const wpi::json &value)
Sets a property value.
NT_Publisher PublishEx(NT_Topic topic, NT_Type type, std::string_view typeStr, const wpi::json &properties, const PubSubOptions &options=kDefaultPubSubOptions)
Creates a new publisher to a topic.
void SetTopicRetained(NT_Topic topic, bool value)
Sets the retained property of a topic.
bool SetTopicProperties(NT_Topic topic, const wpi::json &update)
Updates multiple topic properties.
NT_Publisher Publish(NT_Topic topic, NT_Type type, std::string_view typeStr, const PubSubOptions &options=kDefaultPubSubOptions)
Creates a new publisher to a topic.
std::vector< NT_Topic > GetTopics(NT_Inst inst, std::string_view prefix, unsigned int types)
Get Published Topics.
std::vector< TopicInfo > GetTopicInfo(NT_Inst inst, std::string_view prefix, unsigned int types)
Get Topic Information about multiple topics.
void SetTopicPersistent(NT_Topic topic, bool value)
Sets the persistent property of a topic.
wpi::json GetTopicProperty(NT_Topic topic, std::string_view name)
Gets the current value of a property (as a JSON object).
void ReleaseEntry(NT_Entry entry)
Stops entry subscriber/publisher.
void Unpublish(NT_Handle pubentry)
Stops publisher.
NT_Subscriber Subscribe(NT_Topic topic, NT_Type type, std::string_view typeStr, const PubSubOptions &options=kDefaultPubSubOptions)
Creates a new subscriber to value changes on a topic.
void DeleteTopicProperty(NT_Topic topic, std::string_view name)
Deletes a property.
bool GetTopicPersistent(NT_Topic topic)
Gets the persistent property of a topic.
NT_Type GetTypeFromString(std::string_view typeString)
Turns a type string into a type enum value.
int64_t Now()
Returns monotonic current time in 1 us increments.
void SetNow(int64_t timestamp)
Sets the current timestamp used for timestamping values that do not provide a timestamp (e....
std::string_view GetStringFromType(NT_Type type)
Turns a type enum value into a type string.
EIGEN_CONSTEXPR Index first(const T &x) EIGEN_NOEXCEPT
Definition: IndexedViewHelper.h:81
::uint64_t uint64_t
Definition: Meta.h:58
::uint16_t uint16_t
Definition: Meta.h:54
::int64_t int64_t
Definition: Meta.h:59
NetworkTables (ntcore) namespace.
Definition: ntcore_cpp.h:35
Definition: StdDeque.h:50
void swap(wpi::SmallVectorImpl< T > &LHS, wpi::SmallVectorImpl< T > &RHS)
Implement std::swap in terms of SmallVector swap.
Definition: SmallVector.h:1299
Definition: ntcore_cpp.h:30
/file This file defines the SmallVector class.
Definition: AprilTagFieldLayout.h:18
flags
Definition: http_parser.h:206
Definition: format.h:1544
NetworkTables Connection Information.
Definition: ntcore_cpp.h:119
unsigned int protocol_version
The protocol version being used for this connection.
Definition: ntcore_cpp.h:142
unsigned int remote_port
The port number of the remote node.
Definition: ntcore_cpp.h:130
friend void swap(ConnectionInfo &first, ConnectionInfo &second)
Definition: ntcore_cpp.h:144
int64_t last_update
The last time any update was received from the remote node (same scale as returned by nt::Now()).
Definition: ntcore_cpp.h:136
std::string remote_id
The remote identifier (as set on the remote node by NetworkTableInstance::StartClient4() or nt::Start...
Definition: ntcore_cpp.h:124
std::string remote_ip
The IP address of the remote node.
Definition: ntcore_cpp.h:127
Event notification flags.
Definition: ntcore_cpp.h:52
static constexpr unsigned int kValueRemote
Topic value updated (via network).
Definition: ntcore_cpp.h:77
static constexpr unsigned int kValueAll
Topic value updated (network or local).
Definition: ntcore_cpp.h:81
static constexpr unsigned int kTopic
Any topic event (publish, unpublish, or properties changed).
Definition: ntcore_cpp.h:75
static constexpr unsigned int kNone
Definition: ntcore_cpp.h:55
static constexpr unsigned int kLogMessage
Log message.
Definition: ntcore_cpp.h:83
static constexpr unsigned int kUnpublish
Topic unpublished.
Definition: ntcore_cpp.h:71
static constexpr unsigned int kImmediate
Initial listener addition.
Definition: ntcore_cpp.h:61
static constexpr unsigned int kConnection
Any connection event (connect or disconnect).
Definition: ntcore_cpp.h:67
static constexpr unsigned int kTimeSync
Time synchronized with server.
Definition: ntcore_cpp.h:85
static constexpr unsigned int kPublish
New topic published.
Definition: ntcore_cpp.h:69
static constexpr unsigned int kProperties
Topic properties changed.
Definition: ntcore_cpp.h:73
static constexpr unsigned int kValueLocal
Topic value updated (local).
Definition: ntcore_cpp.h:79
static constexpr unsigned int kConnected
Client connected (on server, any client connected).
Definition: ntcore_cpp.h:63
EventFlags()=delete
static constexpr unsigned int kDisconnected
Client disconnected (on server, any client disconnected).
Definition: ntcore_cpp.h:65
NetworkTables publish/subscribe options.
Definition: ntcore_cpp.h:304
bool topicsOnly
For subscriptions, don't ask for value changes (only topic announcements).
Definition: ntcore_cpp.h:345
NT_Publisher excludePublisher
For subscriptions, if non-zero, value updates for ReadQueue() are not queued for this publisher.
Definition: ntcore_cpp.h:335
bool excludeSelf
For entries, don't queue (for ReadQueue) value updates for the entry's internal publisher.
Definition: ntcore_cpp.h:375
bool sendAll
Send all value changes over the network.
Definition: ntcore_cpp.h:340
static constexpr double kDefaultPeriodic
Default value of periodic.
Definition: ntcore_cpp.h:308
bool keepDuplicates
Preserve duplicate value changes (rather than ignoring them).
Definition: ntcore_cpp.h:350
bool disableLocal
For subscriptions, if local value updates should not be queued for ReadQueue().
Definition: ntcore_cpp.h:369
bool disableRemote
For subscriptions, if remote value updates should not be queued for ReadQueue().
Definition: ntcore_cpp.h:363
bool prefixMatch
Perform prefix match on subscriber topic names.
Definition: ntcore_cpp.h:357
unsigned int structSize
Structure size.
Definition: ntcore_cpp.h:313
double periodic
How frequently changes will be sent over the network, in seconds.
Definition: ntcore_cpp.h:329
unsigned int pollStorage
Polling storage size for a subscription.
Definition: ntcore_cpp.h:321
NetworkTables Topic Information.
Definition: ntcore_cpp.h:89
wpi::json GetProperties() const
Get topic properties as a JSON object.
std::string name
Topic name.
Definition: ntcore_cpp.h:94
NT_Topic topic
Topic handle.
Definition: ntcore_cpp.h:91
std::string type_str
Topic type string.
Definition: ntcore_cpp.h:100
std::string properties
Topic properties JSON string.
Definition: ntcore_cpp.h:103
friend void swap(TopicInfo &first, TopicInfo &second)
Definition: ntcore_cpp.h:108
NT_Type type
Topic type.
Definition: ntcore_cpp.h:97
Client (as published via $clients).
Definition: ntcore_cpp.h:1367
std::string id
Definition: ntcore_cpp.h:1368
std::string conn
Definition: ntcore_cpp.h:1369
uint16_t version
Definition: ntcore_cpp.h:1370
Client publisher (as published via $clientpub$<client> or $serverpub).
Definition: ntcore_cpp.h:1350
int64_t uid
Definition: ntcore_cpp.h:1351
std::string topic
Definition: ntcore_cpp.h:1352
Client subscriber (as published via $clientsub$<client> or $serversub).
Definition: ntcore_cpp.h:1358
int64_t uid
Definition: ntcore_cpp.h:1359
std::vector< std::string > topics
Definition: ntcore_cpp.h:1360
SubscriberOptions options
Definition: ntcore_cpp.h:1361
Subscriber options.
Definition: ntcore_cpp.h:1322
bool topicsOnly
Definition: ntcore_cpp.h:1324
bool sendAll
Definition: ntcore_cpp.h:1325
double periodic
Definition: ntcore_cpp.h:1323
bool prefixMatch
Definition: ntcore_cpp.h:1326
Topic publisher (as published via $pub$<topic>).
Definition: ntcore_cpp.h:1333
uint64_t pubuid
Definition: ntcore_cpp.h:1335
std::string client
Definition: ntcore_cpp.h:1334
Topic subscriber (as published via $sub$<topic>).
Definition: ntcore_cpp.h:1341
SubscriberOptions options
Definition: ntcore_cpp.h:1344
std::string client
Definition: ntcore_cpp.h:1342
uint64_t subuid
Definition: ntcore_cpp.h:1343