From ed0b6de343448d1014b53bcf541041373322fa1c Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Fri, 4 Sep 2015 15:37:06 -0300 Subject: [PATCH] machine: DEFINE_MACHINE() macro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Andreas Färber --- include/hw/boards.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/hw/boards.h b/include/hw/boards.h index 586f939a57..4fe2ce5235 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