From 426b96164487ef441f25e2befc05a5bcce7a0524 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Sun, 11 Mar 2018 14:42:09 -0400 Subject: [PATCH] machine: DEFINE_MACHINE() macro The macro will allow easy registration of a TYPE_MACHINE subclass, using only the machine name and a MachineClass initialization function as parameter. Backports commit ed0b6de343448d1014b53bcf541041373322fa1c from qemu --- qemu/include/hw/boards.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/qemu/include/hw/boards.h b/qemu/include/hw/boards.h index c0f1e9b1..4f3e0efc 100644 --- a/qemu/include/hw/boards.h +++ b/qemu/include/hw/boards.h @@ -129,6 +129,29 @@ struct MachineState { AccelState *accelerator; }; +#define DEFINE_MACHINE(namestr, machine_initfn) \ + static void machine_initfn##_class_init(struct uc_struct *uc, ObjectClass *oc, void *data) \ + { \ + MachineClass *mc = MACHINE_CLASS(uc, oc); \ + machine_initfn(mc); \ + } \ + static const TypeInfo machine_initfn##_typeinfo = { \ + MACHINE_TYPE_NAME(namestr), \ + TYPE_MACHINE, \ + 0, \ + 0, \ + NULL, \ + NULL, \ + NULL, \ + NULL, \ + NULL, \ + machine_initfn##_class_init, \ + }; \ + void machine_initfn##_register_types(struct uc_struct *uc) \ + { \ + type_register_static(uc, &machine_initfn##_typeinfo); \ + } + void machine_register_types(struct uc_struct *uc); #endif