sl4f_lib/location/
emergency_provider_facade.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use anyhow::{Context, Error};
use fidl_fuchsia_location_position::{EmergencyProviderMarker, EmergencyProviderProxy, Position};
use fuchsia_component::client::connect_to_protocol;

#[derive(Debug)]
pub struct EmergencyProviderFacade {
    provider: EmergencyProviderProxy,
}

impl EmergencyProviderFacade {
    pub fn new() -> Result<EmergencyProviderFacade, Error> {
        Ok(EmergencyProviderFacade { provider: connect_to_protocol::<EmergencyProviderMarker>()? })
    }

    /// Queries the current `Position`.
    pub async fn get_current(&self) -> Result<Position, Error> {
        self.provider
            .get_current()
            .await
            .context("fidl error")?
            .map_err(|e| format_err!("service error: {:?}", e))
    }
}