pub async fn open_capability_at_source(
    model: &Model,
    flags: u32,
    open_mode: u32,
    relative_path: String,
    source: CapabilitySource,
    target_moniker: AbsoluteMoniker,
    server_chan: zx::Channel,
) -> Result<(), ModelError> {
    let capability_provider = Arc::new(Mutex::new(get_default_provider(model, &source)));
    let target_realm = model.look_up_realm(&target_moniker).await?;

    let event = Event::new(
        target_realm.abs_moniker.clone(),
        EventPayload::RouteCapability {
            source: source.clone(),
            capability_provider: capability_provider.clone(),
        },
    );

    // This hack changes the flags for a scoped framework service
    let mut flags = flags;
    if let CapabilitySource::Framework { scope_moniker: Some(_), .. } = source {
        flags = SERVICE_OPEN_FLAGS;
    }

    // Get a capability provider from the tree
    target_realm.hooks.dispatch(&event).await?;
    let capability_provider = capability_provider.lock().await.take();

    // If a hook in the component tree gave a capability provider, then use it.
    if let Some(capability_provider) = capability_provider {
        capability_provider.open(flags, open_mode, relative_path, server_chan).await?;
        Ok(())
    } else if let Some(path) = get_framework_capability_path(&source) {
        // TODO(fsamuel): This is a temporary hack. If a global path-based framework capability
        // is not provided by a hook in the component tree, then attempt to connect to the service
        // in component manager's namespace. We could have modeled this as a default provider,
        // but several hooks (such as WorkScheduler) require that a provider is not set.
        io_util::connect_in_namespace(&path.to_string(), server_chan, flags)
            .map_err(|e| ModelError::capability_discovery_error(e))
    } else {
        Err(ModelError::capability_discovery_error(format_err!(
            "No providers for this capability were found!"
        )))
    }
}
/// Open the capability at the given source, binding to its component instance if necessary.
Open the capability at the given source, binding to its component instance if necessary.
Open the capability at the given source binding to its component instance if necessary .
pub async fn open_capability_at_source(
    model: &Model,
    flags: u32,
    open_mode: u32,
    relative_path: String,
    source: CapabilitySource,
    target_moniker: AbsoluteMoniker,
    server_chan: zx::Channel,
) -> Result<(), ModelError> {
    let capability_provider = Arc::new(Mutex::new(get_default_provider(model, &source)));
    let target_realm = model.look_up_realm(&target_moniker).await?;
    let event = Event::new(
        target_realm.abs_moniker.clone(),
        EventPayload::RouteCapability {
            source: source.clone(),
            capability_provider: capability_provider.clone(),
        },
    );
    // This hack changes the flags for a scoped framework service
    let mut flags = flags;
    if let CapabilitySource::Framework { scope_moniker: Some(_), .. } = source {
        flags = SERVICE_OPEN_FLAGS;
    }
    // Get a capability provider from the tree
    target_realm.hooks.dispatch(&event).await?;
    let capability_provider = capability_provider.lock().await.take();
    // If a hook in the component tree gave a capability provider, then use it.
    if let Some(capability_provider) = capability_provider {
        capability_provider.open(flags, open_mode, relative_path, server_chan).await?;
        Ok(())
    } else if let Some(path) = get_framework_capability_path(&source) {
        // TODO(fsamuel): This is a temporary hack. If a global path-based framework capability
        // is not provided by a hook in the component tree, then attempt to connect to the service
        // in component manager's namespace. We could have modeled this as a default provider,
        // but several hooks (such as WorkScheduler) require that a provider is not set.
        io_util::connect_in_namespace(&path.to_string(), server_chan, flags)
            .map_err(|e| ModelError::capability_discovery_error(e))
    } else {
        Err(ModelError::capability_discovery_error(format_err!(
            "No providers for this capability were found!"
        )))
    }
}
pub async fn open_capability_at_source ( model : & Model , flags : u32 , open_mode : u32 , relative_path : String , source : CapabilitySource , target_moniker : AbsoluteMoniker , server_chan : zx :: Channel , ) -> Result < ( ) , ModelError > { let capability_provider = Arc :: new ( Mutex :: new ( get_default_provider ( model , & source ) ) ) ; let target_realm = model . look_up_realm ( & target_moniker ) . await ? ; let event = Event :: new ( target_realm . abs_moniker . clone ( ) , EventPayload :: RouteCapability { source : source . clone ( ) , capability_provider : capability_provider . clone ( ) , } , ) ; // This hack changes the flags for a scoped framework service let mut flags = flags ; if let CapabilitySource :: Framework { scope_moniker : Some ( _ ) , .. } = source { flags = SERVICE_OPEN_FLAGS ; } // Get a capability provider from the tree target_realm . hooks . dispatch ( & event ) . await ? ; let capability_provider = capability_provider . lock ( ) . await . take ( ) ; // If a hook in the component tree gave a capability provider, then use it. if let Some ( capability_provider ) = capability_provider { capability_provider . open ( flags , open_mode , relative_path , server_chan ) . await ? ; Ok ( ( ) ) } else if let Some ( path ) = get_framework_capability_path ( & source ) { // TODO(fsamuel): This is a temporary hack. If a global path-based framework capability // is not provided by a hook in the component tree, then attempt to connect to the service // in component manager's namespace. We could have modeled this as a default provider, // but several hooks (such as WorkScheduler) require that a provider is not set. io_util :: connect_in_namespace ( & path . to_string ( ) , server_chan , flags ) . map_err ( | e | ModelError :: capability_discovery_error ( e ) ) } else { Err ( ModelError :: capability_discovery_error ( format_err ! ( " " ) ) ) } }
Open the capability at the given source, binding to its component instance if necessary.
Open the capability at the given source binding to its component instance if necessary .
model
&Model
flags
u32
open_mode
u32
relative_path
String
source
CapabilitySource
target_moniker
AbsoluteMoniker
server_chan
zx::Channel