sl4f_lib/time/
commands.rs1use crate::server::Facade;
6use anyhow::{bail, Error};
7use async_trait::async_trait;
8use serde_json::{to_value, Value};
9
10use crate::time::facade::TimeFacade;
11
12#[async_trait(?Send)]
13impl Facade for TimeFacade {
14 async fn handle_request(&self, method: String, _args: Value) -> Result<Value, Error> {
15 match method.as_str() {
16 "SystemTimeMillis" => {
17 let system_time = Self::system_time_millis()?;
18 Ok(to_value(system_time)?)
19 }
20 "UserspaceTimeMillis" => {
21 let userspace_time = Self::userspace_time_millis()?;
22 Ok(to_value(userspace_time)?)
23 }
24 "IsSynchronized" => {
25 let result = Self::is_synchronized().await?;
26 Ok(to_value(result)?)
27 }
28 _ => bail!("Unrecognized time facade method: {}", method),
29 }
30 }
31}