pub async fn add_adapter(self, host_path: &Path) -> Result<(), Error> {
        let node = self
            .state
            .read()
            .inspect
            .hosts()
            .create_child(format!("device {}", host_path.display()));
        let host_dev = bt::util::open_rdwr(host_path)?;
        let device_topo = fdio::device_get_topo_path(&host_dev)?;
        fx_log_info!("Adding Adapter: {:?} (topology: {:?})", host_path, device_topo);
        let host_device = init_host(host_path, node).await?;

        // TODO(armansito): Make sure that the bt-host device is left in a well-known state if any
        // of these operations fails.

        // TODO(PKG-47): The following code applies a number of configurations to the bt-host by
        // default. We should tie these to a package configuration (once it is possible), as some of these
        // are undesirable in certain situations, e.g when running PTS tests.
        //
        // Currently applied settings:
        //   - LE Privacy with IRK
        //   - LE background scan for auto-connection
        //   - BR/EDR connectable mode

        let address = host_device.read().get_info().address.clone();
        assign_host_data(host_device.clone(), self.clone(), &address).await?;
        try_restore_bonds(host_device.clone(), self.clone(), &address)
            .await
            .map_err(|e| e.as_failure())?;

        // Assign the name that is currently assigned to the HostDispatcher as the local name.
        host_device
            .read()
            .set_name(self.state.read().name.clone())
            .await
            .map_err(|e| e.as_failure())?;

        let (gatt_server_proxy, remote_gatt_server) = fidl::endpoints::create_proxy()?;
        host_device.read().get_host().request_gatt_server_(remote_gatt_server)?;
        self.spawn_gas_proxy(gatt_server_proxy).await?;

        // Enable privacy by default.
        host_device.read().enable_privacy(true).map_err(|e| e.as_failure())?;

        // TODO(845): Only the active host should be made connectable and scanning in the background.
        host_device
            .read()
            .set_connectable(true)
            .await
            .map_err(|_| err_msg("failed to set connectable"))?;
        host_device
            .read()
            .enable_background_scan(true)
            .map_err(|_| err_msg("failed to enable background scan"))?;

        // Initialize bt-gap as this host's pairing delegate.
        start_pairing_delegate(self.clone(), host_device.clone())?;

        // TODO(fxb/36378): Remove conversions to String when fuchsia.bluetooth.sys is supported.
        let id = host_device.read().get_info().id.value.to_string();
        self.state.write().add_host(id, host_device.clone());

        // Start listening to Host interface events.
        fasync::spawn(host_device::watch_events(self.clone(), host_device.clone()).map(|r| {
            r.unwrap_or_else(|err| {
                fx_log_warn!("Error handling host event: {:?}", err);
            })
        }));

        Ok(())
    }
/// Adds an adapter to the host dispatcher. Called by the watch_hosts device
/// watcher
Adds an adapter to the host dispatcher. Called by the watch_hosts device
watcher
Adds an adapter to the host dispatcher . Called by the watch_hosts device watcher
pub async fn add_adapter(self, host_path: &Path) -> Result<(), Error> {
        let node = self
            .state
            .read()
            .inspect
            .hosts()
            .create_child(format!("device {}", host_path.display()));
        let host_dev = bt::util::open_rdwr(host_path)?;
        let device_topo = fdio::device_get_topo_path(&host_dev)?;
        fx_log_info!("Adding Adapter: {:?} (topology: {:?})", host_path, device_topo);
        let host_device = init_host(host_path, node).await?;
        // TODO(armansito): Make sure that the bt-host device is left in a well-known state if any
        // of these operations fails.
        // TODO(PKG-47): The following code applies a number of configurations to the bt-host by
        // default. We should tie these to a package configuration (once it is possible), as some of these
        // are undesirable in certain situations, e.g when running PTS tests.
        //
        // Currently applied settings:
        //   - LE Privacy with IRK
        //   - LE background scan for auto-connection
        //   - BR/EDR connectable mode
        let address = host_device.read().get_info().address.clone();
        assign_host_data(host_device.clone(), self.clone(), &address).await?;
        try_restore_bonds(host_device.clone(), self.clone(), &address)
            .await
            .map_err(|e| e.as_failure())?;
        // Assign the name that is currently assigned to the HostDispatcher as the local name.
        host_device
            .read()
            .set_name(self.state.read().name.clone())
            .await
            .map_err(|e| e.as_failure())?;
        let (gatt_server_proxy, remote_gatt_server) = fidl::endpoints::create_proxy()?;
        host_device.read().get_host().request_gatt_server_(remote_gatt_server)?;
        self.spawn_gas_proxy(gatt_server_proxy).await?;
        // Enable privacy by default.
        host_device.read().enable_privacy(true).map_err(|e| e.as_failure())?;
        // TODO(845): Only the active host should be made connectable and scanning in the background.
        host_device
            .read()
            .set_connectable(true)
            .await
            .map_err(|_| err_msg("failed to set connectable"))?;
        host_device
            .read()
            .enable_background_scan(true)
            .map_err(|_| err_msg("failed to enable background scan"))?;
        // Initialize bt-gap as this host's pairing delegate.
        start_pairing_delegate(self.clone(), host_device.clone())?;
        // TODO(fxb/36378): Remove conversions to String when fuchsia.bluetooth.sys is supported.
        let id = host_device.read().get_info().id.value.to_string();
        self.state.write().add_host(id, host_device.clone());
        // Start listening to Host interface events.
        fasync::spawn(host_device::watch_events(self.clone(), host_device.clone()).map(|r| {
            r.unwrap_or_else(|err| {
                fx_log_warn!("Error handling host event: {:?}", err);
            })
        }));
        Ok(())
    }
