Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cleaning up the unnecessary functions #708

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
10 changes: 1 addition & 9 deletions core/launcher/src/manager/app_launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,14 +540,6 @@ impl AppLauncher {
}
}

fn get_transport(contract_permited: bool, url: &str) -> AppRuntimeTransport {
if !url.contains("__firebolt_endpoint") && contract_permited {
AppRuntimeTransport::Bridge
} else {
AppRuntimeTransport::Websocket
}
}

pub async fn pre_launch(
state: &LauncherState,
manifest: AppManifest,
Expand All @@ -566,7 +558,7 @@ impl AppLauncher {
},
runtime: Some(AppRuntime {
id: Some(callsign),
transport: Self::get_transport(bool_contract, &manifest.start_page),
transport: AppRuntimeTransport::Websocket,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just get rid of the AppRuntimeTransport enum altogether since it's no longer needed, that will then let you also get rid of EffectiveTransport and even more code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clean up done.

}),
launch: AppLaunchInfo {
intent: Some(intent),
Expand Down
17 changes: 4 additions & 13 deletions core/main/src/broker/endpoint_broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,12 +976,8 @@ impl BrokerOutputForwarder {
.session_state
.get_session_for_connection_id(&session_id)
{
return_api_message_for_transport(
session,
message,
platform_state_c,
)
.await
return_api_message_for_transport(session, message)
.await
}
});
continue;
Expand Down Expand Up @@ -1105,12 +1101,7 @@ impl BrokerOutputForwarder {
.session_state
.get_session_for_connection_id(&session_id)
{
return_api_message_for_transport(
session,
message,
platform_state.clone(),
)
.await
return_api_message_for_transport(session, message).await
}
}
} else {
Expand Down Expand Up @@ -1159,7 +1150,7 @@ impl BrokerOutputForwarder {
.session_state
.get_session_for_connection_id(&session_id)
{
return_api_message_for_transport(session, message, platform_state.clone()).await;
return_api_message_for_transport(session, message).await;
}
}

Expand Down
8 changes: 0 additions & 8 deletions core/main/src/firebolt/firebolt_gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,14 +469,6 @@ async fn send_json_rpc_error(
)
}
}
EffectiveTransport::Bridge(id) => {
if let Err(e) = platform_state.send_to_bridge(id, api_message).await {
error!(
"send_json_rpc_error: Error sending bridge message: e={:?}",
e
)
}
}
}
} else {
error!("send_json_rpc_error: Could not serialize error message");
Expand Down
3 changes: 0 additions & 3 deletions core/main/src/firebolt/firebolt_ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,6 @@ impl FireboltWs {
ApiMessage::new(ApiProtocol::JsonRpc, msg, req_id.clone());
// No Stats here its an invalid RPC request
match session.get_transport() {
EffectiveTransport::Bridge(id) => {
let _ = state.send_to_bridge(id, api_msg).await;
}
EffectiveTransport::Websocket => {
let _ = session.send_json_rpc(api_msg).await;
}
Expand Down
3 changes: 2 additions & 1 deletion core/main/src/firebolt/rpc_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ impl RpcRouter {
let now = Utc::now().timestamp_millis();
let success = !msg.is_error();
TelemetryBuilder::send_fb_tt(&state, req.clone(), now - start, success, &msg);
return_api_message_for_transport(session, msg, state).await;

return_api_message_for_transport(session, msg).await;
}
});
}
Expand Down
21 changes: 4 additions & 17 deletions core/main/src/service/apps/app_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use ripple_sdk::{
apps::{AppEventRequest, EffectiveTransport},
firebolt::fb_general::ListenRequest,
gateway::rpc_gateway_api::{ApiMessage, CallContext},
protocol::BridgeProtocolRequest,
},
log::error,
serde_json::{json, Value},
Expand Down Expand Up @@ -262,7 +261,7 @@ impl AppEvents {
}
}

pub async fn send_event(state: &PlatformState, listener: &EventListener, data: &Value) {
pub async fn send_event(listener: &EventListener, data: &Value) {
let protocol = listener.call_ctx.protocol.clone();
let event = Response {
jsonrpc: TwoPointZero,
Expand All @@ -285,17 +284,6 @@ impl AppEvents {
error!("JsonRPC sender missing");
}
}
EffectiveTransport::Bridge(id) => {
if state.supports_bridge() {
let client = state.get_client();
let request = BridgeProtocolRequest::Send(id, api_message);
if let Err(e) = client.send_extn_request(request).await {
error!("Error sending event to bridge {:?}", e);
}
} else {
error!("Bridge not supported");
}
}
}
}

