rust_rcs_client/chat_bot/
ffi.rs

1// Copyright 2023 宋昊文
2//
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
15use std::ptr::NonNull;
16
17use libc::c_char;
18
19pub type RetrieveSpecificChatbotsResultCallback = extern "C" fn(
20    status_code: u16,
21    reason_phrase: *const c_char,
22    specific_chatbots: *const c_char,
23    response_etag: *const c_char,
24    expiry: u32,
25    context: *mut RetrieveSpecificChatbotsResultCallbackContext,
26);
27
28#[repr(C)]
29pub struct RetrieveSpecificChatbotsResultCallbackContext {
30    _data: [u8; 0],
31    _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
32}
33
34#[cfg(any(
35    all(feature = "android", target_os = "android"),
36    all(feature = "ohos", all(target_os = "linux", target_env = "ohos"))
37))]
38extern "C" {
39    fn retrieve_specific_chatbots_result_callback_context_release(
40        context: *mut RetrieveSpecificChatbotsResultCallbackContext,
41    );
42}
43
44pub struct RetrieveSpecificChatbotsResultCallbackContextWrapper(
45    pub NonNull<RetrieveSpecificChatbotsResultCallbackContext>,
46);
47
48impl Drop for RetrieveSpecificChatbotsResultCallbackContextWrapper {
49    fn drop(&mut self) {
50        #[cfg(any(
51            all(feature = "android", target_os = "android"),
52            all(feature = "ohos", all(target_os = "linux", target_env = "ohos"))
53        ))]
54        let cb_context = self.0.as_ptr();
55        #[cfg(any(
56            all(feature = "android", target_os = "android"),
57            all(feature = "ohos", all(target_os = "linux", target_env = "ohos"))
58        ))]
59        unsafe {
60            retrieve_specific_chatbots_result_callback_context_release(cb_context);
61        }
62    }
63}
64
65unsafe impl Send for RetrieveSpecificChatbotsResultCallbackContextWrapper {}
66
67pub type SearchChatbotResultCallback = extern "C" fn(
68    status_code: u16,
69    reason_phrase: *const c_char,
70    chatbot_search_result_list_json: *const c_char,
71    context: *mut SearchChatbotResultCallbackContext,
72);
73
74#[repr(C)]
75pub struct SearchChatbotResultCallbackContext {
76    _data: [u8; 0],
77    _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
78}
79
80#[cfg(any(
81    all(feature = "android", target_os = "android"),
82    all(feature = "ohos", all(target_os = "linux", target_env = "ohos"))
83))]
84extern "C" {
85    fn search_chatbot_result_callback_context_release(
86        context: *mut SearchChatbotResultCallbackContext,
87    );
88}
89
90pub struct SearchChatbotResultCallbackContextWrapper(
91    pub NonNull<SearchChatbotResultCallbackContext>,
92);
93
94impl Drop for SearchChatbotResultCallbackContextWrapper {
95    fn drop(&mut self) {
96        #[cfg(any(
97            all(feature = "android", target_os = "android"),
98            all(feature = "ohos", all(target_os = "linux", target_env = "ohos"))
99        ))]
100        let cb_context = self.0.as_ptr();
101        #[cfg(any(
102            all(feature = "android", target_os = "android"),
103            all(feature = "ohos", all(target_os = "linux", target_env = "ohos"))
104        ))]
105        unsafe {
106            search_chatbot_result_callback_context_release(cb_context);
107        }
108    }
109}
110
111unsafe impl Send for SearchChatbotResultCallbackContextWrapper {}
112
113pub type RetrieveChatbotInfoResultCallback = extern "C" fn(
114    status_code: u16,
115    reason_phrase: *const c_char,
116    chatbot_info: *const c_char,
117    response_etag: *const c_char,
118    expiry: u32,
119    context: *mut RetrieveChatbotInfoResultCallbackContext,
120);
121
122#[repr(C)]
123pub struct RetrieveChatbotInfoResultCallbackContext {
124    _data: [u8; 0],
125    _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
126}
127
128#[cfg(any(
129    all(feature = "android", target_os = "android"),
130    all(feature = "ohos", all(target_os = "linux", target_env = "ohos"))
131))]
132extern "C" {
133    fn retrieve_chatbot_info_result_callback_context_release(
134        context: *mut RetrieveChatbotInfoResultCallbackContext,
135    );
136}
137
138pub struct RetrieveChatbotInfoResultCallbackContextWrapper(
139    pub NonNull<RetrieveChatbotInfoResultCallbackContext>,
140);
141
142impl Drop for RetrieveChatbotInfoResultCallbackContextWrapper {
143    fn drop(&mut self) {
144        #[cfg(any(
145            all(feature = "android", target_os = "android"),
146            all(feature = "ohos", all(target_os = "linux", target_env = "ohos"))
147        ))]
148        let cb_context = self.0.as_ptr();
149        #[cfg(any(
150            all(feature = "android", target_os = "android"),
151            all(feature = "ohos", all(target_os = "linux", target_env = "ohos"))
152        ))]
153        unsafe {
154            retrieve_chatbot_info_result_callback_context_release(cb_context);
155        }
156    }
157}
158
159unsafe impl Send for RetrieveChatbotInfoResultCallbackContextWrapper {}