macro_rules! action {
($plugin_name:ident : $name:expr; $($tokens:tt)*) => { ... };
}Expand description
Creates an action plugin from Beetry’s leaf-node DSL.
The generated plugin:
- defines a
NodeSpec - defines optional port metadata and parameter metadata
- defines a factory that reconstructs the action from reconstruction data
- registers itself automatically
Minimal action without params or channels:
struct WaitForSignal;
impl ActionBehavior for WaitForSignal {
fn task(&mut self) -> Result<ActionTask> {
}
}
action! {
WaitForSignalPlugin: "Wait For Signal";
create: WaitForSignal;
}Action with parameters:
Parameters are provided via params(binding): ParamsType syntax
Prerequisites: ParamsType is expected to implement
crate::ProvideParamSpec and be deserializable
#[derive(Deserialize)]
struct RetryParams {
retries: u64,
}
impl ProvideParamSpec for RetryParams {
fn provide() -> ParamsSpec {
}
}
struct RetryAction {
params: RetryParams,
}
impl RetryAction {
fn new(params: RetryParams) -> Self {
}
}
impl ActionBehavior for RetryAction {
fn task(&mut self) -> Result<ActionTask> {
}
}
action! {
RetryActionPlugin: "Retry Action";
params(parameters): RetryParams;
create: RetryAction::new(parameters);
}Action with one receiver and one sender:
#[derive(Debug, Clone, Copy, Default, TypeHash, Message)]
struct Pose;
struct RelayPose<R, S>
where
R: Receiver<Pose>,
S: Sender<Pose>,
{
input: R,
output: S,
}
impl<R, S> RelayPose<R, S>
where
R: Receiver<Pose>,
S: Sender<Pose>,
{
fn new(input: R, output: S) -> Self {
Self { input, output }
}
}
impl<R, S> ActionBehavior for RelayPose<R, S>
where
R: Receiver<Pose>,
S: Sender<Pose>,
{
fn task(&mut self) -> Result<ActionTask> {
}
}
action! {
RelayPosePlugin: "Relay Pose";
receivers: [input: Pose => "Incoming pose"];
senders: [output: Pose => "Republished pose"];
create: RelayPose::new(input, output);
}The DSL supports both parameters and ports, so action nodes that depend on channels and parameters can be defined by combining the examples above.