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 Server implementation.
17 
18 #![allow(dead_code)]
19 #![allow(unused_variables)]
20 // FIXME: need abi_stable crate or thin_trait_object crate
21 #![allow(improper_ctypes_definitions)]
22 
23 use std::ffi::{ c_char, CString };
24 use hilog_rust::{ info, error, hilog, HiLogLabel, LogType };
25 use ipc_rust::{ BorrowedMsgParcel, Serialize, Deserialize };
26 use fusion_data_rust::{ IPlugin, CallingContext, DragData };
27 use fusion_utils_rust::{ call_debug_enter, FusionResult, FusionErrorCode };
28 use fusion_plugin_manager_rust::export_plugin;
29 
30 const LOG_LABEL: HiLogLabel = HiLogLabel {
31     log_type: LogType::LogCore,
32     domain: 0xD002220,
33     tag: "FusionDragServer"
34 };
35 
36 /// Implementation of drag service.
37 ///
38 /// # Functions provided by drag service:
39 ///
40 ///     * Start drag and put service in DRAG mode.
41 ///     * Stop drag and reset mode of service.
42 ///     * Add listener for drag events.
43 ///     * Remove listener of drag events.
44 ///     * Set visibility of drag window.
45 ///     * Update shadow.
46 ///
47 /// For integration with `intention framework`, we have to map functions
48 /// mention above to [`IPlugin`] as:
49 ///
50 ///     * `IPlugin::start` to start drag and put service in DRAG mode.
51 ///     * `IPlugin::stop` to start drag and reset mode of service.
52 ///     * `IPlugin::add_watch` to add listener for drag events.
53 ///     * `IPlugin::remove_watch` to remove listener of drag events.
54 ///     * `IPlugin::set_param` to set visibility of drag window, using
55 ///       [`DRAG_WINDOW_VISIBILITY`] as parameter ID.
56 ///     * `IPlugin::set_param` to update shadow, using [`UPDATE_SHADOW`]
57 ///       as parameter ID.
58 ///
59 /// Default action for unmapped interfaces of [`IPlugin`] is simply to
60 /// fail and return error.
61 ///
62 #[derive(Default)]
63 pub struct FusionDragServer(i32);
64 
65 impl IPlugin for FusionDragServer {
enable(&self, context: &CallingContext, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<()>66     fn enable(&self, context: &CallingContext, data: &BorrowedMsgParcel,
67         reply: &mut BorrowedMsgParcel) -> FusionResult<()> {
68         call_debug_enter!("FusionDragServer::enable");
69         Ok(())
70     }
71 
disable(&self, context: &CallingContext, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<()>72     fn disable(&self, context: &CallingContext, data: &BorrowedMsgParcel,
73         reply: &mut BorrowedMsgParcel) -> FusionResult<()> {
74         call_debug_enter!("FusionDragServer::disable");
75         Ok(())
76     }
77 
start(&self, context: &CallingContext, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<()>78     fn start(&self, context: &CallingContext, data: &BorrowedMsgParcel,
79         reply: &mut BorrowedMsgParcel) -> FusionResult<()> {
80         call_debug_enter!("FusionDragServer::start");
81         match DragData::deserialize(data) {
82             Ok(drag_data) => {
83                 info!(LOG_LABEL, "In FusionDragServer::start(): call start_drag()");
84                 info!(LOG_LABEL, "{}", drag_data);
85                 match 0u32.serialize(reply) {
86                     Ok(_) => {
87                         Ok(())
88                     }
89                     Err(_) => {
90                         error!(LOG_LABEL, "Failed to serialize reply");
91                         Err(FusionErrorCode::Fail)
92                     }
93                 }
94             }
95             Err(_) => {
96                 error!(LOG_LABEL, "In FusionDragServer::start(): DragData::deserialize() failed");
97                 Err(FusionErrorCode::Fail)
98             }
99         }
100     }
101 
stop(&self, context: &CallingContext, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<()>102     fn stop(&self, context: &CallingContext, data: &BorrowedMsgParcel,
103         reply: &mut BorrowedMsgParcel) -> FusionResult<()> {
104         call_debug_enter!("FusionDragServer::stop");
105         Ok(())
106     }
107 
add_watch(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<()>108     fn add_watch(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel,
109         reply: &mut BorrowedMsgParcel) -> FusionResult<()> {
110         call_debug_enter!("FusionDragServer::add_watch");
111         Ok(())
112     }
113 
remove_watch(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<()>114     fn remove_watch(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel,
115         reply: &mut BorrowedMsgParcel) -> FusionResult<()> {
116         call_debug_enter!("FusionDragServer::remove_watch");
117         Ok(())
118     }
119 
set_param(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<()>120     fn set_param(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel,
121         reply: &mut BorrowedMsgParcel) -> FusionResult<()> {
122         call_debug_enter!("FusionDragServer::set_param");
123         Ok(())
124     }
125 
get_param(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<()>126     fn get_param(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel,
127         reply: &mut BorrowedMsgParcel) -> FusionResult<()> {
128         call_debug_enter!("FusionDragServer::get_param");
129         Ok(())
130     }
131 
control(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<()>132     fn control(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel,
133         reply: &mut BorrowedMsgParcel) -> FusionResult<()> {
134         call_debug_enter!("FusionDragServer::control");
135         Ok(())
136     }
137 }
138 
139 export_plugin!(FusionDragServer);
140