Skip to content

Commit

Permalink
output: add dynamics
Browse files Browse the repository at this point in the history
  • Loading branch information
fooker committed Oct 14, 2024
1 parent 2552f5a commit 13b6fe4
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 12 deletions.
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dynamic/runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ photonic = { workspace = true }
photonic-dynamic = { path = ".." }
photonic-effects = { path = "../../effects", features = ["dynamic"] }
photonic-output-terminal = { path = "../../output-terminal", features = ["dynamic"] }
photonic-output-null = { path = "../../output-null", features = ["dynamic"] }
photonic-output-split = { path = "../../output-split", features = ["dynamic"] }

anyhow = { workspace = true }
tokio = { workspace = true, features = ["full"] }
Expand Down
7 changes: 6 additions & 1 deletion dynamic/runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ impl Registry for RunnerRegistries {
return combine!(
output,
kind,
(photonic_effects::dynamic::Registry, photonic_output_terminal::dynamic::Registry)
(
photonic_effects::dynamic::Registry,
photonic_output_terminal::dynamic::Registry,
photonic_output_null::dynamic::Registry,
photonic_output_split::dynamic::Registry
)
);
}
}
6 changes: 6 additions & 0 deletions output-null/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ authors.workspace = true
edition.workspace = true
license.workspace = true

[features]
dynamic = ["dep:photonic-dynamic", "dep:serde"]

[dependencies]
photonic = { workspace = true }
photonic-dynamic = { path = "../dynamic", optional = true }

palette = { workspace = true }
anyhow = { workspace = true }

serde = { version = "1.0.197", features = ["derive"], optional = true }

[lints]
workspace = true
40 changes: 40 additions & 0 deletions output-null/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,43 @@ impl<E> Output for NullOutput<E> {
return self.size;
}
}

#[cfg(feature = "dynamic")]
pub mod dynamic {
use anyhow::Result;
use palette::rgb::Rgb;
use serde::Deserialize;

use photonic::boxed::DynOutputDecl;
use photonic_dynamic::factory::{factory, OutputFactory, Producible};
use photonic_dynamic::{builder, registry};

use crate::Null;

#[derive(Deserialize)]
pub struct Config {
size: usize,
}

impl Producible<dyn DynOutputDecl> for Config {
type Product = Null<Rgb>;

fn produce<Reg: registry::Registry>(
config: Self,
_builder: builder::OutputBuilder<'_, Reg>,
) -> Result<Self::Product> {
return Ok(Null::with_size(config.size));
}
}

pub struct Registry;

impl registry::Registry for Registry {
fn output<Reg: registry::Registry>(kind: &str) -> Option<OutputFactory<Reg>> {
return match kind {
"null" => Some(factory::<Config>()),
_ => return None,
};
}
}
}
6 changes: 6 additions & 0 deletions output-split/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ authors.workspace = true
edition.workspace = true
license.workspace = true

[features]
dynamic = ["dep:photonic-dynamic", "dep:serde"]

[dependencies]
photonic = { workspace = true, features = ["boxed"] }
photonic-dynamic = { path = "../dynamic", optional = true }

palette = { workspace = true }
anyhow = { workspace = true }

futures = { workspace = true }

serde = { version = "1.0.197", features = ["derive"], optional = true }

[dev-dependencies]
photonic-output-null = { path = "../output-null" }

Expand Down
48 changes: 48 additions & 0 deletions output-split/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,51 @@ impl Output for SplitOutput {
return self.size;
}
}

#[cfg(feature = "dynamic")]
pub mod dynamic {
use anyhow::Result;
use serde::Deserialize;

use photonic::boxed::{Boxed, DynOutputDecl};
use photonic_dynamic::config::Output;
use photonic_dynamic::factory::{factory, OutputFactory, Producible};
use photonic_dynamic::{builder, registry};

use crate::Split;

#[derive(Deserialize)]
pub struct Config {
outputs: Vec<Output>,
}

impl Producible<dyn DynOutputDecl> for Config {
type Product = Split;

fn produce<Reg: registry::Registry>(
config: Self,
mut builder: builder::OutputBuilder<'_, Reg>,
) -> Result<Self::Product> {
let outputs = config
.outputs
.into_iter()
.map(|config| anyhow::Ok(builder.output(config)?.boxed()))
.collect::<Result<Vec<_>>>()?;

return Ok(Split {
outputs,
});
}
}

pub struct Registry;

impl registry::Registry for Registry {
fn output<Reg: registry::Registry>(kind: &str) -> Option<OutputFactory<Reg>> {
return match kind {
"split" => Some(factory::<Config>()),
_ => return None,
};
}
}
}
4 changes: 2 additions & 2 deletions output-terminal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition.workspace = true
license.workspace = true

[features]
dynamic = ["dep:photonic-dynamic"]
dynamic = ["dep:photonic-dynamic", "dep:serde"]

[dependencies]
photonic = { workspace = true }
Expand All @@ -18,7 +18,7 @@ anyhow = { workspace = true }
tokio = { workspace = true, features = ["io-std", "net", "io-util"] }

nix = { version = "0.29", features = ["fs"] }
serde = { version = "1.0.197", features = ["derive"] }
serde = { version = "1.0.197", features = ["derive"], optional = true }

[lints]
workspace = true
9 changes: 0 additions & 9 deletions output-terminal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,6 @@ pub mod dynamic {
}
}

// pub fn output<B>(config: Config, _builder: &mut B) -> Result<Terminal>
// where B: OutputBuilder {
// return Ok(Terminal {
// size: config.size,
// path: config.path,
// waterfall: config.waterfall,
// });
// }

pub struct Registry;

impl registry::Registry for Registry {
Expand Down

0 comments on commit 13b6fe4

Please sign in to comment.