Shared parameter resolution logic for wrapper servers.
This module provides functions for resolving ParamRef values in options
and subscribing to parameter change notifications. Used by:
Usage
In your server's init/1:
{param_subscriptions, resolved_opts} =
ParamResolution.resolve_and_subscribe(raw_opts, robot_module)In handle_info/2 for parameter changes:
def handle_info({:bb, [:param | param_path], %{payload: %ParameterChanged{}}}, state) do
ParamResolution.handle_param_change(
param_path,
state.param_subscriptions,
state.raw_opts,
robot_module,
fn new_resolved ->
# Call user's handle_options callback
end
)
end
Summary
Functions
Handle a parameter change message.
Resolve ParamRefs in options without subscribing.
Resolve ParamRefs in options and subscribe to parameter change topics.
Subscribe to parameter change topics for tracked parameters.
Types
Functions
@spec handle_change( [atom()], subscriptions(), keyword(), module() | BB.Robot.State.t() ) :: {:changed, keyword()} | :ignored
Handle a parameter change message.
Checks if the changed parameter is one we're subscribed to, re-resolves all options, and calls the provided callback with the new options.
Returns {:changed, new_resolved} if the parameter was tracked,
or :ignored if not.
@spec resolve( keyword(), module() | BB.Robot.State.t() ) :: {subscriptions(), keyword()}
Resolve ParamRefs in options without subscribing.
Takes either a robot module or a BB.Robot.State struct directly.
Passing the state directly avoids a lookup and potential deadlock
during init when the Runtime is still starting.
@spec resolve_and_subscribe( keyword(), module() | BB.Robot.State.t() ) :: {subscriptions(), keyword()}
Resolve ParamRefs in options and subscribe to parameter change topics.
Returns {subscriptions_map, resolved_opts} where:
subscriptions_mapmaps parameter paths to option keysresolved_optshas ParamRefs replaced with their current values
This is a convenience function that calls resolve/2 and subscribe/2.
@spec subscribe(module(), subscriptions()) :: :ok
Subscribe to parameter change topics for tracked parameters.