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 //! Service of multi-device cooperation.
17 
18 #![allow(dead_code)]
19 #![allow(unused_variables)]
20 
21 mod coordination;
22 
23 use std::ffi::{ c_char, CString };
24 
25 use hilog_rust::{ hilog, HiLogLabel, LogType };
26 use ipc_rust::{ BorrowedMsgParcel, Deserialize };
27 
28 use fusion_data_rust::{ IPlugin, CallingContext, GeneralCoordinationParam, StartCoordinationParam,
29     StopCoordinationParam, GetCoordinationStateParam };
30 use fusion_plugin_manager_rust::export_plugin;
31 use fusion_utils_rust::{ call_debug_enter, FusionResult, FusionErrorCode };
32 
33 use coordination::Coordination;
34 
35 const LOG_LABEL: HiLogLabel = HiLogLabel {
36     log_type: LogType::LogCore,
37     domain: 0xD002220,
38     tag: "FusionCoordinationServer"
39 };
40 
41 /// Module-level interface of multi-device cooperation.
42 #[derive(Default)]
43 struct FusionCoordinationServer(Coordination);
44 
45 impl IPlugin for FusionCoordinationServer {
enable(&self, context: &CallingContext, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<()>46     fn enable(&self, context: &CallingContext, data: &BorrowedMsgParcel,
47         reply: &mut BorrowedMsgParcel) -> FusionResult<()> {
48         call_debug_enter!("FusionCoordinationServer::enable");
49         let param = GeneralCoordinationParam::deserialize(data).or(Err(FusionErrorCode::Fail))?;
50         self.0.enable(context, &param)
51     }
52 
disable(&self, context: &CallingContext, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<()>53     fn disable(&self, context: &CallingContext, data: &BorrowedMsgParcel,
54         reply: &mut BorrowedMsgParcel) -> FusionResult<()> {
55         call_debug_enter!("FusionCoordinationServer::disable");
56         let param = GeneralCoordinationParam::deserialize(data).or(Err(FusionErrorCode::Fail))?;
57         self.0.disable(context, &param)
58     }
59 
start(&self, context: &CallingContext, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<()>60     fn start(&self, context: &CallingContext, data: &BorrowedMsgParcel,
61         reply: &mut BorrowedMsgParcel) -> FusionResult<()> {
62         call_debug_enter!("FusionCoordinationServer::start");
63         let param = StartCoordinationParam::deserialize(data).or(Err(FusionErrorCode::Fail))?;
64         self.0.start(context, &param)
65     }
66 
stop(&self, context: &CallingContext, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<()>67     fn stop(&self, context: &CallingContext, data: &BorrowedMsgParcel,
68         reply: &mut BorrowedMsgParcel) -> FusionResult<()> {
69         call_debug_enter!("FusionCoordinationServer::stop");
70         let param = StopCoordinationParam::deserialize(data).or(Err(FusionErrorCode::Fail))?;
71         self.0.stop(context, &param)
72     }
73 
add_watch(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<()>74     fn add_watch(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel,
75         reply: &mut BorrowedMsgParcel) -> FusionResult<()> {
76         call_debug_enter!("FusionCoordinationServer::add_watch");
77         let param = GeneralCoordinationParam::deserialize(data).or(Err(FusionErrorCode::Fail))?;
78         self.0.register_listener(context, &param)
79     }
80 
remove_watch(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<()>81     fn remove_watch(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel,
82         reply: &mut BorrowedMsgParcel) -> FusionResult<()> {
83         call_debug_enter!("FusionCoordinationServer::remove_watch");
84         let param = GeneralCoordinationParam::deserialize(data).or(Err(FusionErrorCode::Fail))?;
85         self.0.unregister_listener(context, &param)
86     }
87 
set_param(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<()>88     fn set_param(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel,
89         reply: &mut BorrowedMsgParcel) -> FusionResult<()> {
90         call_debug_enter!("FusionCoordinationServer::set_param");
91         Err(FusionErrorCode::Fail)
92     }
93 
get_param(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<()>94     fn get_param(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel,
95         reply: &mut BorrowedMsgParcel) -> FusionResult<()> {
96         call_debug_enter!("FusionCoordinationServer::get_param");
97         let param = GetCoordinationStateParam::deserialize(data).or(Err(FusionErrorCode::Fail))?;
98         self.0.get_state(context, &param)
99     }
100 
control(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> FusionResult<()>101     fn control(&self, context: &CallingContext, id: u32, data: &BorrowedMsgParcel,
102         reply: &mut BorrowedMsgParcel) -> FusionResult<()> {
103         call_debug_enter!("FusionCoordinationServer::control");
104         Err(FusionErrorCode::Fail)
105     }
106 }
107 
108 export_plugin!(FusionCoordinationServer);
109