From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: Eduardo Habkost <ehabkost@redhat.com>,
Marcel Apfelbaum <marcel@redhat.com>
Cc: "Philippe Mathieu-Daudé" <f4bug@amsat.org>,
qemu-devel@nongnu.org, "Markus Armbruster" <armbru@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
"Michael Roth" <mdroth@linux.vnet.ibm.com>,
"Paolo Bonzini" <pbonzini@redhat.com>
Subject: [Qemu-devel] [RFC PATCH 2/3] qdev: add helpers to be more explicit when using abstract QOM parent functions
Date: Sat, 13 Jan 2018 23:04:11 -0300 [thread overview]
Message-ID: <20180114020412.26160-3-f4bug@amsat.org> (raw)
In-Reply-To: <20180114020412.26160-1-f4bug@amsat.org>
QOM API learning curve is quite hard, in particular when devices inherit from
abstract parent.
To be more explicit about when a device class change the parent hooks, add few
helpers hoping a device class_init() will be easier to understand.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
include/hw/qdev-core.h | 10 ++++++++++
hw/core/qdev.c | 24 ++++++++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 83db53b3f5..0fc53b33d0 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -381,6 +381,16 @@ void qdev_machine_init(void);
*/
void device_reset(DeviceState *dev);
+void device_class_set_parent_reset(DeviceClass *dc,
+ DeviceReset dev_reset,
+ DeviceReset *parent_reset);
+void device_class_set_parent_realize(DeviceClass *dc,
+ DeviceRealize dev_realize,
+ DeviceRealize *parent_realize);
+void device_class_set_parent_unrealize(DeviceClass *dc,
+ DeviceUnrealize dev_unrealize,
+ DeviceUnrealize *parent_unrealize);
+
const struct VMStateDescription *qdev_get_vmsd(DeviceState *dev);
const char *qdev_fw_name(DeviceState *dev);
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 11112951a5..a71cd264e2 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -1140,6 +1140,30 @@ static void device_class_init(ObjectClass *class, void *data)
dc->user_creatable = true;
}
+void device_class_set_parent_reset(DeviceClass *dc,
+ DeviceReset dev_reset,
+ DeviceReset *parent_reset)
+{
+ *parent_reset = dc->reset;
+ dc->reset = dev_reset;
+}
+
+void device_class_set_parent_realize(DeviceClass *dc,
+ DeviceRealize dev_realize,
+ DeviceRealize *parent_realize)
+{
+ *parent_realize = dc->realize;
+ dc->realize = dev_realize;
+}
+
+void device_class_set_parent_unrealize(DeviceClass *dc,
+ DeviceUnrealize dev_unrealize,
+ DeviceUnrealize *parent_unrealize)
+{
+ *parent_unrealize = dc->unrealize;
+ dc->unrealize = dev_unrealize;
+}
+
void device_reset(DeviceState *dev)
{
DeviceClass *klass = DEVICE_GET_CLASS(dev);
--
2.15.1
next prev parent reply other threads:[~2018-01-14 2:04 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-14 2:04 [Qemu-devel] [RFC PATCH 0/3] add helpers to be more explicit when using QOM abstract parent hooks Philippe Mathieu-Daudé
2018-01-14 2:04 ` [Qemu-devel] [RFC PATCH 1/3] qdev: rename typedef qdev_resetfn() -> DeviceReset() Philippe Mathieu-Daudé
2018-01-15 9:45 ` Laurent Vivier
2018-01-14 2:04 ` Philippe Mathieu-Daudé [this message]
2018-01-15 9:41 ` [Qemu-devel] [RFC PATCH 2/3] qdev: add helpers to be more explicit when using abstract QOM parent functions Laurent Vivier
2018-01-14 2:04 ` [Qemu-devel] [RFC PATCH 3/3] qdev: use device_class_set_parent_realize/unrealize/reset() Philippe Mathieu-Daudé
2018-01-15 1:42 ` David Gibson
2018-01-15 9:09 ` [Qemu-devel] [qemu-s390x] " Cornelia Huck
2018-01-15 9:35 ` [Qemu-devel] " Laurent Vivier
2018-01-15 9:48 ` Marcel Apfelbaum
2018-01-15 11:08 ` [Qemu-devel] [RFC PATCH 0/3] add helpers to be more explicit when using QOM abstract parent hooks Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180114020412.26160-3-f4bug@amsat.org \
--to=f4bug@amsat.org \
--cc=armbru@redhat.com \
--cc=dgilbert@redhat.com \
--cc=ehabkost@redhat.com \
--cc=marcel@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).