emf_core_base_rs_ffi/sys/
api.rs1use crate::collections::{NonNullConst, Optional};
5use crate::sys::sync_handler::SyncHandlerInterface;
6use crate::{Bool, CBase, CBaseFn, CBaseInterface, FnId, TypeWrapper};
7use std::ptr::NonNull;
8
9pub type ShutdownFn =
10 TypeWrapper<unsafe extern "C-unwind" fn(base_module: Option<NonNull<CBase>>) -> !>;
11
12pub type PanicFn = TypeWrapper<
13 unsafe extern "C-unwind" fn(
14 base_module: Option<NonNull<CBase>>,
15 error: Option<NonNullConst<u8>>,
16 ) -> !,
17>;
18
19pub type HasFunctionFn =
20 TypeWrapper<unsafe extern "C-unwind" fn(base_module: Option<NonNull<CBase>>, id: FnId) -> Bool>;
21
22pub type GetFunctionFn = TypeWrapper<
23 unsafe extern "C-unwind" fn(base_module: Option<NonNull<CBase>>, id: FnId) -> Optional<CBaseFn>,
24>;
25
26pub type LockFn = TypeWrapper<unsafe extern "C-unwind" fn(base_module: Option<NonNull<CBase>>)>;
27
28pub type TryLockFn =
29 TypeWrapper<unsafe extern "C-unwind" fn(base_module: Option<NonNull<CBase>>) -> Bool>;
30
31pub type UnlockFn = TypeWrapper<unsafe extern "C-unwind" fn(base_module: Option<NonNull<CBase>>)>;
32
33pub type GetSyncHandlerFn = TypeWrapper<
34 unsafe extern "C-unwind" fn(
35 base_module: Option<NonNull<CBase>>,
36 ) -> NonNullConst<SyncHandlerInterface>,
37>;
38
39pub type SetSyncHandlerFn = TypeWrapper<
40 unsafe extern "C-unwind" fn(
41 base_module: Option<NonNull<CBase>>,
42 handler: Option<NonNullConst<SyncHandlerInterface>>,
43 ),
44>;
45
46pub trait SysBinding {
48 unsafe fn shutdown(&mut self) -> !;
54
55 unsafe fn panic(&self, error: Option<NonNullConst<u8>>) -> !;
61
62 unsafe fn has_function(&self, id: FnId) -> Bool;
72
73 unsafe fn get_function(&self, id: FnId) -> Optional<CBaseFn>;
83
84 unsafe fn lock(&self);
93
94 unsafe fn try_lock(&self) -> Bool;
106
107 unsafe fn unlock(&self);
114
115 unsafe fn get_sync_handler(&self) -> NonNullConst<SyncHandlerInterface>;
125
126 unsafe fn set_sync_handler(&mut self, handler: Option<NonNullConst<SyncHandlerInterface>>);
152}
153
154impl SysBinding for CBaseInterface {
155 #[inline]
156 unsafe fn shutdown(&mut self) -> ! {
157 (self.sys_shutdown_fn)(self.base_module)
158 }
159
160 #[inline]
161 unsafe fn panic(&self, error: Option<NonNullConst<u8>>) -> ! {
162 (self.sys_panic_fn)(self.base_module, error)
163 }
164
165 #[inline]
166 unsafe fn has_function(&self, id: FnId) -> Bool {
167 (self.sys_has_function_fn)(self.base_module, id)
168 }
169
170 #[inline]
171 unsafe fn get_function(&self, id: FnId) -> Optional<CBaseFn> {
172 (self.sys_get_function_fn)(self.base_module, id)
173 }
174
175 #[inline]
176 unsafe fn lock(&self) {
177 (self.sys_lock_fn)(self.base_module)
178 }
179
180 #[inline]
181 unsafe fn try_lock(&self) -> Bool {
182 (self.sys_try_lock_fn)(self.base_module)
183 }
184
185 #[inline]
186 unsafe fn unlock(&self) {
187 (self.sys_unlock_fn)(self.base_module)
188 }
189
190 #[inline]
191 unsafe fn get_sync_handler(&self) -> NonNullConst<SyncHandlerInterface> {
192 (self.sys_get_sync_handler_fn)(self.base_module)
193 }
194
195 #[inline]
196 unsafe fn set_sync_handler(&mut self, handler: Option<NonNullConst<SyncHandlerInterface>>) {
197 (self.sys_set_sync_handler_fn)(self.base_module, handler)
198 }
199}