1 // Copyright (C) 2023 Huawei Device Co., Ltd. 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 use ipc::parcel::MsgParcel; 15 use ipc::{IpcResult, IpcStatusCode}; 16 17 use crate::error::ErrorCode; 18 use crate::manage::events::TaskManagerEvent; 19 use crate::service::RequestServiceStub; 20 21 impl RequestServiceStub { stop(&self, data: &mut MsgParcel, reply: &mut MsgParcel) -> IpcResult<()>22 pub(crate) fn stop(&self, data: &mut MsgParcel, reply: &mut MsgParcel) -> IpcResult<()> { 23 let task_id: String = data.read()?; 24 info!("Service stop tid {}", task_id); 25 26 let Ok(task_id) = task_id.parse::<u32>() else { 27 error!("End Service stop, failed: task_id not valid"); 28 reply.write(&(ErrorCode::TaskNotFound as i32))?; 29 return Err(IpcStatusCode::Failed); 30 }; 31 let uid = ipc::Skeleton::calling_uid(); 32 33 if !self.check_task_uid(task_id, uid) { 34 reply.write(&(ErrorCode::TaskNotFound as i32))?; 35 return Err(IpcStatusCode::Failed); 36 } 37 38 let (event, rx) = TaskManagerEvent::stop(uid, task_id); 39 if !self.task_manager.lock().unwrap().send_event(event) { 40 return Err(IpcStatusCode::Failed); 41 } 42 let ret = match rx.get() { 43 Some(ret) => ret, 44 None => { 45 error!( 46 "End Service stop, tid: {}, failed: receives ret failed", 47 task_id 48 ); 49 return Err(IpcStatusCode::Failed); 50 } 51 }; 52 reply.write(&(ret as i32))?; 53 if ret != ErrorCode::ErrOk { 54 error!("End Service stop, tid: {}, failed: {}", task_id, ret as i32); 55 return Err(IpcStatusCode::Failed); 56 } 57 Ok(()) 58 } 59 } 60