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 #![allow(missing_docs)]
17 #![allow(unused_variables)]
18 #![allow(unused_mut)]
19 
20 extern crate ipc_rust;
21 
22 use ipc_rust::{
23     IRemoteBroker, IRemoteObj, RemoteStub, Result,
24     RemoteObj, define_remote_object, FIRST_CALL_TRANSACTION
25 };
26 use ipc_rust::{MsgParcel, BorrowedMsgParcel};
27 
28 
29 pub enum IIdlTestServiceCode {
30     CodeIdlIpcTestBasic001  = FIRST_CALL_TRANSACTION,
31     CodeIdlIpcTestBasic002,
32     CodeIdlIpcTestBasic101,
33     CodeIdlIpcTestBasic102,
34     CodeIdlIpcTestBasic103,
35     CodeIdlIpcTestBasic104,
36     CodeIdlIpcTestBasic105,
37     CodeIdlIpcTestBasic106,
38     CodeIdlIpcTestBasic107,
39     CodeIdlIpcTestBasic108,
40     CodeIdlIpcTestBasic199,
41 }
42 
43 define_remote_object!(
44     IIdlTestService["IIdlTestService"] {
45         stub: IdlTestServiceStub(on_remote_request),
46         proxy: IdlTestServiceProxy,
47     }
48 );
49 
50 pub trait IIdlTestService: IRemoteBroker {
idl_ipc_test_basic_001(&self) -> Result<()>51     fn idl_ipc_test_basic_001(&self) -> Result<()>;
idl_ipc_test_basic_002(&self) -> Result<()>52     fn idl_ipc_test_basic_002(&self) -> Result<()>;
idl_ipc_test_basic_101(&self, i_bool: &bool) -> Result<bool>53     fn idl_ipc_test_basic_101(&self, i_bool: &bool) -> Result<bool>;
idl_ipc_test_basic_102(&self, i_byte: &i8) -> Result<i8>54     fn idl_ipc_test_basic_102(&self, i_byte: &i8) -> Result<i8>;
idl_ipc_test_basic_103(&self, i_short: &i16) -> Result<i16>55     fn idl_ipc_test_basic_103(&self, i_short: &i16) -> Result<i16>;
idl_ipc_test_basic_104(&self, i_int: &i32) -> Result<i32>56     fn idl_ipc_test_basic_104(&self, i_int: &i32) -> Result<i32>;
idl_ipc_test_basic_105(&self, i_long: &i64) -> Result<i64>57     fn idl_ipc_test_basic_105(&self, i_long: &i64) -> Result<i64>;
idl_ipc_test_basic_106(&self, i_float: &f32) -> Result<f32>58     fn idl_ipc_test_basic_106(&self, i_float: &f32) -> Result<f32>;
idl_ipc_test_basic_107(&self, i_double: &f64) -> Result<f64>59     fn idl_ipc_test_basic_107(&self, i_double: &f64) -> Result<f64>;
idl_ipc_test_basic_108(&self, i_string: &str) -> Result<String>60     fn idl_ipc_test_basic_108(&self, i_string: &str) -> Result<String>;
idl_ipc_test_basic_199(&self, i_bool: &bool, i_long: &i64, i_float: &f32, i_double: &f64, i_string: &str) -> Result<bool>61     fn idl_ipc_test_basic_199(&self, i_bool: &bool, i_long: &i64, i_float: &f32,
62         i_double: &f64, i_string: &str) -> Result<bool>;
63 }
64 
on_remote_request(stub: &dyn IIdlTestService, code: u32, data: &BorrowedMsgParcel, reply: &mut BorrowedMsgParcel) -> Result<()>65 fn on_remote_request(stub: &dyn IIdlTestService, code: u32, data: &BorrowedMsgParcel,
66     reply: &mut BorrowedMsgParcel) -> Result<()> {
67     match code {
68         1 => {
69             stub.idl_ipc_test_basic_001()?;
70             Ok(())
71         }
72         2 => {
73             stub.idl_ipc_test_basic_002()?;
74             Ok(())
75         }
76         3 => {
77             let i_bool : bool = data.read()?;
78             let result = stub.idl_ipc_test_basic_101(&i_bool)?;
79             reply.write(&result)?;
80             Ok(())
81         }
82         4 => {
83             let i_byte : i8 = data.read()?;
84             let result = stub.idl_ipc_test_basic_102(&i_byte)?;
85             reply.write(&result)?;
86             Ok(())
87         }
88         5 => {
89             let i_short : i16 = data.read()?;
90             let result = stub.idl_ipc_test_basic_103(&i_short)?;
91             reply.write(&result)?;
92             Ok(())
93         }
94         6 => {
95             let i_int : i32 = data.read()?;
96             let result = stub.idl_ipc_test_basic_104(&i_int)?;
97             reply.write(&result)?;
98             Ok(())
99         }
100         7 => {
101             let i_long : i64 = data.read()?;
102             let result = stub.idl_ipc_test_basic_105(&i_long)?;
103             reply.write(&result)?;
104             Ok(())
105         }
106         8 => {
107             let i_float : f32 = data.read()?;
108             let result = stub.idl_ipc_test_basic_106(&i_float)?;
109             reply.write(&result)?;
110             Ok(())
111         }
112         9 => {
113             let i_double : f64 = data.read()?;
114             let result = stub.idl_ipc_test_basic_107(&i_double)?;
115             reply.write(&result)?;
116             Ok(())
117         }
118         10 => {
119             let i_string : String = data.read()?;
120             let result = stub.idl_ipc_test_basic_108(&i_string)?;
121             reply.write(&result)?;
122             Ok(())
123         }
124         11 => {
125             let i_bool : bool = data.read()?;
126             let i_long : i64 = data.read()?;
127             let i_float : f32 = data.read()?;
128             let i_double : f64 = data.read()?;
129             let i_string : String = data.read()?;
130             let result = stub.idl_ipc_test_basic_199(&i_bool, &i_long, &i_float, &i_double,
131                 &i_string)?;
132             reply.write(&result)?;
133             Ok(())
134         }
135         _ => Err(-1)
136     }
137 }
138 
139 impl IIdlTestService for RemoteStub<IdlTestServiceStub> {
idl_ipc_test_basic_001(&self) -> Result<()>140     fn idl_ipc_test_basic_001(&self) -> Result<()> {
141         self.0.idl_ipc_test_basic_001()
142     }
143 
idl_ipc_test_basic_002(&self) -> Result<()>144     fn idl_ipc_test_basic_002(&self) -> Result<()> {
145         self.0.idl_ipc_test_basic_002()
146     }
147 
idl_ipc_test_basic_101(&self, i_bool: &bool) -> Result<bool>148     fn idl_ipc_test_basic_101(&self, i_bool: &bool) -> Result<bool> {
149         self.0.idl_ipc_test_basic_101(i_bool)
150     }
151 
idl_ipc_test_basic_102(&self, i_byte: &i8) -> Result<i8>152     fn idl_ipc_test_basic_102(&self, i_byte: &i8) -> Result<i8> {
153         self.0.idl_ipc_test_basic_102(i_byte)
154     }
155 
idl_ipc_test_basic_103(&self, i_short: &i16) -> Result<i16>156     fn idl_ipc_test_basic_103(&self, i_short: &i16) -> Result<i16> {
157         self.0.idl_ipc_test_basic_103(i_short)
158     }
159 
idl_ipc_test_basic_104(&self, i_int: &i32) -> Result<i32>160     fn idl_ipc_test_basic_104(&self, i_int: &i32) -> Result<i32> {
161         self.0.idl_ipc_test_basic_104(i_int)
162     }
163 
idl_ipc_test_basic_105(&self, i_long: &i64) -> Result<i64>164     fn idl_ipc_test_basic_105(&self, i_long: &i64) -> Result<i64> {
165         self.0.idl_ipc_test_basic_105(i_long)
166     }
167 
idl_ipc_test_basic_106(&self, i_float: &f32) -> Result<f32>168     fn idl_ipc_test_basic_106(&self, i_float: &f32) -> Result<f32> {
169         self.0.idl_ipc_test_basic_106(i_float)
170     }
171 
idl_ipc_test_basic_107(&self, i_double: &f64) -> Result<f64>172     fn idl_ipc_test_basic_107(&self, i_double: &f64) -> Result<f64> {
173         self.0.idl_ipc_test_basic_107(i_double)
174     }
175 
idl_ipc_test_basic_108(&self, i_string: &str) -> Result<String>176     fn idl_ipc_test_basic_108(&self, i_string: &str) -> Result<String> {
177         self.0.idl_ipc_test_basic_108(i_string)
178     }
179 
idl_ipc_test_basic_199(&self, i_bool: &bool, i_long: &i64, i_float: &f32, i_double: &f64, i_string: &str) -> Result<bool>180     fn idl_ipc_test_basic_199(&self, i_bool: &bool, i_long: &i64, i_float: &f32,
181         i_double: &f64, i_string: &str) -> Result<bool> {
182         self.0.idl_ipc_test_basic_199(i_bool, i_long, i_float, i_double,
183                 i_string)
184     }
185 }
186 
187 impl IIdlTestService for IdlTestServiceProxy {
idl_ipc_test_basic_001(&self) -> Result<()>188     fn idl_ipc_test_basic_001(&self) -> Result<()> {
189         let mut data = MsgParcel::new().expect("MsgParcel should success");
190         let _reply = self.remote.send_request(IIdlTestServiceCode::CodeIdlIpcTestBasic001 as u32, &data, false)?;
191         Ok(())
192     }
193 
idl_ipc_test_basic_002(&self) -> Result<()>194     fn idl_ipc_test_basic_002(&self) -> Result<()> {
195         let mut data = MsgParcel::new().expect("MsgParcel should success");
196         let _reply = self.remote.send_request(IIdlTestServiceCode::CodeIdlIpcTestBasic002 as u32, &data, true)?;
197         Ok(())
198     }
199 
idl_ipc_test_basic_101(&self, i_bool: &bool) -> Result<bool>200     fn idl_ipc_test_basic_101(&self, i_bool: &bool) -> Result<bool> {
201         let mut data = MsgParcel::new().expect("MsgParcel should success");
202         data.write(&i_bool)?;
203         let reply = self.remote.send_request(IIdlTestServiceCode::CodeIdlIpcTestBasic101 as u32, &data, false)?;
204         let result : bool = reply.read()?;
205         Ok(result)
206     }
207 
idl_ipc_test_basic_102(&self, i_byte: &i8) -> Result<i8>208     fn idl_ipc_test_basic_102(&self, i_byte: &i8) -> Result<i8> {
209         let mut data = MsgParcel::new().expect("MsgParcel should success");
210         data.write(&i_byte)?;
211         let reply = self.remote.send_request(IIdlTestServiceCode::CodeIdlIpcTestBasic102 as u32, &data, false)?;
212         let result : i8 = reply.read()?;
213         Ok(result)
214     }
215 
idl_ipc_test_basic_103(&self, i_short: &i16) -> Result<i16>216     fn idl_ipc_test_basic_103(&self, i_short: &i16) -> Result<i16> {
217         let mut data = MsgParcel::new().expect("MsgParcel should success");
218         data.write(&i_short)?;
219         let reply = self.remote.send_request(IIdlTestServiceCode::CodeIdlIpcTestBasic103 as u32, &data, false)?;
220         let result : i16 = reply.read()?;
221         Ok(result)
222     }
223 
idl_ipc_test_basic_104(&self, i_int: &i32) -> Result<i32>224     fn idl_ipc_test_basic_104(&self, i_int: &i32) -> Result<i32> {
225         let mut data = MsgParcel::new().expect("MsgParcel should success");
226         data.write(&i_int)?;
227         let reply = self.remote.send_request(IIdlTestServiceCode::CodeIdlIpcTestBasic104 as u32, &data, false)?;
228         let result : i32 = reply.read()?;
229         Ok(result)
230     }
231 
idl_ipc_test_basic_105(&self, i_long: &i64) -> Result<i64>232     fn idl_ipc_test_basic_105(&self, i_long: &i64) -> Result<i64> {
233         let mut data = MsgParcel::new().expect("MsgParcel should success");
234         data.write(&i_long)?;
235         let reply = self.remote.send_request(IIdlTestServiceCode::CodeIdlIpcTestBasic105 as u32, &data, false)?;
236         let result : i64 = reply.read()?;
237         Ok(result)
238     }
239 
idl_ipc_test_basic_106(&self, i_float: &f32) -> Result<f32>240     fn idl_ipc_test_basic_106(&self, i_float: &f32) -> Result<f32> {
241         let mut data = MsgParcel::new().expect("MsgParcel should success");
242         data.write(&i_float)?;
243         let reply = self.remote.send_request(IIdlTestServiceCode::CodeIdlIpcTestBasic106 as u32, &data, false)?;
244         let result : f32 = reply.read()?;
245         Ok(result)
246     }
247 
idl_ipc_test_basic_107(&self, i_double: &f64) -> Result<f64>248     fn idl_ipc_test_basic_107(&self, i_double: &f64) -> Result<f64> {
249         let mut data = MsgParcel::new().expect("MsgParcel should success");
250         data.write(&i_double)?;
251         let reply = self.remote.send_request(IIdlTestServiceCode::CodeIdlIpcTestBasic107 as u32, &data, false)?;
252         let result : f64 = reply.read()?;
253         Ok(result)
254     }
255 
idl_ipc_test_basic_108(&self, i_string: &str) -> Result<String>256     fn idl_ipc_test_basic_108(&self, i_string: &str) -> Result<String> {
257         let mut data = MsgParcel::new().expect("MsgParcel should success");
258         data.write(&i_string)?;
259         let reply = self.remote.send_request(IIdlTestServiceCode::CodeIdlIpcTestBasic108 as u32, &data, false)?;
260         let result : String = reply.read()?;
261         Ok(result)
262     }
263 
idl_ipc_test_basic_199(&self, i_bool: &bool, i_long: &i64, i_float: &f32, i_double: &f64, i_string: &str) -> Result<bool>264     fn idl_ipc_test_basic_199(&self, i_bool: &bool, i_long: &i64, i_float: &f32,
265         i_double: &f64, i_string: &str) -> Result<bool> {
266         let mut data = MsgParcel::new().expect("MsgParcel should success");
267         data.write(&i_bool)?;
268         data.write(&i_long)?;
269         data.write(&i_float)?;
270         data.write(&i_double)?;
271         data.write(&i_string)?;
272         let reply = self.remote.send_request(IIdlTestServiceCode::CodeIdlIpcTestBasic199 as u32, &data, false)?;
273         let result : bool = reply.read()?;
274         Ok(result)
275     }
276 }
277