/// Facade to launch mod from Sl4f
/// # Arguments
/// * `args`: will be parsed to LaunchModRequest
/// * `mod_url`: url of the mod
/// * `mod_name`: same as mod_url if nothing is passed in
/// * `story_name`: same as mod_url if nothing is passed in
Facade to launch mod from Sl4f
Facade to launch mod from Sl4f
pub async fn launch_mod(&self, args: Value) -> Result<BasemgrResult, Error> {
        let req: LaunchModRequest = from_value(args)?;
        // Building the component url from the name of component.
        let mod_url = match req.mod_url {
            Some(x) => {
                let url = match x.find(":") {
                    Some(_y) => x.to_string(),
                    None => format!("fuchsia-pkg://fuchsia.com/{}#meta/{}.cmx", x, x).to_string(),
                };
                fx_log_info!("Launching mod {} in Basemgr Facade.", url);
                url
            }
            None => return Err(format_err!("Missing MOD_URL to launch")),
        };
        let mod_name = match req.mod_name {
            Some(x) => x.to_string(),
            None => {
                fx_log_info!("No mod_name specified, using auto-generated mod_name: {}", &mod_url);
                mod_url.clone()
            }
        };
        let story_name = match req.story_name {
            Some(x) => x.to_string(),
            None => {
                fx_log_info!(
                    "No story_name specified, using auto-generated story_name: {}",
                    &mod_url
                );
                mod_url.clone()
            }
        };
        let mut intent = Intent { action: None, handler: None, parameters: None };
        intent.handler = Some(mod_url.clone());
        let mut commands = vec![];
        //set it to default value of surface relation
        let sur_rel = SurfaceRelation {
            dependency: SurfaceDependency::None,
            arrangement: SurfaceArrangement::None,
            emphasis: 1.0,
        };
        let add_mod = AddMod {
            intent: intent,
            mod_name_transitional: Some(mod_name.clone()),
            mod_name: vec![mod_name.clone()],
            surface_parent_mod_name: None,
            surface_relation: sur_rel,
        };
        commands.push(StoryCommand::AddMod(add_mod));
        let mut puppet_master = match self.discover_puppet_master()? {
            Some(proxy) => proxy,
            None => return Err(format_err!("Unable to connect to Puppet Master Service")),
        };
        let (proxy, server) = fidl::endpoints::create_proxy::<StoryPuppetMasterMarker>()?;
        puppet_master.control_story(story_name.as_str(), server)?;
        // Chunk the command list into fixed size chunks and cast it to iterator to
        // meet fidl's specification
        for chunk in commands.chunks_mut(CHUNK_SIZE).into_iter() {
            proxy.enqueue(&mut chunk.into_iter()).expect("Session failed to enqueue commands");
        }
        proxy.execute().await?;
        Ok(BasemgrResult::Success)
    }
pub async fn launch_mod ( & self , args : Value ) -> Result < BasemgrResult , Error > { let req : LaunchModRequest = from_value ( args ) ? ; // Building the component url from the name of component. let mod_url = match req . mod_url { Some ( x ) => { let url = match x . find ( " " ) { Some ( _y ) => x . to_string ( ) , None => format ! ( " " x x ) . to_string ( ) , } ; fx_log_info ! ( " " url ) ; url } None => return Err ( format_err ! ( " " ) ) , } ; let mod_name = match req . mod_name { Some ( x ) => x . to_string ( ) , None => { fx_log_info ! ( " " mod_url ) ; mod_url . clone ( ) } } ; let story_name = match req . story_name { Some ( x ) => x . to_string ( ) , None => { fx_log_info ! ( " " mod_url ) ; mod_url . clone ( ) } } ; let mut intent = Intent { action : None , handler : None , parameters : None } ; intent . handler = Some ( mod_url . clone ( ) ) ; let mut commands = vec ! [ ] ; //set it to default value of surface relation let sur_rel = SurfaceRelation { dependency : SurfaceDependency :: None , arrangement : SurfaceArrangement :: None , emphasis : 1.0 , } ; let add_mod = AddMod { intent : intent , mod_name_transitional : Some ( mod_name . clone ( ) ) , mod_name : vec ! [ mod_name clone ( ) ] , surface_parent_mod_name : None , surface_relation : sur_rel , } ; commands . push ( StoryCommand :: AddMod ( add_mod ) ) ; let mut puppet_master = match self . discover_puppet_master ( ) ? { Some ( proxy ) => proxy , None => return Err ( format_err ! ( " " ) ) , } ; let ( proxy , server ) = fidl :: endpoints :: create_proxy :: < StoryPuppetMasterMarker > ( ) ? ; puppet_master . control_story ( story_name . as_str ( ) , server ) ? ; // Chunk the command list into fixed size chunks and cast it to iterator to // meet fidl's specification for chunk in commands . chunks_mut ( CHUNK_SIZE ) . into_iter ( ) { proxy . enqueue ( & mut chunk . into_iter ( ) ) . expect ( " " ) ; } proxy . execute ( ) . await ? ; Ok ( BasemgrResult :: Success ) }
Facade to launch mod from Sl4f
Facade to launch mod from Sl4f
&self
args
Value