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