• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 client 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 ipc_rust;
24 
25 use fusion_data_rust::{
26     Intention, DefaultReply, GeneralCoordinationParam, StartCoordinationParam,
27     StopCoordinationParam, GetCoordinationStateParam, FusionResult
28 };
29 use fusion_utils_rust::call_debug_enter;
30 use fusion_ipc_client_rust::FusionIpcClient;
31 use ipc_rust::{ MsgParcel, Deserialize };
32 use std::ffi::{ c_char, CString };
33 use std::rc::Rc;
34 use hilog_rust::{ debug, error, hilog, HiLogLabel, LogType };
35 
36 const LOG_LABEL: HiLogLabel = HiLogLabel {
37     log_type: LogType::LogCore,
38     domain: 0xD002220,
39     tag: "FusionCoordinationClient"
40 };
41 
42 /// struct FusionCoordinationClient
43 #[derive(Default)]
44 pub struct FusionCoordinationClient {
45     dummy: i32
46 }
47 
48 impl FusionCoordinationClient {
49     /// TODO: add documentation.
enable_coordination(&self, user_data: i32, ipc_client: Rc<FusionIpcClient>) -> FusionResult<i32>50     pub fn enable_coordination(&self, user_data: i32, ipc_client: Rc<FusionIpcClient>) -> FusionResult<i32>
51     {
52         call_debug_enter!("FusionCoordinationClient::enable_coordination");
53         match MsgParcel::new() {
54             Some(mut reply_parcel) => {
55                 let param = GeneralCoordinationParam {
56                     user_data
57                 };
58                 let mut borrowed_reply_parcel = reply_parcel.borrowed();
59                 debug!(LOG_LABEL, "Call ipc_client::enable()");
60                 ipc_client.enable(Intention::Coordination, &param, &mut borrowed_reply_parcel)
61             }
62             None => {
63                 error!(LOG_LABEL, "Can not instantiate MsgParcel");
64                 Err(-1)
65             }
66         }
67     }
68 
69     /// TODO: add documentation.
disable_coordination(&self, user_data: i32, ipc_client: Rc<FusionIpcClient>) -> FusionResult<i32>70     pub fn disable_coordination(&self, user_data: i32, ipc_client: Rc<FusionIpcClient>) -> FusionResult<i32>
71     {
72         call_debug_enter!("FusionCoordinationClient::disable_coordination");
73         match MsgParcel::new() {
74             Some(mut reply_parcel) => {
75                 let param = GeneralCoordinationParam {
76                     user_data
77                 };
78                 let mut borrowed_reply_parcel = reply_parcel.borrowed();
79                 debug!(LOG_LABEL, "Call ipc_client::disable()");
80                 ipc_client.disable(Intention::Coordination, &param, &mut borrowed_reply_parcel)
81             }
82             None => {
83                 error!(LOG_LABEL, "Can not instantiate MsgParcel");
84                 Err(-1)
85             }
86         }
87     }
88 
89     /// TODO: add documentation.
start_coordination(&self, user_data: i32, remote_network_id: String, start_device_id: i32, ipc_client: Rc<FusionIpcClient>) -> FusionResult<i32>90     pub fn start_coordination(&self, user_data: i32, remote_network_id: String,
91         start_device_id: i32, ipc_client: Rc<FusionIpcClient>) -> FusionResult<i32>
92     {
93         call_debug_enter!("FusionCoordinationClient::start_coordination");
94         match MsgParcel::new() {
95             Some(mut reply_parcel) => {
96                 let param = StartCoordinationParam {
97                     user_data,
98                     remote_network_id,
99                     start_device_id,
100                 };
101                 let mut borrowed_reply_parcel = reply_parcel.borrowed();
102                 debug!(LOG_LABEL, "Call ipc_client::start()");
103                 ipc_client.start(Intention::Coordination, &param, &mut borrowed_reply_parcel)
104             }
105             None => {
106                 error!(LOG_LABEL, "Can not instantiate MsgParcel");
107                 Err(-1)
108             }
109         }
110     }
111 
112     /// TODO: add documentation.
stop_coordination(&self, user_data: i32, is_unchained: i32, ipc_client: Rc<FusionIpcClient>) -> FusionResult<i32>113     pub fn stop_coordination(&self, user_data: i32, is_unchained: i32,
114         ipc_client: Rc<FusionIpcClient>) -> FusionResult<i32>
115     {
116         call_debug_enter!("FusionCoordinationClient::stop_coordination");
117         match MsgParcel::new() {
118             Some(mut reply_parcel) => {
119                 let param = StopCoordinationParam {
120                     user_data,
121                     is_unchained,
122                 };
123                 let mut borrowed_reply_parcel = reply_parcel.borrowed();
124                 debug!(LOG_LABEL, "Call ipc_client::stop()");
125                 ipc_client.stop(Intention::Coordination, &param, &mut borrowed_reply_parcel)
126             }
127             None => {
128                 error!(LOG_LABEL, "Can not instantiate MsgParcel");
129                 Err(-1)
130             }
131         }
132     }
133 
134     /// TODO: add documentation.
get_coordination_state(&self, user_data: i32, device_id: String, ipc_client: Rc<FusionIpcClient>) -> FusionResult<i32>135     pub fn get_coordination_state(&self, user_data: i32, device_id: String,
136         ipc_client: Rc<FusionIpcClient>) -> FusionResult<i32>
137     {
138         call_debug_enter!("FusionCoordinationClient::get_coordination_state");
139         match MsgParcel::new() {
140             Some(mut reply_parcel) => {
141                 let param = GetCoordinationStateParam {
142                     user_data,
143                     device_id,
144                 };
145                 let mut borrowed_reply_parcel = reply_parcel.borrowed();
146                 debug!(LOG_LABEL, "Call ipc_client::get_param()");
147                 ipc_client.get_param(Intention::Coordination, 0u32, &param, &mut borrowed_reply_parcel)?;
148 
149                 match DefaultReply::deserialize(&borrowed_reply_parcel) {
150                     Ok(x) => {
151                         Ok(x.reply)
152                     }
153                     Err(_) => {
154                         error!(LOG_LABEL, "Fail to deserialize DefaultReply");
155                         Err(-1)
156                     }
157                 }
158             }
159             None => {
160                 error!(LOG_LABEL, "Can not instantiate MsgParcel");
161                 Err(-1)
162             }
163         }
164     }
165 
166     /// TODO: add documentation.
register_coordination_listener(&self, ipc_client: Rc<FusionIpcClient>) -> FusionResult<i32>167     pub fn register_coordination_listener(&self, ipc_client: Rc<FusionIpcClient>) -> FusionResult<i32>
168     {
169         call_debug_enter!("FusionCoordinationClient::register_coordination_listener");
170         match MsgParcel::new() {
171             Some(mut reply_parcel) => {
172                 let param = GeneralCoordinationParam::default();
173                 let mut borrowed_reply_parcel = reply_parcel.borrowed();
174                 debug!(LOG_LABEL, "Call ipc_client::add_watch()");
175                 ipc_client.add_watch(Intention::Coordination, 0u32, &param, &mut borrowed_reply_parcel)
176             }
177             None => {
178                 error!(LOG_LABEL, "Can not instantiate MsgParcel");
179                 Err(-1)
180             }
181         }
182     }
183 
184     /// TODO: add documentation.
unregister_coordination_listener(&self, ipc_client: Rc<FusionIpcClient>) -> FusionResult<i32>185     pub fn unregister_coordination_listener(&self, ipc_client: Rc<FusionIpcClient>) -> FusionResult<i32>
186     {
187         call_debug_enter!("FusionCoordinationClient::unregister_coordination_listener");
188         match MsgParcel::new() {
189             Some(mut reply_parcel) => {
190                 let param = GeneralCoordinationParam::default();
191                 let mut borrowed_reply_parcel = reply_parcel.borrowed();
192                 debug!(LOG_LABEL, "Call ipc_client::remove_watch()");
193                 ipc_client.remove_watch(Intention::Coordination, 0u32, &param, &mut borrowed_reply_parcel)
194             }
195             None => {
196                 error!(LOG_LABEL, "Can not instantiate MsgParcel");
197                 Err(-1)
198             }
199         }
200     }
201 }
202