001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.util.sendable;
006
007import edu.wpi.first.util.function.BooleanConsumer;
008import edu.wpi.first.util.function.FloatConsumer;
009import edu.wpi.first.util.function.FloatSupplier;
010import java.util.function.BooleanSupplier;
011import java.util.function.Consumer;
012import java.util.function.DoubleConsumer;
013import java.util.function.DoubleSupplier;
014import java.util.function.LongConsumer;
015import java.util.function.LongSupplier;
016import java.util.function.Supplier;
017
018/** Helper class for building Sendable dashboard representations. */
019public interface SendableBuilder extends AutoCloseable {
020  /** The backend kinds used for the sendable builder. */
021  enum BackendKind {
022    /** Unknown. */
023    kUnknown,
024
025    /** NetworkTables. */
026    kNetworkTables
027  }
028
029  /**
030   * Set the string representation of the named data type that will be used by the smart dashboard
031   * for this sendable.
032   *
033   * @param type data type
034   */
035  void setSmartDashboardType(String type);
036
037  /**
038   * Set a flag indicating if this Sendable should be treated as an actuator. By default, this flag
039   * is false.
040   *
041   * @param value true if actuator, false if not
042   */
043  void setActuator(boolean value);
044
045  /**
046   * Add a boolean property.
047   *
048   * @param key property name
049   * @param getter getter function (returns current value)
050   * @param setter setter function (sets new value)
051   */
052  void addBooleanProperty(String key, BooleanSupplier getter, BooleanConsumer setter);
053
054  /**
055   * Add a constant boolean property.
056   *
057   * @param key property name
058   * @param value the value
059   */
060  void publishConstBoolean(String key, boolean value);
061
062  /**
063   * Add an integer property.
064   *
065   * @param key property name
066   * @param getter getter function (returns current value)
067   * @param setter setter function (sets new value)
068   */
069  void addIntegerProperty(String key, LongSupplier getter, LongConsumer setter);
070
071  /**
072   * Add a constant integer property.
073   *
074   * @param key property name
075   * @param value the value
076   */
077  void publishConstInteger(String key, long value);
078
079  /**
080   * Add a float property.
081   *
082   * @param key property name
083   * @param getter getter function (returns current value)
084   * @param setter setter function (sets new value)
085   */
086  void addFloatProperty(String key, FloatSupplier getter, FloatConsumer setter);
087
088  /**
089   * Add a constant float property.
090   *
091   * @param key property name
092   * @param value the value
093   */
094  void publishConstFloat(String key, float value);
095
096  /**
097   * Add a double property.
098   *
099   * @param key property name
100   * @param getter getter function (returns current value)
101   * @param setter setter function (sets new value)
102   */
103  void addDoubleProperty(String key, DoubleSupplier getter, DoubleConsumer setter);
104
105  /**
106   * Add a constant double property.
107   *
108   * @param key property name
109   * @param value the value
110   */
111  void publishConstDouble(String key, double value);
112
113  /**
114   * Add a string property.
115   *
116   * @param key property name
117   * @param getter getter function (returns current value)
118   * @param setter setter function (sets new value)
119   */
120  void addStringProperty(String key, Supplier<String> getter, Consumer<String> setter);
121
122  /**
123   * Add a constant string property.
124   *
125   * @param key property name
126   * @param value the value
127   */
128  void publishConstString(String key, String value);
129
130  /**
131   * Add a boolean array property.
132   *
133   * @param key property name
134   * @param getter getter function (returns current value)
135   * @param setter setter function (sets new value)
136   */
137  void addBooleanArrayProperty(String key, Supplier<boolean[]> getter, Consumer<boolean[]> setter);
138
139  /**
140   * Add a constant boolean array property.
141   *
142   * @param key property name
143   * @param value the value
144   */
145  void publishConstBooleanArray(String key, boolean[] value);
146
147  /**
148   * Add an integer array property.
149   *
150   * @param key property name
151   * @param getter getter function (returns current value)
152   * @param setter setter function (sets new value)
153   */
154  void addIntegerArrayProperty(String key, Supplier<long[]> getter, Consumer<long[]> setter);
155
156  /**
157   * Add a constant integer property.
158   *
159   * @param key property name
160   * @param value the value
161   */
162  void publishConstIntegerArray(String key, long[] value);
163
164  /**
165   * Add a float array property.
166   *
167   * @param key property name
168   * @param getter getter function (returns current value)
169   * @param setter setter function (sets new value)
170   */
171  void addFloatArrayProperty(String key, Supplier<float[]> getter, Consumer<float[]> setter);
172
173  /**
174   * Add a constant float array property.
175   *
176   * @param key property name
177   * @param value the value
178   */
179  void publishConstFloatArray(String key, float[] value);
180
181  /**
182   * Add a double array property.
183   *
184   * @param key property name
185   * @param getter getter function (returns current value)
186   * @param setter setter function (sets new value)
187   */
188  void addDoubleArrayProperty(String key, Supplier<double[]> getter, Consumer<double[]> setter);
189
190  /**
191   * Add a constant double array property.
192   *
193   * @param key property name
194   * @param value the value
195   */
196  void publishConstDoubleArray(String key, double[] value);
197
198  /**
199   * Add a string array property.
200   *
201   * @param key property name
202   * @param getter getter function (returns current value)
203   * @param setter setter function (sets new value)
204   */
205  void addStringArrayProperty(String key, Supplier<String[]> getter, Consumer<String[]> setter);
206
207  /**
208   * Add a constant string array property.
209   *
210   * @param key property name
211   * @param value the value
212   */
213  void publishConstStringArray(String key, String[] value);
214
215  /**
216   * Add a raw property.
217   *
218   * @param key property name
219   * @param typeString type string
220   * @param getter getter function (returns current value)
221   * @param setter setter function (sets new value)
222   */
223  void addRawProperty(
224      String key, String typeString, Supplier<byte[]> getter, Consumer<byte[]> setter);
225
226  /**
227   * Add a constant raw property.
228   *
229   * @param key property name
230   * @param typeString type string
231   * @param value the value
232   */
233  void publishConstRaw(String key, String typeString, byte[] value);
234
235  /**
236   * Gets the kind of backend being used.
237   *
238   * @return Backend kind
239   */
240  BackendKind getBackendKind();
241
242  /**
243   * Return whether this sendable has been published.
244   *
245   * @return True if it has been published, false if not.
246   */
247  boolean isPublished();
248
249  /** Update the published values by calling the getters for all properties. */
250  void update();
251
252  /** Clear properties. */
253  void clearProperties();
254
255  /**
256   * Adds a closeable. The closeable.close() will be called when close() is called.
257   *
258   * @param closeable closeable object
259   */
260  void addCloseable(AutoCloseable closeable);
261}