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 java.util.function.BooleanSupplier;
009import java.util.function.Consumer;
010import java.util.function.DoubleConsumer;
011import java.util.function.DoubleSupplier;
012import java.util.function.Supplier;
013
014public interface SendableBuilder {
015  /** The backend kinds used for the sendable builder. */
016  enum BackendKind {
017    kUnknown,
018    kNetworkTables
019  }
020
021  /**
022   * Set the string representation of the named data type that will be used by the smart dashboard
023   * for this sendable.
024   *
025   * @param type data type
026   */
027  void setSmartDashboardType(String type);
028
029  /**
030   * Set a flag indicating if this sendable should be treated as an actuator. By default this flag
031   * is false.
032   *
033   * @param value true if actuator, false if not
034   */
035  void setActuator(boolean value);
036
037  /**
038   * Set the function that should be called to set the Sendable into a safe state. This is called
039   * when entering and exiting Live Window mode.
040   *
041   * @param func function
042   */
043  void setSafeState(Runnable func);
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 double property.
056   *
057   * @param key property name
058   * @param getter getter function (returns current value)
059   * @param setter setter function (sets new value)
060   */
061  void addDoubleProperty(String key, DoubleSupplier getter, DoubleConsumer setter);
062
063  /**
064   * Add a string property.
065   *
066   * @param key property name
067   * @param getter getter function (returns current value)
068   * @param setter setter function (sets new value)
069   */
070  void addStringProperty(String key, Supplier<String> getter, Consumer<String> setter);
071
072  /**
073   * Add a boolean array property.
074   *
075   * @param key property name
076   * @param getter getter function (returns current value)
077   * @param setter setter function (sets new value)
078   */
079  void addBooleanArrayProperty(String key, Supplier<boolean[]> getter, Consumer<boolean[]> setter);
080
081  /**
082   * Add a double array property.
083   *
084   * @param key property name
085   * @param getter getter function (returns current value)
086   * @param setter setter function (sets new value)
087   */
088  void addDoubleArrayProperty(String key, Supplier<double[]> getter, Consumer<double[]> setter);
089
090  /**
091   * Add a string array property.
092   *
093   * @param key property name
094   * @param getter getter function (returns current value)
095   * @param setter setter function (sets new value)
096   */
097  void addStringArrayProperty(String key, Supplier<String[]> getter, Consumer<String[]> setter);
098
099  /**
100   * Add a raw property.
101   *
102   * @param key property name
103   * @param getter getter function (returns current value)
104   * @param setter setter function (sets new value)
105   */
106  void addRawProperty(String key, Supplier<byte[]> getter, Consumer<byte[]> setter);
107
108  /**
109   * Gets the kind of backend being used.
110   *
111   * @return Backend kind
112   */
113  BackendKind getBackendKind();
114
115  /**
116   * Return whether this sendable has been published.
117   *
118   * @return True if it has been published, false if not.
119   */
120  boolean isPublished();
121
122  /** Update the published values by calling the getters for all properties. */
123  void update();
124
125  /** Clear properties. */
126  void clearProperties();
127}