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 //! Drag client implementation. 17 18 #![allow(dead_code)] 19 #![allow(unused_variables)] 20 21 extern crate fusion_data_rust; 22 extern crate fusion_utils_rust; 23 extern crate ipc_rust; 24 25 use fusion_data_rust::{ Intention, AllocSocketPairParam, BasicParamID, FusionResult }; 26 use fusion_utils_rust::call_debug_enter; 27 use fusion_ipc_client_rust::FusionIpcClient; 28 use ipc_rust::{ FileDesc, MsgParcel, Deserialize }; 29 use std::ffi::{ c_char, CString }; 30 use std::rc::Rc; 31 use hilog_rust::{ debug, error, info, hilog, HiLogLabel, LogType }; 32 33 const LOG_LABEL: HiLogLabel = HiLogLabel { 34 log_type: LogType::LogCore, 35 domain: 0xD002220, 36 tag: "FusionBasicClient" 37 }; 38 39 /// struct FusionBasicClient 40 #[derive(Default)] 41 pub struct FusionBasicClient { 42 dummy: i32 43 } 44 45 impl FusionBasicClient { 46 /// TODO: add documentation. alloc_socket_pair(&self, param: &AllocSocketPairParam, ipc_client: Rc<FusionIpcClient>) -> FusionResult<(FileDesc, i32)>47 pub fn alloc_socket_pair(&self, param: &AllocSocketPairParam, ipc_client: Rc<FusionIpcClient>) 48 -> FusionResult<(FileDesc, i32)> 49 { 50 call_debug_enter!("FusionBasicClient::alloc_socket_pair"); 51 match MsgParcel::new() { 52 Some(mut reply_parcel) => { 53 let mut borrowed_reply_parcel = reply_parcel.borrowed(); 54 debug!(LOG_LABEL, "in DragClient::start_drag(): call ipc_client::start()"); 55 ipc_client.control(Intention::Basic, u32::from(BasicParamID::AllocSocketPair), 56 param, &mut borrowed_reply_parcel)?; 57 58 if let Ok(fdesc) = FileDesc::deserialize(&borrowed_reply_parcel) { 59 if let Ok(token_type) = i32::deserialize(&borrowed_reply_parcel) { 60 info!(LOG_LABEL, "Deserialization succeeded"); 61 return Ok((fdesc, token_type)); 62 } 63 } 64 error!(LOG_LABEL, "Failed to deserialize reply"); 65 Err(-1) 66 } 67 None => { 68 error!(LOG_LABEL, "in DragClient::start_drag(): can not instantiate MsgParcel"); 69 Err(-1) 70 } 71 } 72 } 73 } 74