diff mbox

[4/7] machine: DEFINE_MACHINE macro

Message ID 1439924934-30491-5-git-send-email-ehabkost@redhat.com
State New
Headers show

Commit Message

Eduardo Habkost Aug. 18, 2015, 7:08 p.m. UTC
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>
---
 include/hw/boards.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Eduardo Habkost Aug. 20, 2015, 9:14 p.m. UTC | #1
On Tue, Aug 18, 2015 at 12:08:51PM -0700, Eduardo Habkost wrote:
> 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>

I will need to redo this patch after some other fixes I will submit
soon, so patches 4-7/7 can be dropped, by now.
diff mbox

Patch

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