1use std::{ffi::c_char, ptr::NonNull};
16
17use crate::messaging::cpm::MessagingSessionHandle;
18
19pub type StateChangeCallback = extern "C" fn(state: i32, context: *mut StateChangeCallbackContext);
20
21#[repr(C)]
22pub struct StateChangeCallbackContext {
23 _data: [u8; 0],
24 _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
25}
26
27#[cfg(any(
28 all(feature = "android", target_os = "android"),
29 all(feature = "ohos", all(target_os = "linux", target_env = "ohos"))
30))]
31extern "C" {
32 fn state_change_callback_context_release(context: *mut StateChangeCallbackContext);
33}
34
35pub struct StateChangeCallbackContextWrapper(pub NonNull<StateChangeCallbackContext>);
36
37impl Drop for StateChangeCallbackContextWrapper {
38 fn drop(&mut self) {
39 #[cfg(any(
40 all(feature = "android", target_os = "android"),
41 all(feature = "ohos", all(target_os = "linux", target_env = "ohos"))
42 ))]
43 let cb_context = self.0.as_ptr();
44 #[cfg(any(
45 all(feature = "android", target_os = "android"),
46 all(feature = "ohos", all(target_os = "linux", target_env = "ohos"))
47 ))]
48 unsafe {
49 state_change_callback_context_release(cb_context);
50 }
51 }
52}
53
54unsafe impl Send for StateChangeCallbackContextWrapper {}
55
56pub type MessageCallback = extern "C" fn(
57 i32,
58 Option<Box<MessagingSessionHandle>>,
59 *const c_char,
60 *const c_char,
61 *const c_char,
62 *const c_char,
63 *const c_char,
64 *const c_char,
65 context: *mut MessageCallbackContext,
66);
67
68#[repr(C)]
69pub struct MessageCallbackContext {
70 _data: [u8; 0],
71 _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
72}
73
74#[cfg(any(
75 all(feature = "android", target_os = "android"),
76 all(feature = "ohos", all(target_os = "linux", target_env = "ohos"))
77))]
78extern "C" {
79 fn message_callback_context_release(context: *mut MessageCallbackContext);
80}
81
82pub struct MessageCallbackContextWrapper(pub NonNull<MessageCallbackContext>);
83
84impl Drop for MessageCallbackContextWrapper {
85 fn drop(&mut self) {
86 #[cfg(any(
87 all(feature = "android", target_os = "android"),
88 all(feature = "ohos", all(target_os = "linux", target_env = "ohos"))
89 ))]
90 let cb_context = self.0.as_ptr();
91 #[cfg(any(
92 all(feature = "android", target_os = "android"),
93 all(feature = "ohos", all(target_os = "linux", target_env = "ohos"))
94 ))]
95 unsafe {
96 message_callback_context_release(cb_context);
97 }
98 }
99}
100
101unsafe impl Send for MessageCallbackContextWrapper {}