qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 4/7] machine: DEFINE_MACHINE macro


From: Eduardo Habkost
Subject: [Qemu-devel] [PATCH 4/7] machine: DEFINE_MACHINE macro
Date: Tue, 18 Aug 2015 12:08:51 -0700

The macro will allow easy registration of a TYPE_MACHINE subclass, using
only the machine name and a MachineClass initialization function as
parameter.

Signed-off-by: Eduardo Habkost <address@hidden>
---
 include/hw/boards.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/include/hw/boards.h b/include/hw/boards.h
index 3f84afd..95bcecd 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -152,4 +152,22 @@ struct MachineState {
     AccelState *accelerator;
 };
 
+#define DEFINE_MACHINE(namestr, machine_initfn) \
+    static void machine_initfn##_class_init(ObjectClass *oc, void *data) \
+    { \
+        MachineClass *mc = MACHINE_CLASS(oc); \
+        mc->name = namestr; \
+        machine_initfn(mc); \
+    } \
+    static const TypeInfo machine_initfn##_typeinfo = { \
+        .name       = namestr TYPE_MACHINE_SUFFIX, \
+        .parent     = TYPE_MACHINE, \
+        .class_init = machine_initfn##_class_init, \
+    }; \
+    static void machine_initfn##_register_types(void) \
+    { \
+        type_register_static(&machine_initfn##_typeinfo); \
+    } \
+    machine_init(machine_initfn##_register_types)
+
 #endif
-- 
2.1.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]