1 /* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 //! Common data definitions of IPC. 17 18 #![allow(dead_code)] 19 #![allow(unused_variables)] 20 21 use std::ffi::{ c_char, CString }; 22 23 use hilog_rust::{ info, hilog, HiLogLabel, LogType }; 24 use ipc_rust::{ 25 BorrowedMsgParcel, Serialize, Deserialize, IpcResult, 26 get_calling_token_id, get_calling_uid, get_calling_pid 27 }; 28 29 use fusion_utils_rust::call_debug_enter; 30 31 const LOG_LABEL: HiLogLabel = HiLogLabel { 32 log_type: LogType::LogCore, 33 domain: 0xD002220, 34 tag: "FusionIpcDefaultData" 35 }; 36 37 /// User ID、user token、user process ID etc. of one IPC request. 38 pub struct CallingContext { 39 calling_uid: u64, 40 calling_pid: u64, 41 calling_token_id: u64, 42 } 43 44 impl CallingContext { 45 /// Get user ID、user token、user process ID etc. of current IPC request. current() -> Self46 pub fn current() -> Self { 47 info!(LOG_LABEL, "Assemble current calling context"); 48 Self { 49 calling_uid: get_calling_uid(), 50 calling_pid: get_calling_pid(), 51 calling_token_id: get_calling_token_id() 52 } 53 } 54 } 55 56 /// Default reply for a request. 57 pub struct DefaultReply { 58 /// The result of a request. 59 pub reply: i32, 60 } 61 62 impl Serialize for DefaultReply { serialize(&self, parcel: &mut BorrowedMsgParcel<'_>) -> IpcResult<()>63 fn serialize(&self, parcel: &mut BorrowedMsgParcel<'_>) -> IpcResult<()> { 64 call_debug_enter!("DefaultReply::serialize"); 65 self.reply.serialize(parcel)?; 66 Ok(()) 67 } 68 } 69 70 impl Deserialize for DefaultReply { deserialize(parcel: &BorrowedMsgParcel<'_>) -> IpcResult<Self>71 fn deserialize(parcel: &BorrowedMsgParcel<'_>) -> IpcResult<Self> { 72 call_debug_enter!("DefaultReply::deserialize"); 73 let reply = i32::deserialize(parcel)?; 74 Ok(DefaultReply { 75 reply 76 }) 77 } 78 } 79