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 use std::ffi::{ c_char, CString };
17 
18 use hilog_rust::{ debug, error, hilog, HiLogLabel, LogType };
19 
20 use fusion_utils_rust::{ FusionResult, FusionErrorCode };
21 
22 use crate::input_binding;
23 use crate::input_binding::CPointerStyle;
24 
25 const LOG_LABEL: HiLogLabel = HiLogLabel {
26     log_type: LogType::LogCore,
27     domain: 0xD002220,
28     tag: "RustPointerStyle"
29 };
30 const INPUT_BINDING_OK: i32 = 0;
31 
32 impl Default for CPointerStyle {
default() -> Self33     fn default() -> Self {
34         Self::new()
35     }
36 }
37 
38 impl CPointerStyle {
39     /// Create a CPointerStyle object.
new() -> Self40     pub fn new() -> Self {
41         Self {
42             size: -1,
43             color: 0,
44             id: 0,
45         }
46     }
47 }
48 
49 /// Struct pointer style.
50 pub struct PointerStyle {
51     inner: CPointerStyle,
52 }
53 
54 impl Default for PointerStyle {
default() -> Self55     fn default() -> Self {
56         Self::new()
57     }
58 }
59 
60 impl PointerStyle {
61     /// Create a PointerStyle object.
new() -> Self62     pub fn new() -> Self {
63         Self {
64             inner: CPointerStyle::default()
65         }
66     }
67 
68     /// Get the pointer style from the PointerStyle.
pointer_style(&mut self) -> FusionResult<()>69     pub fn pointer_style(&mut self) -> FusionResult<()> {
70         // SAFETY:  no `None` here, cause `CPointerStyle` is valid.
71         unsafe {
72             if input_binding::CGetPointerStyle(&mut self.inner) != INPUT_BINDING_OK {
73                 error!(LOG_LABEL, "Get pointer style failed");
74                 return Err(FusionErrorCode::Fail);
75             }
76             debug!(LOG_LABEL, "Get pointer style success");
77             Ok(())
78         }
79     }
80 }