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 //! Coordination Server implementation. 17 18 #![allow(dead_code)] 19 #![allow(unused_variables)] 20 21 extern crate fusion_data_rust; 22 extern crate fusion_utils_rust; 23 extern crate fusion_plugin_manager_rust; 24 extern crate hilog_rust; 25 extern crate ipc_rust; 26 27 mod coordination; 28 29 use std::ffi::{ c_char, CString }; 30 use hilog_rust::{ error, hilog, HiLogLabel, LogType }; 31 use ipc_rust::{ BorrowedMsgParcel, Deserialize }; 32 use fusion_data_rust::{ IPlugin, CallingContext, GeneralCoordinationParam, StartCoordinationParam, 33 StopCoordinationParam, GetCoordinationStateParam, FusionResult }; 34 use fusion_utils_rust::call_debug_enter; 35 use fusion_plugin_manager_rust::export_plugin; 36 use coordination::Coordination; 37 38 const LOG_LABEL: HiLogLabel = HiLogLabel { 39 log_type: LogType::LogCore, 40 domain: 0xD002220, 41 tag: "FusionCoordinationServer" 42 }; 43 44 /// struct FusionCoordinationServer 45 #[derive(Default)] 46 pub struct FusionCoordinationServer(Coordination); 47 48 // impl FusionCoordinationServer { 49 // /// TODO: add documentation. 50 // pub fn new(ops: &FusionDragOperations) -> Self { 51 // Self(ops.clone()) 52 // } 53 // } 54 55 impl IPlugin for FusionCoordinationServer { enable(&self, context: &CallingContext, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<i32>56 fn enable(&self, context: &CallingContext, data: &BorrowedMsgParcel, 57 reply: &mut BorrowedMsgParcel) -> FusionResult<i32> { 58 call_debug_enter!("FusionCoordinationServer::enable"); 59 match GeneralCoordinationParam::deserialize(data) { 60 Ok(param) => { 61 self.0.enable(context, ¶m) 62 } 63 Err(_) => { 64 error!(LOG_LABEL, "GeneralCoordinationParam::deserialize() failed"); 65 Err(-1) 66 } 67 } 68 } 69 disable(&self, context: &CallingContext, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<i32>70 fn disable(&self, context: &CallingContext, data: &BorrowedMsgParcel, 71 reply: &mut BorrowedMsgParcel) -> FusionResult<i32> { 72 call_debug_enter!("FusionCoordinationServer::disable"); 73 match GeneralCoordinationParam::deserialize(data) { 74 Ok(param) => { 75 self.0.disable(context, ¶m) 76 } 77 Err(_) => { 78 error!(LOG_LABEL, "GeneralCoordinationParam::deserialize() failed"); 79 Err(-1) 80 } 81 } 82 } 83 start(&self, context: &CallingContext, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<i32>84 fn start(&self, context: &CallingContext, data: &BorrowedMsgParcel, 85 reply: &mut BorrowedMsgParcel) -> FusionResult<i32> { 86 call_debug_enter!("FusionCoordinationServer::start"); 87 match StartCoordinationParam::deserialize(data) { 88 Ok(param) => { 89 self.0.start(context, ¶m) 90 } 91 Err(_) => { 92 error!(LOG_LABEL, "StartCoordinationParam::deserialize() failed"); 93 Err(-1) 94 } 95 } 96 } 97 stop(&self, context: &CallingContext, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<i32>98 fn stop(&self, context: &CallingContext, data: &BorrowedMsgParcel, 99 reply: &mut BorrowedMsgParcel) -> FusionResult<i32> { 100 call_debug_enter!("FusionCoordinationServer::stop"); 101 match StopCoordinationParam::deserialize(data) { 102 Ok(param) => { 103 self.0.stop(context, ¶m) 104 } 105 Err(_) => { 106 error!(LOG_LABEL, "StopCoordinationParam::deserialize() failed"); 107 Err(-1) 108 } 109 } 110 } 111 add_watch(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<i32>112 fn add_watch(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel, 113 reply: &mut BorrowedMsgParcel) -> FusionResult<i32> { 114 call_debug_enter!("FusionCoordinationServer::add_watch"); 115 match GeneralCoordinationParam::deserialize(data) { 116 Ok(param) => { 117 self.0.register_listener(context, ¶m) 118 } 119 Err(_) => { 120 error!(LOG_LABEL, "GeneralCoordinationParam::deserialize() failed"); 121 Err(-1) 122 } 123 } 124 } 125 remove_watch(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<i32>126 fn remove_watch(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel, 127 reply: &mut BorrowedMsgParcel) -> FusionResult<i32> { 128 call_debug_enter!("FusionCoordinationServer::remove_watch"); 129 match GeneralCoordinationParam::deserialize(data) { 130 Ok(param) => { 131 self.0.unregister_listener(context, ¶m) 132 } 133 Err(_) => { 134 error!(LOG_LABEL, "GeneralCoordinationParam::deserialize() failed"); 135 Err(-1) 136 } 137 } 138 } 139 set_param(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<i32>140 fn set_param(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel, 141 reply: &mut BorrowedMsgParcel) -> FusionResult<i32> { 142 call_debug_enter!("FusionCoordinationServer::set_param"); 143 Err(-1) 144 } 145 get_param(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<i32>146 fn get_param(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel, 147 reply: &mut BorrowedMsgParcel) -> FusionResult<i32> { 148 call_debug_enter!("FusionCoordinationServer::get_param"); 149 match GetCoordinationStateParam::deserialize(data) { 150 Ok(param) => { 151 self.0.get_state(context, ¶m) 152 } 153 Err(_) => { 154 error!(LOG_LABEL, "GetCoordinationStateParam::deserialize() failed"); 155 Err(-1) 156 } 157 } 158 } 159 control(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<i32>160 fn control(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel, 161 reply: &mut BorrowedMsgParcel) -> FusionResult<i32> { 162 call_debug_enter!("FusionCoordinationServer::control"); 163 Err(-1) 164 } 165 } 166 167 export_plugin!(FusionCoordinationServer); 168