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