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 an integer property. 060 * 061 * @param key property name 062 * @param getter getter function (returns current value) 063 * @param setter setter function (sets new value) 064 */ 065 void addIntegerProperty(String key, LongSupplier getter, LongConsumer setter); 066 067 /** 068 * Add a float property. 069 * 070 * @param key property name 071 * @param getter getter function (returns current value) 072 * @param setter setter function (sets new value) 073 */ 074 void addFloatProperty(String key, FloatSupplier getter, FloatConsumer setter); 075 076 /** 077 * Add a double property. 078 * 079 * @param key property name 080 * @param getter getter function (returns current value) 081 * @param setter setter function (sets new value) 082 */ 083 void addDoubleProperty(String key, DoubleSupplier getter, DoubleConsumer setter); 084 085 /** 086 * Add a string property. 087 * 088 * @param key property name 089 * @param getter getter function (returns current value) 090 * @param setter setter function (sets new value) 091 */ 092 void addStringProperty(String key, Supplier<String> getter, Consumer<String> setter); 093 094 /** 095 * Add a boolean array property. 096 * 097 * @param key property name 098 * @param getter getter function (returns current value) 099 * @param setter setter function (sets new value) 100 */ 101 void addBooleanArrayProperty(String key, Supplier<boolean[]> getter, Consumer<boolean[]> setter); 102 103 /** 104 * Add an integer array property. 105 * 106 * @param key property name 107 * @param getter getter function (returns current value) 108 * @param setter setter function (sets new value) 109 */ 110 void addIntegerArrayProperty(String key, Supplier<long[]> getter, Consumer<long[]> setter); 111 112 /** 113 * Add a float array property. 114 * 115 * @param key property name 116 * @param getter getter function (returns current value) 117 * @param setter setter function (sets new value) 118 */ 119 void addFloatArrayProperty(String key, Supplier<float[]> getter, Consumer<float[]> setter); 120 121 /** 122 * Add a double array property. 123 * 124 * @param key property name 125 * @param getter getter function (returns current value) 126 * @param setter setter function (sets new value) 127 */ 128 void addDoubleArrayProperty(String key, Supplier<double[]> getter, Consumer<double[]> setter); 129 130 /** 131 * Add a string 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 addStringArrayProperty(String key, Supplier<String[]> getter, Consumer<String[]> setter); 138 139 /** 140 * Add a raw property. 141 * 142 * @param key property name 143 * @param typeString type string 144 * @param getter getter function (returns current value) 145 * @param setter setter function (sets new value) 146 */ 147 void addRawProperty( 148 String key, String typeString, Supplier<byte[]> getter, Consumer<byte[]> setter); 149 150 /** 151 * Gets the kind of backend being used. 152 * 153 * @return Backend kind 154 */ 155 BackendKind getBackendKind(); 156 157 /** 158 * Return whether this sendable has been published. 159 * 160 * @return True if it has been published, false if not. 161 */ 162 boolean isPublished(); 163 164 /** Update the published values by calling the getters for all properties. */ 165 void update(); 166 167 /** Clear properties. */ 168 void clearProperties(); 169 170 /** 171 * Adds a closeable. The closeable.close() will be called when close() is called. 172 * 173 * @param closeable closeable object 174 */ 175 void addCloseable(AutoCloseable closeable); 176}