mod operation; use giterated_models::{ error::OperationError, object::{GiteratedObject, Object, ObjectRequestError}, object_backend::ObjectBackend, operation::{GiteratedOperation, OperationState}, }; use std::fmt::Debug; pub use operation::*; mod value; pub use value::*; mod setting; pub use setting::*; use crate::{ new_stack::{PluginState, Runtime}, vtable::RuntimeVTable, AnyObject, AnyOperation, }; /// A container for a callback pointer, used to provide an internal callback function or /// state to a plugin when performing a callback. #[derive(Clone, Copy)] #[repr(C)] pub struct CallbackPtr(*const ()); impl CallbackPtr { pub unsafe fn from_raw(callback: *const ()) -> Self { Self(callback) } } #[derive(Clone)] #[repr(C)] pub struct RuntimeState { pub vtable: RuntimeVTable, } impl RuntimeState { pub unsafe fn from_static() -> Self { let runtime = giterated_static_runtime::get_runtime_reference(); let runtime = runtime.cast::>().as_ref(); runtime.state() } pub unsafe fn runtime_state() -> PluginState { let runtime = giterated_static_runtime::get_runtime_reference(); PluginState::from_raw_ptr(giterated_static_runtime::get_runtime_reference().as_ptr()) } } #[async_trait::async_trait(?Send)] impl ObjectBackend for RuntimeState { async fn object_operation( &self, object: O, _operation: &str, payload: D, _operation_state: &OperationState, ) -> Result> where O: GiteratedObject + Debug + 'static, D: GiteratedOperation + Debug + 'static, D::Success: Clone, D::Failure: Clone, { let _object = AnyObject::new(object); let _operation = AnyOperation::new(payload); todo!() } async fn get_object( &self, object_str: &str, operation_state: &OperationState, ) -> Result, OperationError> { let object = unsafe { (self.vtable.get_object)( Self::runtime_state(), object_str, &mut operation_state.clone(), ) }?; let object = unsafe { object.cast::() }; panic!("object casted"); Ok(unsafe { Object::new_unchecked(object, self.clone()) }) } }