1818use std:: time:: Duration ;
1919
2020use crate :: {
21- firebolt :: handlers :: privacy_rpc :: PrivacyImpl ,
22- firebolt:: rpc:: RippleRPCProvider ,
21+ broker :: broker_utils :: BrokerUtils ,
22+ firebolt:: { handlers :: privacy_rpc :: PrivacyImpl , rpc:: RippleRPCProvider } ,
2323 service:: apps:: {
2424 app_events:: { AppEventDecorationError , AppEventDecorator , AppEvents } ,
2525 provider_broker:: { self , ProviderBroker } ,
@@ -34,7 +34,7 @@ use jsonrpsee::{
3434
3535use ripple_sdk:: {
3636 api:: {
37- apps:: { AppError , AppManagerResponse , AppMethod , AppRequest , AppResponse } ,
37+ apps:: { AppError , AppManagerResponse , AppMethod , AppRequest } ,
3838 firebolt:: {
3939 fb_capabilities:: FireboltCap ,
4040 fb_discovery:: {
@@ -45,7 +45,7 @@ use ripple_sdk::{
4545 provider:: { ProviderRequestPayload , ProviderResponse , ProviderResponsePayload } ,
4646 } ,
4747 } ,
48- log:: { error, info} ,
48+ log:: { debug , error, info} ,
4949 tokio:: { sync:: oneshot, time:: timeout} ,
5050} ;
5151use ripple_sdk:: {
@@ -251,7 +251,7 @@ impl DiscoveryServer for DiscoveryImpl {
251251 DiscoveryImpl :: get_content_policy ( & ctx, & self . state , & ctx. app_id ) . await
252252 }
253253
254- async fn launch ( & self , ctx : CallContext , request : LaunchRequest ) -> RpcResult < bool > {
254+ async fn launch ( & self , _ctx : CallContext , request : LaunchRequest ) -> RpcResult < bool > {
255255 let app_defaults_configuration = self . state . get_device_manifest ( ) . applications . defaults ;
256256
257257 let intent_validation_config = self
@@ -261,8 +261,6 @@ impl DiscoveryServer for DiscoveryImpl {
261261 . intent_validation ;
262262 validate_navigation_intent ( intent_validation_config, request. intent . clone ( ) ) . await ?;
263263
264- let req_updated_source = update_intent_source ( ctx. app_id . clone ( ) , request. clone ( ) ) ;
265-
266264 if let Some ( reserved_app_id) =
267265 app_defaults_configuration. get_reserved_application_id ( & request. app_id )
268266 {
@@ -276,45 +274,25 @@ impl DiscoveryServer for DiscoveryImpl {
276274 ) ) ;
277275 }
278276
279- // Not validating the intent, pass-through to app as is.
280- if !AppEvents :: is_app_registered_for_event (
281- & self . state ,
282- reserved_app_id. to_string ( ) ,
283- DISCOVERY_EVENT_ON_NAVIGATE_TO ,
284- ) {
285- return Err ( rpc_navigate_reserved_app_err (
286- format ! ( "Discovery.launch: reserved app id {} is not registered for discovery.onNavigateTo event" ,
287- reserved_app_id) . as_str ( ) ,
288- ) ) ;
289- }
290- // emit EVENT_ON_NAVIGATE_TO to the reserved app.
291- AppEvents :: emit_to_app (
292- & self . state ,
293- reserved_app_id. to_string ( ) ,
294- DISCOVERY_EVENT_ON_NAVIGATE_TO ,
295- & serde_json:: to_value ( req_updated_source. intent ) . unwrap ( ) ,
277+ match BrokerUtils :: process_internal_main_request (
278+ & self . state . clone ( ) ,
279+ "discovery.launch.internal" ,
280+ Some ( serde_json:: to_value ( request) . map_err ( |e| {
281+ error ! ( "Serialization error: {:?}" , e) ;
282+ rpc_err ( "Failed to serialize LaunchIntent" )
283+ } ) ?) ,
296284 )
297- . await ;
298- info ! (
299- "emit_to_app called for app {} event {}" ,
300- reserved_app_id. to_string( ) ,
301- DISCOVERY_EVENT_ON_NAVIGATE_TO
302- ) ;
303- return Ok ( true ) ;
304- }
305- let ( app_resp_tx, app_resp_rx) = oneshot:: channel :: < AppResponse > ( ) ;
306-
307- let app_request =
308- AppRequest :: new ( AppMethod :: Launch ( req_updated_source. clone ( ) ) , app_resp_tx) ;
309-
310- if self
311- . state
312- . get_client ( )
313- . send_app_request ( app_request)
314- . is_ok ( )
315- && app_resp_rx. await . is_ok ( )
316- {
317- return Ok ( true ) ;
285+ . await
286+ {
287+ Ok ( val) => {
288+ debug ! ( "Internal subscription launch successful" ) ;
289+ return Ok ( val. as_bool ( ) . unwrap_or ( false ) ) ;
290+ }
291+ Err ( e) => {
292+ error ! ( "Internal subscription launch failed: {:?}" , e) ;
293+ return Err ( rpc_err ( "Internal subscription launch failed" ) ) ;
294+ }
295+ }
318296 }
319297
320298 Err ( jsonrpsee:: core:: Error :: Custom ( String :: from (
@@ -493,70 +471,70 @@ impl DiscoveryServer for DiscoveryImpl {
493471 Ok ( true )
494472 }
495473}
496- fn update_intent_source ( source_app_id : String , request : LaunchRequest ) -> LaunchRequest {
497- let source = format ! ( "xrn:firebolt:application:{}" , source_app_id) ;
498- match request. intent . clone ( ) {
499- Some ( NavigationIntent :: NavigationIntentStrict ( navigation_intent) ) => {
500- let updated_navigation_intent = match navigation_intent {
501- NavigationIntentStrict :: Home ( mut home_intent) => {
502- home_intent. context . source = source;
503- NavigationIntentStrict :: Home ( home_intent)
504- }
505- NavigationIntentStrict :: Launch ( mut launch_intent) => {
506- launch_intent. context . source = source;
507- NavigationIntentStrict :: Launch ( launch_intent)
508- }
509- NavigationIntentStrict :: Entity ( mut entity_intent) => {
510- entity_intent. context . source = source;
511- NavigationIntentStrict :: Entity ( entity_intent)
512- }
513- NavigationIntentStrict :: Playback ( mut playback_intent) => {
514- playback_intent. context . source = source;
515- NavigationIntentStrict :: Playback ( playback_intent)
516- }
517- NavigationIntentStrict :: Search ( mut search_intent) => {
518- search_intent. context . source = source;
519- NavigationIntentStrict :: Search ( search_intent)
520- }
521- NavigationIntentStrict :: Section ( mut section_intent) => {
522- section_intent. context . source = source;
523- NavigationIntentStrict :: Section ( section_intent)
524- }
525- NavigationIntentStrict :: Tune ( mut tune_intent) => {
526- tune_intent. context . source = source;
527- NavigationIntentStrict :: Tune ( tune_intent)
528- }
529- NavigationIntentStrict :: ProviderRequest ( mut provider_request_intent) => {
530- provider_request_intent. context . source = source;
531- NavigationIntentStrict :: ProviderRequest ( provider_request_intent)
532- }
533- NavigationIntentStrict :: PlayEntity ( mut p) => {
534- p. context . source = source;
535- NavigationIntentStrict :: PlayEntity ( p)
536- }
537- NavigationIntentStrict :: PlayQuery ( mut p) => {
538- p. context . source = source;
539- NavigationIntentStrict :: PlayQuery ( p)
540- }
541- } ;
542-
543- LaunchRequest {
544- app_id : request. app_id ,
545- intent : Some ( NavigationIntent :: NavigationIntentStrict (
546- updated_navigation_intent,
547- ) ) ,
548- }
549- }
550- Some ( NavigationIntent :: NavigationIntentLoose ( mut loose_intent) ) => {
551- loose_intent. context . source = source;
552- LaunchRequest {
553- app_id : request. app_id ,
554- intent : Some ( NavigationIntent :: NavigationIntentLoose ( loose_intent) ) ,
555- }
556- }
557- _ => request,
558- }
559- }
474+ // fn update_intent_source(source_app_id: String, request: LaunchRequest) -> LaunchRequest {
475+ // let source = format!("xrn:firebolt:application:{}", source_app_id);
476+ // match request.intent.clone() {
477+ // Some(NavigationIntent::NavigationIntentStrict(navigation_intent)) => {
478+ // let updated_navigation_intent = match navigation_intent {
479+ // NavigationIntentStrict::Home(mut home_intent) => {
480+ // home_intent.context.source = source;
481+ // NavigationIntentStrict::Home(home_intent)
482+ // }
483+ // NavigationIntentStrict::Launch(mut launch_intent) => {
484+ // launch_intent.context.source = source;
485+ // NavigationIntentStrict::Launch(launch_intent)
486+ // }
487+ // NavigationIntentStrict::Entity(mut entity_intent) => {
488+ // entity_intent.context.source = source;
489+ // NavigationIntentStrict::Entity(entity_intent)
490+ // }
491+ // NavigationIntentStrict::Playback(mut playback_intent) => {
492+ // playback_intent.context.source = source;
493+ // NavigationIntentStrict::Playback(playback_intent)
494+ // }
495+ // NavigationIntentStrict::Search(mut search_intent) => {
496+ // search_intent.context.source = source;
497+ // NavigationIntentStrict::Search(search_intent)
498+ // }
499+ // NavigationIntentStrict::Section(mut section_intent) => {
500+ // section_intent.context.source = source;
501+ // NavigationIntentStrict::Section(section_intent)
502+ // }
503+ // NavigationIntentStrict::Tune(mut tune_intent) => {
504+ // tune_intent.context.source = source;
505+ // NavigationIntentStrict::Tune(tune_intent)
506+ // }
507+ // NavigationIntentStrict::ProviderRequest(mut provider_request_intent) => {
508+ // provider_request_intent.context.source = source;
509+ // NavigationIntentStrict::ProviderRequest(provider_request_intent)
510+ // }
511+ // NavigationIntentStrict::PlayEntity(mut p) => {
512+ // p.context.source = source;
513+ // NavigationIntentStrict::PlayEntity(p)
514+ // }
515+ // NavigationIntentStrict::PlayQuery(mut p) => {
516+ // p.context.source = source;
517+ // NavigationIntentStrict::PlayQuery(p)
518+ // }
519+ // };
520+
521+ // LaunchRequest {
522+ // app_id: request.app_id,
523+ // intent: Some(NavigationIntent::NavigationIntentStrict(
524+ // updated_navigation_intent,
525+ // )),
526+ // }
527+ // }
528+ // Some(NavigationIntent::NavigationIntentLoose(mut loose_intent)) => {
529+ // loose_intent.context.source = source;
530+ // LaunchRequest {
531+ // app_id: request.app_id,
532+ // intent: Some(NavigationIntent::NavigationIntentLoose(loose_intent)),
533+ // }
534+ // }
535+ // _ => request,
536+ // }
537+ // }
560538
561539pub async fn validate_navigation_intent (
562540 intent_validation_config : IntentValidation ,
0 commit comments