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 `Drag` service.
17
18#![allow(dead_code)]
19#![allow(unused_variables)]
20
21use std::ffi::{ c_char, CString };
22use fusion_data_rust::{ Intention, DefaultReply, DragData };
23use fusion_utils_rust::{ call_debug_enter, FusionResult, FusionErrorCode };
24use fusion_ipc_client_rust::FusionIpcClient;
25use ipc_rust::{ MsgParcel, Deserialize };
26use hilog_rust::{ debug, error, hilog, HiLogLabel, LogType };
27
28const LOG_LABEL: HiLogLabel = HiLogLabel {
29    log_type: LogType::LogCore,
30    domain: 0xD002220,
31    tag: "FusionDragClient"
32};
33
34/// Definition of proxy for `Drag` service.
35#[derive(Default)]
36pub struct DragClient(i32);
37
38impl DragClient {
39    /// Request service to change to [`DRAG`] mode.
40    pub fn start_drag(&self, drag_data: &DragData, ipc_client: &FusionIpcClient) -> FusionResult<i32>
41    {
42        call_debug_enter!("DragClient::start_drag");
43        match MsgParcel::new() {
44            Some(mut reply_parcel) => {
45                let mut borrowed_reply_parcel = reply_parcel.borrowed();
46                debug!(LOG_LABEL, "Call ipc_client::start()");
47                ipc_client.start(Intention::Drag, drag_data, &mut borrowed_reply_parcel)?;
48
49                match DefaultReply::deserialize(&borrowed_reply_parcel) {
50                    Ok(x) => {
51                        Ok(x.reply)
52                    }
53                    Err(_) => {
54                        error!(LOG_LABEL, "Failed to deserialize DefaultReply");
55                        Err(FusionErrorCode::Fail)
56                    }
57                }
58            }
59            None => {
60                error!(LOG_LABEL, "Can not instantiate MsgParcel");
61                Err(FusionErrorCode::Fail)
62            }
63        }
64    }
65}
66