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
This commit is contained in:
Eduardo Habkost 2018-03-11 14:42:09 -04:00 committed by Lioncash
parent 46e1c5482b
commit 426b961644
No known key found for this signature in database
GPG Key ID: 4E3C3CC1031BA9C7

View File

@ -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