pub async fn add_adapter ( self , host_path : & Path ) -> Result < ( ) , Error > { let node = self . state . read ( ) . inspect . hosts ( ) . create_child ( format ! ( " " host_path display ( ) ) ) ; let host_dev = bt :: util :: open_rdwr ( host_path ) ? ; let device_topo = fdio :: device_get_topo_path ( & host_dev ) ? ; fx_log_info ! ( " " host_path device_topo ) ; let host_device = init_host ( host_path , node ) . await ? ; // TODO(armansito): Make sure that the bt-host device is left in a well-known state if any // of these operations fails. // TODO(PKG-47): The following code applies a number of configurations to the bt-host by // default. We should tie these to a package configuration (once it is possible), as some of these // are undesirable in certain situations, e.g when running PTS tests. // // Currently applied settings: //   - LE Privacy with IRK //   - LE background scan for auto-connection //   - BR/EDR connectable mode let address = host_device . read ( ) . get_info ( ) . address . clone ( ) ; assign_host_data ( host_device . clone ( ) , self . clone ( ) , & address ) . await ? ; try_restore_bonds ( host_device . clone ( ) , self . clone ( ) , & address ) . await . map_err ( | e | e . as_failure ( ) ) ? ; // Assign the name that is currently assigned to the HostDispatcher as the local name. host_device . read ( ) . set_name ( self . state . read ( ) . name . clone ( ) ) . await . map_err ( | e | e . as_failure ( ) ) ? ; let ( gatt_server_proxy , remote_gatt_server ) = fidl :: endpoints :: create_proxy ( ) ? ; host_device . read ( ) . get_host ( ) . request_gatt_server_ ( remote_gatt_server ) ? ; self . spawn_gas_proxy ( gatt_server_proxy ) . await ? ; // Enable privacy by default. host_device . read ( ) . enable_privacy ( true ) . map_err ( | e | e . as_failure ( ) ) ? ; // TODO(845): Only the active host should be made connectable and scanning in the background. host_device . read ( ) . set_connectable ( true ) . await . map_err ( | _ | err_msg ( " " ) ) ? ; host_device . read ( ) . enable_background_scan ( true ) . map_err ( | _ | err_msg ( " " ) ) ? ; // Initialize bt-gap as this host's pairing delegate. start_pairing_delegate ( self . clone ( ) , host_device . clone ( ) ) ? ; // TODO(fxb/36378): Remove conversions to String when fuchsia.bluetooth.sys is supported. let id = host_device . read ( ) . get_info ( ) . id . value . to_string ( ) ; self . state . write ( ) . add_host ( id , host_device . clone ( ) ) ; // Start listening to Host interface events. fasync :: spawn ( host_device :: watch_events ( self . clone ( ) , host_device . clone ( ) ) . map ( | r | { r . unwrap_or_else ( | err | { fx_log_warn ! ( " " err ) ; } ) } ) ) ; Ok ( ( ) ) }
Adds an adapter to the host dispatcher.
Adds an adapter to the host dispatcher .
self
host_path
&Path