aboutsummaryrefslogtreecommitdiff
path: root/rust/qemu-api/tests/tests.rs
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2024-10-28 10:29:27 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2024-12-10 18:49:26 +0100
commit8c80c472da6342c5924bc4ea7e87c77ca61477b8 (patch)
tree4343d0f5b9df3868acc1b3e2c272154da39408f8 /rust/qemu-api/tests/tests.rs
parentc6c4f3e0d90990c642523c087482eac3f42566c1 (diff)
downloadqemu-8c80c472da6342c5924bc4ea7e87c77ca61477b8.zip
qemu-8c80c472da6342c5924bc4ea7e87c77ca61477b8.tar.gz
qemu-8c80c472da6342c5924bc4ea7e87c77ca61477b8.tar.bz2
rust: qdev: move device_class_init! body to generic function, ClassInitImpl implementation to macro
Use a trait to access the former parameters to device_class_init!. This allows hiding the details of the class_init implementation behind a generic function and makes higher-level functionality available from qemu_api. The implementation of ClassInitImpl is then the same for all devices and is easily macroized. Later on, we can remove the need to implement ClassInitImpl by hand for all device types, and stop making rust_device_class_init<>() public. While at it, document the members of DeviceImpl. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'rust/qemu-api/tests/tests.rs')
-rw-r--r--rust/qemu-api/tests/tests.rs30
1 files changed, 13 insertions, 17 deletions
diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs
index fd0c979..b8b12a4 100644
--- a/rust/qemu-api/tests/tests.rs
+++ b/rust/qemu-api/tests/tests.rs
@@ -2,13 +2,14 @@
// Author(s): Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
// SPDX-License-Identifier: GPL-2.0-or-later
-use std::{ffi::CStr, os::raw::c_void};
+use std::ffi::CStr;
use qemu_api::{
bindings::*,
c_str, declare_properties, define_property,
- definitions::{ClassInitImpl, ObjectImpl},
- device_class, device_class_init,
+ definitions::ObjectImpl,
+ device_class::{self, DeviceImpl},
+ impl_device_class,
zeroable::Zeroable,
};
@@ -45,28 +46,23 @@ fn test_device_decl_macros() {
),
}
- device_class_init! {
- dummy_class_init,
- props => DUMMY_PROPERTIES,
- realize_fn => None,
- legacy_reset_fn => None,
- vmsd => VMSTATE,
- }
-
impl ObjectImpl for DummyState {
type Class = DummyClass;
const TYPE_NAME: &'static CStr = c_str!("dummy");
const PARENT_TYPE_NAME: Option<&'static CStr> = Some(device_class::TYPE_DEVICE);
}
- impl ClassInitImpl for DummyState {
- const CLASS_INIT: Option<unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut c_void)> =
- Some(dummy_class_init);
- const CLASS_BASE_INIT: Option<
- unsafe extern "C" fn(klass: *mut ObjectClass, data: *mut c_void),
- > = None;
+ impl DeviceImpl for DummyState {
+ fn properties() -> &'static [Property] {
+ &DUMMY_PROPERTIES
+ }
+ fn vmsd() -> Option<&'static VMStateDescription> {
+ Some(&VMSTATE)
+ }
}
+ impl_device_class!(DummyState);
+
unsafe {
module_call_init(module_init_type::MODULE_INIT_QOM);
object_unref(object_new(DummyState::TYPE_NAME.as_ptr()).cast());