Class TunableRegistry
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceHandler for tuning objects of specific type. -
Method Summary
Modifier and TypeMethodDescriptionstatic TunableBackendgetBackend(String path) Gets the backend for creating a tunable.Get function used for reporting warning messages.static TunableTableGet a tunable table for a particular name.static <T> TunableRegistry.TypeHandler<T> getTypeHandler(T value) Gets the handler for logging an object.static booleanpublish(String path, ComplexTunable tunable) Publishes a complex tunable.static booleanpublish(String path, TunableBase tunable) Publishes a tunable.static voidpublishComplexChildren(String path, ComplexTunable tunable) Publishes a complex tunable's children.static voidregisterBackend(String prefix, TunableBackend backend) Registers a backend for creating tunables.static <T> voidregisterTypeHandler(Class<T> cls, TunableRegistry.TypeHandler<T> handler) Registers a handler for tuning objects of a particular type.static voidRemoves a tunable.static voidremove(ComplexTunable tunable) Removes every tracked publication for a complex tunable.static voidreportWarning(String msg) Report a warning message (e.g.static voidreset()Clear all registered types and backends and closes all entries.static voidresetChangedAfterUpdate(TunableBase tunable) Resets a tunable's changed flag after the current update cycle finishes.static voidrunAfterUpdate(Runnable callback) Runs a callback after the current update cycle finishes resetting changed flags.static voidsetReportWarning(Consumer<String> func) Set function used for reporting warning messages (e.g.static voidupdate()Updates all tunable values from backends.static voidupdateComplexIfNeeded(ComplexTunable tunable) Updates a complex tunable if it has not already been updated during the current registry update.static voidwithUpdateMutex(Runnable func) Execute a function while holding the same mutex used for update().
-
Method Details
-
setReportWarning
-
getReportWarning
-
reportWarning
Report a warning message (e.g. type mismatch).- Parameters:
msg- warning message
-
registerTypeHandler
Registers a handler for tuning objects of a particular type. The handler should populate the provided TunableTable name as appropriate for the object's data.- Type Parameters:
T- class- Parameters:
cls- class objecthandler- handler (accepts TunableTable, entry name, and object)
-
registerBackend
Registers a backend for creating tunables. When calling getBackend(), the longest prefix match is used.- Parameters:
prefix- prefix for tunables covered by this backendbackend- backend
-
getTypeHandler
Gets the handler for logging an object. Should generally only be used by Tunable.- Type Parameters:
T- class- Parameters:
value- value- Returns:
- handler or null if no match
-
getBackend
Gets the backend for creating a tunable. Should generally only be used internally or by custom backends.- Parameters:
path- full name- Returns:
- tunable backend, or a no-op backend if no match
-
resetChangedAfterUpdate
Resets a tunable's changed flag after the current update cycle finishes.Backends should call this after publishing a changed tunable so every alias in every backend can observe the shared changed flag before it is cleared.
- Parameters:
tunable- tunable to reset
-
runAfterUpdate
Runs a callback after the current update cycle finishes resetting changed flags.Backends should use this for callbacks that react to tuned values so callback mutations are observed as new changes in the next update cycle.
- Parameters:
callback- callback to run; must not throw
-
updateComplexIfNeeded
Updates a complex tunable if it has not already been updated during the current registry update.This should generally only be used by
TunableBackendimplementations.- Parameters:
tunable- tunable to update
-
getTable
Get a tunable table for a particular name.- Parameters:
path- full name- Returns:
- tunable table
-
publishComplexChildren
Publishes a complex tunable's children.This should generally only be used by
TunableBackendimplementations after they publish the complex parent entry.- Parameters:
path- normalized pathtunable- the tunable
-
publish
Publishes a tunable.- Parameters:
path- normalized pathtunable- the tunable- Returns:
- true if the backend accepted the tunable
-
publish
Publishes a complex tunable.- Parameters:
path- normalized pathtunable- the tunable- Returns:
- true if the backend accepted the tunable
-
remove
-
remove
Removes every tracked publication for a complex tunable.- Parameters:
tunable- complex tunable to remove
-
update
public static void update()Updates all tunable values from backends. -
withUpdateMutex
Execute a function while holding the same mutex used for update(). As tunables are not thread-safe, this is designed to allow external synchronization for tunables used in secondary threads outside of the robot main loop.Every competing access, including main-loop access, must use this method or another safe handoff. The update mutex is held while backends and user callbacks run, so the function should be short and must not allow a mutable tunable value to escape and be accessed after the function completes.
- Parameters:
func- function to execute
-
reset
public static void reset()Clear all registered types and backends and closes all entries. Should typically only be used by unit test code.
-