|
@@ -9,15 +9,34 @@
|
|
|
use crate::bindings::{Object, ObjectClass, TypeInfo};
|
|
|
|
|
|
/// Trait a type must implement to be registered with QEMU.
|
|
|
-pub trait ObjectImpl {
|
|
|
- type Class;
|
|
|
- const TYPE_INFO: TypeInfo;
|
|
|
+pub trait ObjectImpl: Sized {
|
|
|
+ type Class: ClassInitImpl;
|
|
|
const TYPE_NAME: &'static CStr;
|
|
|
const PARENT_TYPE_NAME: Option<&'static CStr>;
|
|
|
const ABSTRACT: bool = false;
|
|
|
const INSTANCE_INIT: Option<unsafe extern "C" fn(obj: *mut Object)> = None;
|
|
|
const INSTANCE_POST_INIT: Option<unsafe extern "C" fn(obj: *mut Object)> = None;
|
|
|
const INSTANCE_FINALIZE: Option<unsafe extern "C" fn(obj: *mut Object)> = None;
|
|
|
+
|
|
|
+ const TYPE_INFO: TypeInfo = TypeInfo {
|
|
|
+ name: Self::TYPE_NAME.as_ptr(),
|
|
|
+ parent: if let Some(pname) = Self::PARENT_TYPE_NAME {
|
|
|
+ pname.as_ptr()
|
|
|
+ } else {
|
|
|
+ core::ptr::null_mut()
|
|
|
+ },
|
|
|
+ instance_size: core::mem::size_of::<Self>(),
|
|
|
+ instance_align: core::mem::align_of::<Self>(),
|
|
|
+ instance_init: Self::INSTANCE_INIT,
|
|
|
+ instance_post_init: Self::INSTANCE_POST_INIT,
|
|
|
+ instance_finalize: Self::INSTANCE_FINALIZE,
|
|
|
+ abstract_: Self::ABSTRACT,
|
|
|
+ class_size: core::mem::size_of::<Self::Class>(),
|
|
|
+ class_init: <Self::Class as ClassInitImpl>::CLASS_INIT,
|
|
|
+ class_base_init: <Self::Class as ClassInitImpl>::CLASS_BASE_INIT,
|
|
|
+ class_data: core::ptr::null_mut(),
|
|
|
+ interfaces: core::ptr::null_mut(),
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
/// Trait used to fill in a class struct.
|
|
@@ -83,28 +102,3 @@ extern "C" fn ctor_fn() {
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
-
|
|
|
-#[macro_export]
|
|
|
-macro_rules! type_info {
|
|
|
- ($t:ty) => {
|
|
|
- $crate::bindings::TypeInfo {
|
|
|
- name: <$t as $crate::definitions::ObjectImpl>::TYPE_NAME.as_ptr(),
|
|
|
- parent: if let Some(pname) = <$t as $crate::definitions::ObjectImpl>::PARENT_TYPE_NAME {
|
|
|
- pname.as_ptr()
|
|
|
- } else {
|
|
|
- ::core::ptr::null_mut()
|
|
|
- },
|
|
|
- instance_size: ::core::mem::size_of::<$t>(),
|
|
|
- instance_align: ::core::mem::align_of::<$t>(),
|
|
|
- instance_init: <$t as $crate::definitions::ObjectImpl>::INSTANCE_INIT,
|
|
|
- instance_post_init: <$t as $crate::definitions::ObjectImpl>::INSTANCE_POST_INIT,
|
|
|
- instance_finalize: <$t as $crate::definitions::ObjectImpl>::INSTANCE_FINALIZE,
|
|
|
- abstract_: <$t as $crate::definitions::ObjectImpl>::ABSTRACT,
|
|
|
- class_size: ::core::mem::size_of::<<$t as $crate::definitions::ObjectImpl>::Class>(),
|
|
|
- class_init: <<$t as $crate::definitions::ObjectImpl>::Class as $crate::definitions::ClassInitImpl>::CLASS_INIT,
|
|
|
- class_base_init: <<$t as $crate::definitions::ObjectImpl>::Class as $crate::definitions::ClassInitImpl>::CLASS_BASE_INIT,
|
|
|
- class_data: ::core::ptr::null_mut(),
|
|
|
- interfaces: ::core::ptr::null_mut(),
|
|
|
- };
|
|
|
- }
|
|
|
-}
|