Received: from eggs.gnu.org ([2001:4830:134:3::10]:39419) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZRmGl-0007DW-4M for qemu-devel@nongnu.org; Tue, 18 Aug 2015 15:10:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZRmGh-0005fL-Ai for qemu-devel@nongnu.org; Tue, 18 Aug 2015 15:09:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34489) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZRmGh-0005fE-5b for qemu-devel@nongnu.org; Tue, 18 Aug 2015 15:09:55 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id D04039175B for ; Tue, 18 Aug 2015 19:09:54 +0000 (UTC) From: Eduardo Habkost Date: Tue, 18 Aug 2015 12:08:51 -0700 Message-Id: <1439924934-30491-5-git-send-email-ehabkost@redhat.com> In-Reply-To: <1439924934-30491-1-git-send-email-ehabkost@redhat.com> References: <1439924934-30491-1-git-send-email-ehabkost@redhat.com> Subject: [Qemu-devel] [PATCH 4/7] machine: DEFINE_MACHINE macro List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , "Michael S. Tsirkin" 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 --- include/hw/boards.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 -- 2.1.0