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 //! Proxy for general functionality of service.
17 
18 #![allow(dead_code)]
19 #![allow(unused_variables)]
20 
21 use std::ffi::{ c_char, CString };
22 
23 use hilog_rust::{ debug, hilog, HiLogLabel, LogType };
24 use ipc_rust::{ FileDesc, MsgParcel, Deserialize };
25 
26 use fusion_data_rust::{ Intention, AllocSocketPairParam, BasicParamID};
27 use fusion_utils_rust::{ call_debug_enter, FusionResult, FusionErrorCode };
28 use fusion_ipc_client_rust::FusionIpcClient;
29 
30 const LOG_LABEL: HiLogLabel = HiLogLabel {
31     log_type: LogType::LogCore,
32     domain: 0xD002220,
33     tag: "FusionBasicClient"
34 };
35 
36 /// Definition of proxy for general functionality of service.
37 #[derive(Default)]
38 pub struct FusionBasicClient(i32);
39 
40 impl FusionBasicClient {
41     /// Request connection of service via socket.
alloc_socket_pair(&self, param: &AllocSocketPairParam, ipc_client: &FusionIpcClient) -> FusionResult<(FileDesc, i32)>42     pub fn alloc_socket_pair(&self, param: &AllocSocketPairParam,
43                              ipc_client: &FusionIpcClient) -> FusionResult<(FileDesc, i32)>
44     {
45         call_debug_enter!("FusionBasicClient::alloc_socket_pair");
46         let mut reply_parcel = MsgParcel::new().ok_or(FusionErrorCode::Fail)?;
47         let mut borrowed_reply_parcel = reply_parcel.borrowed();
48 
49         debug!(LOG_LABEL, "Call ipc_client::start()");
50         ipc_client.control(Intention::Basic, u32::from(BasicParamID::AllocSocketPair),
51             param, &mut borrowed_reply_parcel)?;
52 
53         let fdesc = FileDesc::deserialize(&borrowed_reply_parcel).or(Err(FusionErrorCode::Fail))?;
54         let token_type = i32::deserialize(&borrowed_reply_parcel).or(Err(FusionErrorCode::Fail))?;
55         Ok((fdesc, token_type))
56     }
57 }
58