1f857971dSopenharmony_ci/* 2f857971dSopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd. 3f857971dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4f857971dSopenharmony_ci * you may not use this file except in compliance with the License. 5f857971dSopenharmony_ci * You may obtain a copy of the License at 6f857971dSopenharmony_ci * 7f857971dSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8f857971dSopenharmony_ci * 9f857971dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10f857971dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11f857971dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f857971dSopenharmony_ci * See the License for the specific language governing permissions and 13f857971dSopenharmony_ci * limitations under the License. 14f857971dSopenharmony_ci */ 15f857971dSopenharmony_ci 16f857971dSopenharmony_ci//! Proxy for general functionality of service. 17f857971dSopenharmony_ci 18f857971dSopenharmony_ci#![allow(dead_code)] 19f857971dSopenharmony_ci#![allow(unused_variables)] 20f857971dSopenharmony_ci 21f857971dSopenharmony_ciuse std::ffi::{ c_char, CString }; 22f857971dSopenharmony_ci 23f857971dSopenharmony_ciuse hilog_rust::{ debug, hilog, HiLogLabel, LogType }; 24f857971dSopenharmony_ciuse ipc_rust::{ FileDesc, MsgParcel, Deserialize }; 25f857971dSopenharmony_ci 26f857971dSopenharmony_ciuse fusion_data_rust::{ Intention, AllocSocketPairParam, BasicParamID}; 27f857971dSopenharmony_ciuse fusion_utils_rust::{ call_debug_enter, FusionResult, FusionErrorCode }; 28f857971dSopenharmony_ciuse fusion_ipc_client_rust::FusionIpcClient; 29f857971dSopenharmony_ci 30f857971dSopenharmony_ciconst LOG_LABEL: HiLogLabel = HiLogLabel { 31f857971dSopenharmony_ci log_type: LogType::LogCore, 32f857971dSopenharmony_ci domain: 0xD002220, 33f857971dSopenharmony_ci tag: "FusionBasicClient" 34f857971dSopenharmony_ci}; 35f857971dSopenharmony_ci 36f857971dSopenharmony_ci/// Definition of proxy for general functionality of service. 37f857971dSopenharmony_ci#[derive(Default)] 38f857971dSopenharmony_cipub struct FusionBasicClient(i32); 39f857971dSopenharmony_ci 40f857971dSopenharmony_ciimpl FusionBasicClient { 41f857971dSopenharmony_ci /// Request connection of service via socket. 42f857971dSopenharmony_ci pub fn alloc_socket_pair(&self, param: &AllocSocketPairParam, 43f857971dSopenharmony_ci ipc_client: &FusionIpcClient) -> FusionResult<(FileDesc, i32)> 44f857971dSopenharmony_ci { 45f857971dSopenharmony_ci call_debug_enter!("FusionBasicClient::alloc_socket_pair"); 46f857971dSopenharmony_ci let mut reply_parcel = MsgParcel::new().ok_or(FusionErrorCode::Fail)?; 47f857971dSopenharmony_ci let mut borrowed_reply_parcel = reply_parcel.borrowed(); 48f857971dSopenharmony_ci 49f857971dSopenharmony_ci debug!(LOG_LABEL, "Call ipc_client::start()"); 50f857971dSopenharmony_ci ipc_client.control(Intention::Basic, u32::from(BasicParamID::AllocSocketPair), 51f857971dSopenharmony_ci param, &mut borrowed_reply_parcel)?; 52f857971dSopenharmony_ci 53f857971dSopenharmony_ci let fdesc = FileDesc::deserialize(&borrowed_reply_parcel).or(Err(FusionErrorCode::Fail))?; 54f857971dSopenharmony_ci let token_type = i32::deserialize(&borrowed_reply_parcel).or(Err(FusionErrorCode::Fail))?; 55f857971dSopenharmony_ci Ok((fdesc, token_type)) 56f857971dSopenharmony_ci } 57f857971dSopenharmony_ci} 58