1cc290419Sopenharmony_ci/* 2cc290419Sopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd. 3cc290419Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4cc290419Sopenharmony_ci * you may not use this file except in compliance with the License. 5cc290419Sopenharmony_ci * You may obtain a copy of the License at 6cc290419Sopenharmony_ci * 7cc290419Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8cc290419Sopenharmony_ci * 9cc290419Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10cc290419Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11cc290419Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12cc290419Sopenharmony_ci * See the License for the specific language governing permissions and 13cc290419Sopenharmony_ci * limitations under the License. 14cc290419Sopenharmony_ci */ 15cc290419Sopenharmony_ci//! shell 16cc290419Sopenharmony_ci 17cc290419Sopenharmony_ci#[allow(unused_imports)] 18cc290419Sopenharmony_ciuse crate::daemon_lib::daemon_app; 19cc290419Sopenharmony_ciuse crate::daemon_lib::shell; 20cc290419Sopenharmony_ciuse crate::daemon_lib::auth; 21cc290419Sopenharmony_ci#[allow(unused_imports)] 22cc290419Sopenharmony_ciuse crate::common::forward; 23cc290419Sopenharmony_ci#[allow(unused_imports)] 24cc290419Sopenharmony_ciuse crate::common::jdwp; 25cc290419Sopenharmony_ci#[allow(unused_imports)] 26cc290419Sopenharmony_ciuse crate::common::hdcfile; 27cc290419Sopenharmony_ci#[allow(unused_imports)] 28cc290419Sopenharmony_ciuse crate::utils::hdc_log::*; 29cc290419Sopenharmony_ciuse crate::config::ConnectType; 30cc290419Sopenharmony_ciuse crate::transfer::buffer; 31cc290419Sopenharmony_ciuse crate::transfer::TcpMap; 32cc290419Sopenharmony_ciuse crate::transfer::UsbMap; 33cc290419Sopenharmony_ciuse crate::transfer::ConnectTypeMap; 34cc290419Sopenharmony_ci 35cc290419Sopenharmony_cipub async fn free_all_sessiones() { 36cc290419Sopenharmony_ci let sessiones = ConnectTypeMap::get_all_session().await; 37cc290419Sopenharmony_ci for session_id in sessiones { 38cc290419Sopenharmony_ci free_session(session_id).await; 39cc290419Sopenharmony_ci } 40cc290419Sopenharmony_ci} 41cc290419Sopenharmony_ci 42cc290419Sopenharmony_cipub async fn free_session(session_id: u32) { 43cc290419Sopenharmony_ci auth::AuthStatusMap::remove(session_id).await; 44cc290419Sopenharmony_ci stop_task(session_id).await; 45cc290419Sopenharmony_ci match ConnectTypeMap::get(session_id).await { 46cc290419Sopenharmony_ci Some(ConnectType::Bt) => {} 47cc290419Sopenharmony_ci Some(ConnectType::Tcp) => { 48cc290419Sopenharmony_ci TcpMap::end(session_id).await; 49cc290419Sopenharmony_ci } 50cc290419Sopenharmony_ci Some(ConnectType::Uart) => {} 51cc290419Sopenharmony_ci Some(ConnectType::Usb(_)) => { 52cc290419Sopenharmony_ci UsbMap::end(session_id).await; 53cc290419Sopenharmony_ci } 54cc290419Sopenharmony_ci 55cc290419Sopenharmony_ci Some(ConnectType::HostUsb(_)) => { 56cc290419Sopenharmony_ci // add to avoid warning 57cc290419Sopenharmony_ci } 58cc290419Sopenharmony_ci 59cc290419Sopenharmony_ci Some(ConnectType::Bridge) => {} 60cc290419Sopenharmony_ci 61cc290419Sopenharmony_ci None => { 62cc290419Sopenharmony_ci crate::warn!("free_session cannot find connect type for session_id:{session_id}"); 63cc290419Sopenharmony_ci } 64cc290419Sopenharmony_ci } 65cc290419Sopenharmony_ci} 66cc290419Sopenharmony_ci 67cc290419Sopenharmony_cipub async fn stop_task(session_id: u32) { 68cc290419Sopenharmony_ci hdcfile::stop_task(session_id).await; 69cc290419Sopenharmony_ci shell::stop_task(session_id).await; 70cc290419Sopenharmony_ci daemon_app::stop_task(session_id).await; 71cc290419Sopenharmony_ci forward::stop_task(session_id).await; 72cc290419Sopenharmony_ci jdwp::stop_session_task(session_id).await; 73cc290419Sopenharmony_ci} 74cc290419Sopenharmony_ci 75cc290419Sopenharmony_cipub async fn dump_running_task_info() -> String { 76cc290419Sopenharmony_ci let mut result = "\n".to_string(); 77cc290419Sopenharmony_ci result.push_str(&format!("{:#}", buffer::dump_session().await)); 78cc290419Sopenharmony_ci result.push_str(&format!("{:#}", hdcfile::dump_task().await)); 79cc290419Sopenharmony_ci result.push_str(&format!("{:#}", shell::dump_task().await)); 80cc290419Sopenharmony_ci result.push_str(&format!("{:#}", daemon_app::dump_task().await)); 81cc290419Sopenharmony_ci result.push_str(&format!("{:#}", forward::dump_task().await)); 82cc290419Sopenharmony_ci result.push_str("# "); 83cc290419Sopenharmony_ci result.to_string() 84cc290419Sopenharmony_ci} 85