JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Huge refactor to prep for moving the daemon over to the plugin architecture

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨5df753c

⁨giterated-plugins/giterated-plugin/src/lib.rs⁩ - ⁨1635⁩ bytes
Raw
1 pub mod callback;
2 pub mod handle;
3 pub mod new_stack;
4 pub mod vtable;
5
6 #[macro_use]
7 extern crate tracing;
8
9 use std::{any::Any, fmt::Debug, mem::transmute, ptr::null_mut, sync::Arc};
10
11 use callback::{OperationHandlerCallback, SettingGetterCallback, ValueGetterCallback};
12 use dlopen2::wrapper::WrapperApi;
13 use giterated_models::{
14 object::GiteratedObject, operation::GiteratedOperation, settings::Setting,
15 value::GiteratedObjectValue,
16 };
17 use handle::PluginInitializationState;
18 use new_stack::{FFIPluginMeta, PluginState};
19
20 pub use vtable::{AnyFailure, AnyObject, AnyOperation, AnySuccess, NewAnySetting, NewAnyValue};
21 use vtable::{HostVTable, InitializationVTable};
22
23 #[derive(WrapperApi)]
24 pub struct GiteratedPluginApi {
25 plugin_meta: unsafe extern "C" fn() -> FFIPluginMeta,
26 load_host_vtable: unsafe extern "C" fn(vtable: &HostVTable),
27 load_initialization_vtable: unsafe extern "C" fn(vtable: &InitializationVTable),
28 initialize: unsafe extern "C" fn() -> PluginState,
29 initialize_registration: unsafe extern "C" fn(
30 init_state: *mut PluginInitializationState,
31 ) -> *mut PluginInitializationState,
32 }
33
34 #[repr(C)]
35 pub struct FFIBox<T: ?Sized>(*mut T);
36
37 impl<T: ?Sized> FFIBox<T> {
38 pub fn from_box(src: Box<T>) -> Self {
39 Self(Box::into_raw(src))
40 }
41
42 pub fn untyped(self) -> FFIBox<()> {
43 FFIBox(self.0 as *mut ())
44 }
45 }
46
47 impl<T: ?Sized> AsRef<T> for FFIBox<T> {
48 fn as_ref(&self) -> &T {
49 todo!()
50 }
51 }
52
53 impl<T: ?Sized> std::ops::Deref for FFIBox<T> {
54 type Target = T;
55
56 fn deref(&self) -> &Self::Target {
57 unsafe { self.0.as_ref() }.unwrap()
58 }
59 }
60