qom: add helper macro DEFINE_TYPES()
commit38b5d79b2e8cf6085324066d84e8bb3b3bbe8548
authorIgor Mammedov <imammedo@redhat.com>
Mon, 9 Oct 2017 19:50:50 +0000 (9 21:50 +0200)
committerDavid Gibson <david@gibson.dropbear.id.au>
Mon, 16 Oct 2017 23:34:00 +0000 (17 10:34 +1100)
tree97b9f23f52fd0290d230cec1197a55057c1e19f1
parentaa04c9d20704fa5b9ab239d5111adbcce5f49808
qom: add helper macro DEFINE_TYPES()

DEFINE_TYPES() will help to simplify following routine patterns:

 static void foo_register_types(void)
 {
    type_register_static(&foo1_type_info);
    type_register_static(&foo2_type_info);
    ...
 }

 type_init(foo_register_types)

or

 static void foo_register_types(void)
 {
    int i;

    for (i = 0; i < ARRAY_SIZE(type_infos); i++) {
        type_register_static(&type_infos[i]);
    }
 }

 type_init(foo_register_types)

with a single line

 DEFINE_TYPES(type_infos)

where types have static definition which could be consolidated in
a single array of TypeInfo structures.
It saves us ~6-10LOC per use case and would help to replace
imperative foo_register_types() there with declarative style of
type registration.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
include/qom/object.h