diff mbox

[PULL,17/21] machine: DEFINE_MACHINE() macro

Message ID 1442673810-2679-18-git-send-email-afaerber@suse.de
State New
Headers show

Commit Message

Andreas Färber Sept. 19, 2015, 2:43 p.m. UTC
From: Eduardo Habkost <ehabkost@redhat.com>

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 <ehabkost@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 include/hw/boards.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
diff mbox

Patch

diff --git a/include/hw/boards.h b/include/hw/boards.h
index 586f939..4fe2ce5 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -159,4 +159,21 @@  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); \
+        machine_initfn(mc); \
+    } \
+    static const TypeInfo machine_initfn##_typeinfo = { \
+        .name       = MACHINE_TYPE_NAME(namestr), \
+        .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