Expand Down Expand Up @@ -351,7 +339,6 @@ impl AppEvents {
}
if context.is_some() {
AppEvents::send_event(
state,
&i,
&json!({
"context": context.clone(),
Expand All @@ -360,7 +347,7 @@ impl AppEvents {
)
.await;
} else {
AppEvents::send_event(state, &i, &decorated_res.unwrap()).await;
AppEvents::send_event(&i, &decorated_res.unwrap()).await;
}
}

Expand All @@ -373,7 +360,7 @@ impl AppEvents {
event_ctx_string.clone(),
);
for i in listeners {
AppEvents::send_event(state, &i, result).await;
AppEvents::send_event(&i, result).await;
}
}
}
Expand All @@ -392,7 +379,7 @@ impl AppEvents {
for i in listeners_vec {
let decorated_res = i.decorate(state, event_name, result).await;
if let Ok(res) = decorated_res {
AppEvents::send_event(state, &i, &res).await;
AppEvents::send_event(&i, &res).await;
} else {
error!("could not generate event for '{}'", event_name);
}
Expand Down
69 changes: 6 additions & 63 deletions core/main/src/service/apps/delegated_launcher_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ use std::{

use ripple_sdk::{
api::{
apps::{
AppError, AppManagerResponse, AppMethod, AppSession, EffectiveTransport, StateChange,
},
apps::{AppError, AppManagerResponse, AppMethod, AppSession, StateChange},
device::{device_user_grants_data::EvaluateAt, entertainment_data::NavigationIntent},
firebolt::{
fb_capabilities::{DenyReason, DenyReasonWithCap, FireboltPermission},
Expand Down Expand Up @@ -66,7 +64,6 @@ use ripple_sdk::{
LCM_EVENT_ON_REQUEST_READY,
},
},
protocol::{BridgeProtocolRequest, BridgeSessionParams},
},
log::info,
tokio::{self, sync::mpsc::Receiver},
Expand All @@ -84,10 +81,8 @@ use crate::{
user_grants::{GrantHandler, GrantPolicyEnforcer, GrantState},
},
state::{
bootstrap_state::ChannelsState,
cap::permitted_state::PermissionHandler,
platform_state::PlatformState,
session_state::{PendingSessionInfo, Session},
bootstrap_state::ChannelsState, cap::permitted_state::PermissionHandler,
platform_state::PlatformState, session_state::PendingSessionInfo,
},
utils::rpc_utils::rpc_await_oneshot,
SEMVER_LIGHTWEIGHT,
Expand Down Expand Up @@ -622,14 +617,7 @@ impl DelegatedLauncherHandler {
&mut self,
mut session: AppSession,
) -> Result<AppManagerResponse, AppError> {
let transport = session.get_transport();
if let EffectiveTransport::Bridge(_) = transport.clone() {
if !self.platform_state.supports_bridge() {
error!("Bridge is not a supported contract");
return Err(AppError::NotSupported);
}
}

let _transport = session.get_transport();
let app_id = session.app.id.clone();

if let Some(app_title) = session.app.title.as_ref() {
Expand Down Expand Up @@ -881,40 +869,8 @@ impl DelegatedLauncherHandler {
emit_event: bool,
) -> CompletedSessionResponse {
let app_id = session.app.id.clone();
let transport = session.get_transport();
let _transport = session.get_transport();
let session_id = Uuid::new_v4().to_string();
if let EffectiveTransport::Bridge(container_id) = transport.clone() {
if platform_state.supports_bridge() {
// Step 1: Add the session of the app to the state if bridge
let session_state = Session::new(app_id.clone(), None, transport);
platform_state
.session_state
.add_session(session_id.clone(), session_state);
let id = container_id.clone();
debug!(
"App session details: appId: {} session: {}",
app_id, session_id
);
// Step 2: Start the session using contract
let request = BridgeSessionParams {
container_id,
session_id: session_id.clone(),
app_id: app_id.clone(),
};
let request = BridgeProtocolRequest::StartSession(request);
let client = platform_state.get_client();
// After processing the session response the launcher will launch the app
// Below thread is going to wait for the app to be launched and create a connection
tokio::spawn(async move {
if let Err(e) = client.send_extn_request(request).await {
error!("Error sending request to bridge {:?}", e);
} else {
info!("Bridge connected for {}", id);
}
});
}
}

let loaded_session_id = Uuid::new_v4().to_string();
let mut active_session_id = None;
if !session.launch.inactive {
Expand Down Expand Up @@ -1062,23 +1018,10 @@ impl DelegatedLauncherHandler {
async fn end_session(&mut self, app_id: &str) -> Result<AppManagerResponse, AppError> {
debug!("end_session: entry: app_id={}", app_id);
let app = self.platform_state.app_manager_state.remove(app_id);
if let Some(app) = app {
if let Some(_app) = app {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could just be if app.is_some() {.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if let Some(timer) = self.timer_map.remove(app_id) {
timer.cancel();
}
let transport = app.initial_session.get_transport();
if let EffectiveTransport::Bridge(container_id) = transport {
AppEvents::remove_session(&self.platform_state, app.session_id.clone());
let request = BridgeProtocolRequest::EndSession(container_id);
if let Err(e) = self
.platform_state
.get_client()
.send_extn_request(request)
.await
{
error!("Error sending event to bridge {:?}", e);
}
}
} else {
error!("end_session app_id={} Not found", app_id);
return Err(AppError::NotFound);
Expand Down
2 changes: 1 addition & 1 deletion core/main/src/state/cap/cap_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl CapState {
if let Ok(data) = serde_json::to_value(cap_info) {
debug!("data={:?}", data);
// Step 4: Send exclusive cap info data for each listener
AppEvents::send_event(ps, &listener, &data).await;
AppEvents::send_event(&listener, &data).await;
}
}
}
Expand Down
16 changes: 2 additions & 14 deletions core/main/src/state/platform_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,20 @@

use ripple_sdk::{
api::{
gateway::rpc_gateway_api::{ApiMessage, RpcRequest},
gateway::rpc_gateway_api::RpcRequest,
manifest::{
app_library::AppLibraryState,
device_manifest::{AppLibraryEntry, DeviceManifest},
exclusory::ExclusoryImpl,
extn_manifest::ExtnManifest,
},
protocol::BridgeProtocolRequest,
session::SessionAdjective,
},
extn::{
extn_client_message::{ExtnMessage, ExtnPayloadProvider},
extn_id::ExtnId,
},
framework::{ripple_contract::RippleContract, RippleResponse},
framework::ripple_contract::RippleContract,
utils::error::RippleError,
uuid::Uuid,
};
Expand Down Expand Up @@ -184,11 +183,6 @@ impl PlatformState {
self.get_client().respond(msg).await
}

pub fn supports_bridge(&self) -> bool {
let contract = RippleContract::BridgeProtocol.as_clear_string();
self.extn_manifest.required_contracts.contains(&contract)
}

pub fn supports_cloud_sync(&self) -> bool {
let contract = RippleContract::CloudSync.as_clear_string();
self.extn_manifest.required_contracts.contains(&contract)
Expand All @@ -209,12 +203,6 @@ impl PlatformState {
self.extn_manifest.required_contracts.contains(&contract)
}

pub async fn send_to_bridge(&self, id: String, msg: ApiMessage) -> RippleResponse {
let request = BridgeProtocolRequest::Send(id, msg);
self.get_client().send_extn_request(request).await?;
Ok(())
}

pub fn supports_device_tokens(&self) -> bool {
let contract = RippleContract::Session(SessionAdjective::Device).as_clear_string();
self.extn_manifest.required_contracts.contains(&contract)
Expand Down
15 changes: 2 additions & 13 deletions core/main/src/utils/router_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,15 @@ use ripple_sdk::{
utils::error::RippleError,
};

use crate::state::{
metrics_state::MetricsState, platform_state::PlatformState, session_state::Session,
};
use crate::state::{metrics_state::MetricsState, session_state::Session};

pub async fn return_api_message_for_transport(
session: Session,
msg: ApiMessage,
state: PlatformState,
) {
pub async fn return_api_message_for_transport(session: Session, msg: ApiMessage) {
match session.get_transport() {
EffectiveTransport::Websocket => {
if let Err(e) = session.send_json_rpc(msg).await {
error!("Error while responding back message {:?}", e)
}
}
EffectiveTransport::Bridge(container_id) => {
if let Err(e) = state.send_to_bridge(container_id, msg).await {
error!("Error sending event to bridge {:?}", e);
}
}
}
}

Expand Down
Loading
Loading