Skip to main content

ember_plus/server/
handler.rs

1//! Server event handlers.
2
3use std::sync::Arc;
4use crate::error::Result;
5use crate::glow::{EmberPath, GlowConnection, InvocationResult, EmberValue};
6
7/// Handler for setValue operations.
8pub type SetValueHandler = Arc<dyn Fn(&EmberPath, &EmberValue) -> Result<bool> + Send + Sync>;
9
10/// Handler for function invocations.
11pub type InvokeHandler = Arc<dyn Fn(&EmberPath, i32, &[EmberValue]) -> Result<InvocationResult> + Send + Sync>;
12
13/// Handler for matrix operations.
14pub type MatrixHandler = Arc<dyn Fn(&EmberPath, &GlowConnection) -> Result<()> + Send + Sync>;
15
16/// Default handler that accepts all setValue operations.
17pub fn default_set_value_handler() -> SetValueHandler {
18    Arc::new(|_path, _value| Ok(true))
19}
20
21/// Default handler that returns success for all invocations.
22pub fn default_invoke_handler() -> InvokeHandler {
23    Arc::new(|_path, invocation_id, _args| {
24        Ok(InvocationResult::success(invocation_id, vec![]))
25    })
26}
27
28/// Default handler for matrix operations.
29pub fn default_matrix_handler() -> MatrixHandler {
30    Arc::new(|_path, _connection| Ok(()))
31}