WPILibC++ 2027.0.0-alpha-2
Loading...
Searching...
No Matches
SendableRegistry.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 <memory>
8#include <string>
9#include <string_view>
10
11namespace wpi {
12
13class Sendable;
14class SendableBuilder;
15
16/**
17 * The SendableRegistry class is the public interface for registering sensors
18 * and actuators for use on dashboards.
19 */
20class SendableRegistry final {
21 public:
22 SendableRegistry() = delete;
23
24 using UID = size_t;
25
26 /**
27 * Initializes the SendableRegistry. This is used to ensure initialization and
28 * destruction order relative to Sendables.
29 */
30 static void EnsureInitialized();
31
32 /**
33 * Adds an object to the registry.
34 *
35 * @param sendable object to add
36 * @param name component name
37 */
38 static void Add(Sendable* sendable, std::string_view name);
39
40 /**
41 * Adds an object to the registry.
42 *
43 * @param sendable object to add
44 * @param moduleType A string that defines the module name in the label for
45 * the value
46 * @param channel The channel number the device is plugged into
47 */
48 static void Add(Sendable* sendable, std::string_view moduleType, int channel);
49
50 /**
51 * Adds an object to the registry.
52 *
53 * @param sendable object to add
54 * @param moduleType A string that defines the module name in the label for
55 * the value
56 * @param moduleNumber The number of the particular module type
57 * @param channel The channel number the device is plugged into
58 */
59 static void Add(Sendable* sendable, std::string_view moduleType,
60 int moduleNumber, int channel);
61
62 /**
63 * Adds an object to the registry.
64 *
65 * @param sendable object to add
66 * @param subsystem subsystem name
67 * @param name component name
68 */
69 static void Add(Sendable* sendable, std::string_view subsystem,
70 std::string_view name);
71
72 /**
73 * Adds a child object to an object. Adds the child object to the registry
74 * if it's not already present.
75 *
76 * @param parent parent object
77 * @param child child object
78 */
79 static void AddChild(Sendable* parent, Sendable* child);
80
81 /**
82 * Adds a child object to an object. Adds the child object to the registry
83 * if it's not already present.
84 *
85 * @param parent parent object
86 * @param child child object
87 */
88 static void AddChild(Sendable* parent, void* child);
89
90 /**
91 * Removes an object from the registry.
92 *
93 * @param sendable object to remove
94 * @return true if the object was removed; false if it was not present
95 */
96 static bool Remove(Sendable* sendable);
97
98 /**
99 * Moves an object in the registry (for use in move constructors/assignments).
100 *
101 * @param to new object
102 * @param from old object
103 */
104 static void Move(Sendable* to, Sendable* from);
105
106 /**
107 * Determines if an object is in the registry.
108 *
109 * @param sendable object to check
110 * @return True if in registry, false if not.
111 */
112 static bool Contains(const Sendable* sendable);
113
114 /**
115 * Gets the name of an object.
116 *
117 * @param sendable object
118 * @return Name (empty if object is not in registry)
119 */
120 static std::string GetName(const Sendable* sendable);
121
122 /**
123 * Sets the name of an object.
124 *
125 * @param sendable object
126 * @param name name
127 */
128 static void SetName(Sendable* sendable, std::string_view name);
129
130 /**
131 * Sets the name of an object with a channel number.
132 *
133 * @param sendable object
134 * @param moduleType A string that defines the module name in the label for
135 * the value
136 * @param channel The channel number the device is plugged into
137 */
138 static void SetName(Sendable* sendable, std::string_view moduleType,
139 int channel);
140
141 /**
142 * Sets the name of an object with a module and channel number.
143 *
144 * @param sendable object
145 * @param moduleType A string that defines the module name in the label for
146 * the value
147 * @param moduleNumber The number of the particular module type
148 * @param channel The channel number the device is plugged into
149 */
150 static void SetName(Sendable* sendable, std::string_view moduleType,
151 int moduleNumber, int channel);
152
153 /**
154 * Sets both the subsystem name and device name of an object.
155 *
156 * @param sendable object
157 * @param subsystem subsystem name
158 * @param name device name
159 */
160 static void SetName(Sendable* sendable, std::string_view subsystem,
161 std::string_view name);
162
163 /**
164 * Gets the subsystem name of an object.
165 *
166 * @param sendable object
167 * @return Subsystem name (empty if object is not in registry)
168 */
169 static std::string GetSubsystem(const Sendable* sendable);
170
171 /**
172 * Sets the subsystem name of an object.
173 *
174 * @param sendable object
175 * @param subsystem subsystem name
176 */
177 static void SetSubsystem(Sendable* sendable, std::string_view subsystem);
178
179 /**
180 * Gets a unique handle for setting/getting data with SetData() and GetData().
181 *
182 * @return Handle
183 */
184 static int GetDataHandle();
185
186 /**
187 * Associates arbitrary data with an object in the registry.
188 *
189 * @param sendable object
190 * @param handle data handle returned by GetDataHandle()
191 * @param data data to set
192 * @return Previous data (may be null)
193 */
194 static std::shared_ptr<void> SetData(Sendable* sendable, int handle,
195 std::shared_ptr<void> data);
196
197 /**
198 * Gets arbitrary data associated with an object in the registry.
199 *
200 * @param sendable object
201 * @param handle data handle returned by GetDataHandle()
202 * @return data (may be null if none associated)
203 */
204 static std::shared_ptr<void> GetData(Sendable* sendable, int handle);
205
206 /**
207 * Get unique id for an object. Since objects can move, use this instead
208 * of storing Sendable* directly if ownership is in question.
209 *
210 * @param sendable object
211 * @return unique id
212 */
213 static UID GetUniqueId(Sendable* sendable);
214
215 /**
216 * Get sendable object for a given unique id.
217 *
218 * @param uid unique id
219 * @return sendable object (may be null)
220 */
222
223 /**
224 * Publishes an object in the registry.
225 *
226 * @param sendableUid sendable unique id
227 * @param builder publisher backend
228 */
229 static void Publish(UID sendableUid,
230 std::unique_ptr<SendableBuilder> builder);
231
232 /**
233 * Updates published information from an object.
234 *
235 * @param sendableUid sendable unique id
236 */
237 static void Update(UID sendableUid);
238};
239
240} // namespace wpi
and restrictions which apply to each piece of software is included later in this file and or inside of the individual applicable source files The disclaimer of warranty in the WPILib license above applies to all code in and nothing in any of the other licenses gives permission to use the names of FIRST nor the names of the WPILib contributors to endorse or promote products derived from this software The following pieces of software have additional or alternate and or glfw and nanopb were modified for use in Google Inc All rights reserved Redistribution and use in source and binary with or without are permitted provided that the following conditions are this list of conditions and the following disclaimer *Redistributions in binary form must reproduce the above copyright this list of conditions and the following disclaimer in the documentation and or other materials provided with the distribution *Neither the name of Google Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY OR CONSEQUENTIAL WHETHER IN STRICT OR EVEN IF ADVISED OF THE POSSIBILITY OF SUCH January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable from
Definition ThirdPartyNotices.txt:140
Interface for Sendable objects.
Definition Sendable.h:16
The SendableRegistry class is the public interface for registering sensors and actuators for use on d...
Definition SendableRegistry.h:20
static std::string GetName(const Sendable *sendable)
Gets the name of an object.
static Sendable * GetSendable(UID uid)
Get sendable object for a given unique id.
size_t UID
Definition SendableRegistry.h:24
static std::shared_ptr< void > GetData(Sendable *sendable, int handle)
Gets arbitrary data associated with an object in the registry.
static void SetName(Sendable *sendable, std::string_view name)
Sets the name of an object.
static std::string GetSubsystem(const Sendable *sendable)
Gets the subsystem name of an object.
static void SetSubsystem(Sendable *sendable, std::string_view subsystem)
Sets the subsystem name of an object.
static void Add(Sendable *sendable, std::string_view moduleType, int channel)
Adds an object to the registry.
static UID GetUniqueId(Sendable *sendable)
Get unique id for an object.
static void EnsureInitialized()
Initializes the SendableRegistry.
static void Add(Sendable *sendable, std::string_view subsystem, std::string_view name)
Adds an object to the registry.
static void SetName(Sendable *sendable, std::string_view subsystem, std::string_view name)
Sets both the subsystem name and device name of an object.
static std::shared_ptr< void > SetData(Sendable *sendable, int handle, std::shared_ptr< void > data)
Associates arbitrary data with an object in the registry.
static void SetName(Sendable *sendable, std::string_view moduleType, int moduleNumber, int channel)
Sets the name of an object with a module and channel number.
static void Publish(UID sendableUid, std::unique_ptr< SendableBuilder > builder)
Publishes an object in the registry.
static void Update(UID sendableUid)
Updates published information from an object.
static void Move(Sendable *to, Sendable *from)
Moves an object in the registry (for use in move constructors/assignments).
static void Add(Sendable *sendable, std::string_view name)
Adds an object to the registry.
static int GetDataHandle()
Gets a unique handle for setting/getting data with SetData() and GetData().
static void AddChild(Sendable *parent, void *child)
Adds a child object to an object.
static void SetName(Sendable *sendable, std::string_view moduleType, int channel)
Sets the name of an object with a channel number.
static void AddChild(Sendable *parent, Sendable *child)
Adds a child object to an object.
static bool Remove(Sendable *sendable)
Removes an object from the registry.
static bool Contains(const Sendable *sendable)
Determines if an object is in the registry.
static void Add(Sendable *sendable, std::string_view moduleType, int moduleNumber, int channel)
Adds an object to the registry.
Definition ntcore_cpp.h:26