• 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 //! ExtraData data definitions of DRAG module.
17 
18 use crate::{
19     input_binding, input_binding::CExtraData
20 };
21 use fusion_data_rust::{
22     DragData, FusionResult
23 };
24 
25 impl CExtraData {
26     /// Create a CExtraData object
new(appended: bool) -> Self27     pub fn new(appended: bool) -> Self {
28         CExtraData {
29             appended,
30             buffer: std::ptr::null(),
31             buffer_size: 0usize,
32             source_type: -1i32,
33             pointer_id: -1i32,
34         }
35     }
36 
37     /// Set CExtraData appended property
set_appended(&mut self, appended: bool) -> &mut Self38     pub fn set_appended(&mut self, appended: bool) -> &mut Self {
39         self.appended = appended;
40         self
41     }
42 
43     /// Set CExtraData buffer property
set_buffer(&mut self, vec: &Vec<u8>) -> &mut Self44     pub fn set_buffer(&mut self, vec: &Vec<u8>) -> &mut Self {
45         let vec_ptr = vec.as_ptr();
46         self.buffer = vec_ptr;
47         self.buffer_size = vec.len();
48         self
49     }
50 
51     /// Set CExtraData source type property
set_source_type(&mut self, source_type: i32) -> &mut Self52     pub fn set_source_type(&mut self, source_type: i32) -> &mut Self {
53         self.source_type = source_type;
54         self
55     }
56 
57     /// Set CExtraData pointer id property
set_pointer_id(&mut self, pointer_id: i32) -> &mut Self58     pub fn set_pointer_id(&mut self, pointer_id: i32) -> &mut Self {
59         self.pointer_id = pointer_id;
60         self
61     }
62 }
63 
64 /// struct ExtraData
65 pub struct ExtraData {
66     inner: CExtraData,
67 }
68 
69 impl ExtraData {
70     /// Create a ExtraData object
new(appended: bool) -> Self71     pub fn new(appended: bool) -> Self {
72         Self {
73             inner: CExtraData::new(appended)
74         }
75     }
76 
77     /// The extra data information is sent to the external subsystem
appended_extra_data(&mut self, allow_appended: bool, drag_data: DragData) -> FusionResult<i32>78     pub fn appended_extra_data(&mut self, allow_appended: bool, drag_data: DragData) -> FusionResult<i32> {
79         let buffer: &Vec<u8>= &drag_data.buffer;
80         if buffer.is_empty() {
81             return Err(-1)
82         }
83         self.inner.set_appended(allow_appended)
84                   .set_buffer(buffer)
85                   .set_source_type(drag_data.source_type)
86                   .set_pointer_id(drag_data.pointer_id);
87 
88         // SAFETY:  no `None` here, cause `cextra_data` is valid
89         unsafe {
90             input_binding::CAppendExtraData(&self.inner);
91         }
92         Ok(0)
93     }
94 }