[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 4/6] chardev: implement realize
From: |
Anthony Liguori |
Subject: |
[Qemu-devel] [PATCH 4/6] chardev: implement realize |
Date: |
Mon, 15 Oct 2012 14:34:15 -0500 |
This can be used to initialize an object independently of setting properties.
This makes the 'open' method legacy.
Signed-off-by: Anthony Liguori <address@hidden>
---
qemu-char.c | 48 +++++++++++++++++++++++++++++++++++++++++++++---
qemu-char.h | 3 +++
2 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/qemu-char.c b/qemu-char.c
index 866c560..e9a81c7 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2981,9 +2981,13 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
chr = CHARDEV(object_new(class_name));
cdc = CHARDEV_GET_CLASS(chr);
- g_assert(cdc->open != NULL);
-
- cdc->open(chr, opts, &err);
+ if (cdc->open) {
+ cdc->open(chr, opts, &err);
+ } else {
+ if (!err) {
+ object_property_set_bool(OBJECT(chr), true, "realized", &err);
+ }
+ }
g_free(class_name);
@@ -3107,11 +3111,49 @@ CharDriverState *qemu_char_get_next_serial(void)
return serial_hds[next_serial++];
}
+static bool chardev_get_realized(Object *obj, Error **errp)
+{
+ CharDriverState *chr = CHARDEV(obj);
+
+ return chr->realized;
+}
+
+static void chardev_set_realized(Object *obj, bool value, Error **errp)
+{
+ CharDriverState *chr = CHARDEV(obj);
+ CharDriverClass *cdc = CHARDEV_GET_CLASS(chr);
+
+ if (chr->realized == value) {
+ return;
+ }
+
+ if (!value && chr->realized) {
+ error_set(errp, QERR_PERMISSION_DENIED);
+ } else {
+ Error *local_err = NULL;
+
+ g_assert(cdc->realize);
+ cdc->realize(chr, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ } else {
+ chr->realized = true;
+ }
+ }
+}
+
+static void chardev_initfn(Object *obj)
+{
+ object_property_add_bool(obj, "realized", chardev_get_realized,
+ chardev_set_realized, NULL);
+}
+
static const TypeInfo chardev_info = {
.name = TYPE_CHARDEV,
.parent = TYPE_OBJECT,
.instance_size = sizeof(CharDriverState),
.class_size = sizeof(CharDriverClass),
+ .instance_init = chardev_initfn,
};
static void register_types(void)
diff --git a/qemu-char.h b/qemu-char.h
index df7957d..be2a410 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -66,7 +66,9 @@ struct CharDriverClass
{
ObjectClass parent_class;
+ /* Objects should implement only one of these two methods */
void (*open)(struct CharDriverState *chr, QemuOpts *opts, Error **errp);
+ void (*realize)(struct CharDriverState *chr, QemuOpts *opts, Error **errp);
};
struct CharDriverState {
@@ -94,6 +96,7 @@ struct CharDriverState {
int opened;
int avail_connections;
QTAILQ_ENTRY(CharDriverState) next;
+ bool realized;
};
/**
--
1.7.5.4
- [Qemu-devel] [RFC PATCH 0/6] chardev: convert to QOM, Anthony Liguori, 2012/10/15
- [Qemu-devel] [PATCH 1/6] object: add object_property_add_bool, Anthony Liguori, 2012/10/15
- [Qemu-devel] [PATCH 5/6] chardev: switch the easy backends to realize, Anthony Liguori, 2012/10/15
- [Qemu-devel] [PATCH 3/6] chardev: create new QOM types for each sub chardev type, Anthony Liguori, 2012/10/15
- [Qemu-devel] [PATCH 6/6] chardev: convert file backend to realize, Anthony Liguori, 2012/10/15
- [Qemu-devel] [PATCH 2/6] chardev: convert to QOM (shallow pass), Anthony Liguori, 2012/10/15
- [Qemu-devel] [PATCH 4/6] chardev: implement realize,
Anthony Liguori <=
- Re: [Qemu-devel] [RFC PATCH 0/6] chardev: convert to QOM, Gerd Hoffmann, 2012/10/17