sl4f_lib/location/
commands.rs1use crate::location::emergency_provider_facade::EmergencyProviderFacade;
6use crate::location::regulatory_region_facade::RegulatoryRegionFacade;
7use crate::location::types::PositionSerializer;
8use crate::server::Facade;
9use anyhow::{format_err, Error};
10use async_trait::async_trait;
11use serde_json::{to_value, Value};
12
13#[async_trait(?Send)]
14impl Facade for RegulatoryRegionFacade {
15 async fn handle_request(&self, method: String, args: Value) -> Result<Value, Error> {
16 match method.as_ref() {
17 "set_region" => {
18 let region =
19 args.get("region").ok_or_else(|| format_err!("Must provide a `region`"))?;
20 let region =
21 region.as_str().ok_or_else(|| format_err!("`region` must be a string"))?;
22 Ok(to_value(self.set_region(region)?)?)
23 }
24 _ => {
25 return Err(format_err!(
26 "unsupported command {} for regulatory-region-facade!",
27 method
28 ))
29 }
30 }
31 }
32}
33
34#[async_trait(?Send)]
35impl Facade for EmergencyProviderFacade {
36 async fn handle_request(&self, method: String, _args: Value) -> Result<Value, Error> {
37 match method.as_ref() {
38 "get_current" => Ok(to_value(PositionSerializer(self.get_current().await?))?),
39 _ => {
40 return Err(format_err!(
41 "unsupported command {} for emergency-provider-facade!",
42 method
43 ))
44 }
45 }
46 }
47}