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
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2022 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 {
    crate::platform::PlatformServices,
    anyhow::{Context, Result},
    async_trait::async_trait,
    fidl_fuchsia_virtualization::{
        GuestManagerMarker, GuestManagerProxy, LinuxManagerMarker, LinuxManagerProxy,
    },
    fuchsia_component::client::{connect_to_protocol, connect_to_protocol_at_path},
    guest_cli_args::GuestType,
};

pub struct FuchsiaPlatformServices;

impl FuchsiaPlatformServices {
    pub fn new() -> Self {
        Self
    }
}

#[async_trait(?Send)]
impl PlatformServices for FuchsiaPlatformServices {
    async fn connect_to_manager(&self, guest_type: GuestType) -> Result<GuestManagerProxy> {
        let manager = connect_to_protocol_at_path::<GuestManagerMarker>(
            format!("/svc/{}", guest_type.guest_manager_interface()).as_str(),
        )
        .context("Failed to connect to manager service")?;
        Ok(manager)
    }

    async fn connect_to_linux_manager(&self) -> Result<LinuxManagerProxy> {
        connect_to_protocol::<LinuxManagerMarker>()
            .context("Failed to connect to linux manager service")
    }
}