001/*----------------------------------------------------------------------------*/
002/* Copyright (c) 2017-2018 FIRST. All Rights Reserved.                        */
003/* Open Source Software - may be modified and shared by FRC teams. The code   */
004/* must be accompanied by the FIRST BSD license file in the root directory of */
005/* the project.                                                               */
006/*----------------------------------------------------------------------------*/
007
008package edu.wpi.first.wpilibj.smartdashboard;
009
010import edu.wpi.first.networktables.NetworkTableEntry;
011import edu.wpi.first.networktables.NetworkTableValue;
012import java.util.function.BooleanSupplier;
013import java.util.function.Consumer;
014import java.util.function.DoubleConsumer;
015import java.util.function.DoubleSupplier;
016import java.util.function.Supplier;
017
018public interface SendableBuilder {
019  /**
020   * Set the string representation of the named data type that will be used
021   * by the smart dashboard for this sendable.
022   *
023   * @param type    data type
024   */
025  void setSmartDashboardType(String type);
026
027  /**
028   * Set the function that should be called to set the Sendable into a safe
029   * state.  This is called when entering and exiting Live Window mode.
030   *
031   * @param func    function
032   */
033  void setSafeState(Runnable func);
034
035  /**
036   * Set the function that should be called to update the network table
037   * for things other than properties.  Note this function is not passed
038   * the network table object; instead it should use the entry handles
039   * returned by getEntry().
040   *
041   * @param func    function
042   */
043  void setUpdateTable(Runnable func);
044
045  /**
046   * Add a property without getters or setters.  This can be used to get
047   * entry handles for the function called by setUpdateTable().
048   *
049   * @param key   property name
050   * @return Network table entry
051   */
052  NetworkTableEntry getEntry(String key);
053
054  /**
055   * Represents an operation that accepts a single boolean-valued argument and
056   * returns no result. This is the primitive type specialization of Consumer
057   * for boolean. Unlike most other functional interfaces, BooleanConsumer is
058   * expected to operate via side-effects.
059   *
060   * <p>This is a functional interface whose functional method is accept(boolean).
061   */
062  @FunctionalInterface
063  interface BooleanConsumer {
064    /**
065     * Performs the operation on the given value.
066     * @param value the value
067     */
068    void accept(boolean value);
069  }
070
071  /**
072   * Add a boolean property.
073   *
074   * @param key     property name
075   * @param getter  getter function (returns current value)
076   * @param setter  setter function (sets new value)
077   */
078  void addBooleanProperty(String key, BooleanSupplier getter, BooleanConsumer setter);
079
080  /**
081   * Add a double property.
082   *
083   * @param key     property name
084   * @param getter  getter function (returns current value)
085   * @param setter  setter function (sets new value)
086   */
087  void addDoubleProperty(String key, DoubleSupplier getter, DoubleConsumer setter);
088
089  /**
090   * Add a string property.
091   *
092   * @param key     property name
093   * @param getter  getter function (returns current value)
094   * @param setter  setter function (sets new value)
095   */
096  void addStringProperty(String key, Supplier<String> getter, Consumer<String> setter);
097
098  /**
099   * Add a boolean array property.
100   *
101   * @param key     property name
102   * @param getter  getter function (returns current value)
103   * @param setter  setter function (sets new value)
104   */
105  void addBooleanArrayProperty(String key, Supplier<boolean[]> getter, Consumer<boolean[]> setter);
106
107  /**
108   * Add a double array property.
109   *
110   * @param key     property name
111   * @param getter  getter function (returns current value)
112   * @param setter  setter function (sets new value)
113   */
114  void addDoubleArrayProperty(String key, Supplier<double[]> getter, Consumer<double[]> setter);
115
116  /**
117   * Add a string array property.
118   *
119   * @param key     property name
120   * @param getter  getter function (returns current value)
121   * @param setter  setter function (sets new value)
122   */
123  void addStringArrayProperty(String key, Supplier<String[]> getter, Consumer<String[]> setter);
124
125  /**
126   * Add a raw property.
127   *
128   * @param key     property name
129   * @param getter  getter function (returns current value)
130   * @param setter  setter function (sets new value)
131   */
132  void addRawProperty(String key, Supplier<byte[]> getter, Consumer<byte[]> setter);
133
134  /**
135   * Add a NetworkTableValue 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 addValueProperty(String key, Supplier<NetworkTableValue> getter,
142                        Consumer<NetworkTableValue> setter);
143}