Behaviour for parameter persistence backends.
Implementations handle loading and saving parameter values to durable storage. The store is initialized when a robot starts and closed when it stops.
Lifecycle
init/2- Called during robot startup with module name and optionsload/1- Called to retrieve all persisted parameterssave/3- Called after each successful parameter changeclose/1- Called during robot shutdown
Built-in Implementations
BB.Parameter.Store.Dets- Disk-backed storage using OTP's:dets
Example Implementation
defmodule MyApp.ParameterStore do
@behaviour BB.Parameter.Store
@impl true
def init(robot_module, opts) do
# Initialize storage connection
{:ok, %{robot: robot_module, conn: connect(opts)}}
end
@impl true
def load(state) do
# Return all stored parameters
{:ok, fetch_all(state.conn)}
end
@impl true
def save(state, path, value) do
# Persist a parameter change
:ok = write(state.conn, path, value)
:ok
end
@impl true
def close(state) do
# Clean up resources
disconnect(state.conn)
:ok
end
end
Summary
Callbacks
Close the parameter store.
Initialize the parameter store.
Load all persisted parameters.
Save a parameter value.
Types
Callbacks
@callback close(state()) :: :ok
Close the parameter store.
Called during robot shutdown. Implementations should release any resources (file handles, connections, etc.).
Initialize the parameter store.
Called during robot startup. The robot_module identifies which robot
this store is for (useful for multi-robot setups). Options come from
the DSL configuration.
Returns {:ok, state} where state is passed to subsequent callbacks,
or {:error, reason} if initialization fails.
Load all persisted parameters.
Called after initialization to retrieve previously saved parameter values.
Returns a list of {path, value} tuples.
These values are applied after DSL defaults, so persisted values take precedence over defaults.
Save a parameter value.
Called after each successful BB.Parameter.set/3 operation.
The implementation should persist the value durably.