Skip to main content

guest_cli/platform/
fuchsia.rs

1// Copyright 2022 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use crate::platform::PlatformServices;
6use anyhow::{Context, Result};
7use async_trait::async_trait;
8use fidl_fuchsia_virtualization::{GuestManagerMarker, GuestManagerProxy};
9use fuchsia_component::client::connect_to_protocol_at_path;
10use guest_cli_args::GuestType;
11
12pub struct FuchsiaPlatformServices;
13
14impl FuchsiaPlatformServices {
15    pub fn new() -> Self {
16        Self
17    }
18}
19
20#[async_trait(?Send)]
21impl PlatformServices for FuchsiaPlatformServices {
22    async fn connect_to_manager(&self, guest_type: GuestType) -> Result<GuestManagerProxy> {
23        let manager = connect_to_protocol_at_path::<GuestManagerMarker>(
24            format!("/svc/{}", guest_type.guest_manager_interface()).as_str(),
25        )
26        .context("Failed to connect to manager service")?;
27        Ok(manager)
28    }
29}