From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com,
mimu@linux.vnet.ibm.com, bharata@linux.vnet.ibm.com,
agraf@suse.de, borntraeger@de.ibm.com,
"Paolo Bonzini" <pbonzini@redhat.com>,
cornelia.huck@de.ibm.com, "Igor Mammedov" <imammedo@redhat.com>,
"Andreas Färber" <afaerber@suse.de>,
david@gibson.dropbear.id.au
Subject: [Qemu-devel] [PATCH v2 1/2] qom: Implement object_property_add_const_link()
Date: Fri, 1 May 2015 11:09:06 -0300 [thread overview]
Message-ID: <1430489347-13772-2-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1430489347-13772-1-git-send-email-ehabkost@redhat.com>
It can be used in simpler cases where a read-only property is needed.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
include/qom/object.h | 23 +++++++++++++++++++++++
qom/object.c | 15 +++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/include/qom/object.h b/include/qom/object.h
index d2d7748..78bb941 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1123,6 +1123,8 @@ void object_property_add_child(Object *obj, const char *name,
typedef enum {
/* Unref the link pointer when the property is deleted */
OBJ_PROP_LINK_UNREF_ON_RELEASE = 0x1,
+ /* Free the child pointer passed to object_property_add_link() */
+ OBJ_PROP_LINK_FREE_CHILD_POINTER = 0x2,
} ObjectPropertyLinkFlags;
/**
@@ -1162,6 +1164,8 @@ void object_property_allow_set_link(Object *, const char *,
* property is deleted with object_property_del(). If the
* <code>@flags</code> <code>OBJ_PROP_LINK_UNREF_ON_RELEASE</code> bit is set,
* the reference count is decremented when the property is deleted.
+ * If the <code>OBJ_PROP_LINK_FREE_CHILD_POINTER</code> bit is set,
+ * @child is freed when the property is deleted.
*/
void object_property_add_link(Object *obj, const char *name,
const char *type, Object **child,
@@ -1170,6 +1174,25 @@ void object_property_add_link(Object *obj, const char *name,
ObjectPropertyLinkFlags flags,
Error **errp);
+
+/**
+ * object_property_add_const_link:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @type: the qobj type of the link
+ * @child: pointer to the linked object
+ * @flags: additional options for the link
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Like object_property_add_link(), but adds a link property that will
+ * always point to the same object.
+ */
+void object_property_add_const_link(Object *obj, const char *name,
+ const char *type, Object *child,
+ ObjectPropertyLinkFlags flags,
+ Error **errp);
+
+
/**
* object_property_add_str:
* @obj: the object to add a property to
diff --git a/qom/object.c b/qom/object.c
index b8dff43..7d4a46d 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1227,6 +1227,9 @@ static void object_release_link_property(Object *obj, const char *name,
if ((prop->flags & OBJ_PROP_LINK_UNREF_ON_RELEASE) && *prop->child) {
object_unref(*prop->child);
}
+ if (prop->flags & OBJ_PROP_LINK_FREE_CHILD_POINTER) {
+ g_free(prop->child);
+ }
g_free(prop);
}
@@ -1266,6 +1269,18 @@ out:
g_free(full_type);
}
+void object_property_add_const_link(Object *obj, const char *name,
+ const char *type, Object *child,
+ ObjectPropertyLinkFlags flags,
+ Error **errp)
+{
+ Object **childp = g_new0(Object*, 1);
+
+ *childp = child;
+ object_property_add_link(obj, name, type, childp, NULL,
+ flags | OBJ_PROP_LINK_FREE_CHILD_POINTER, errp);
+}
+
gchar *object_get_canonical_path_component(Object *obj)
{
ObjectProperty *prop = NULL;
--
2.1.0
next prev parent reply other threads:[~2015-05-01 14:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-01 14:09 [Qemu-devel] [PATCH v2 0/2] cpu: Add /machine/cpus[<index>] links Eduardo Habkost
2015-05-01 14:09 ` Eduardo Habkost [this message]
2015-05-01 18:15 ` [Qemu-devel] [PATCH v2 1/2] qom: Implement object_property_add_const_link() Paolo Bonzini
2015-05-05 16:06 ` Eduardo Habkost
2015-05-05 16:21 ` Paolo Bonzini
2015-05-01 14:09 ` [Qemu-devel] [PATCH v2 2/2] cpu: Register QOM links at /machine/cpus[<index>] Eduardo Habkost
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=1430489347-13772-2-git-send-email-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=afaerber@suse.de \
--cc=agraf@suse.de \
--cc=bharata@linux.vnet.ibm.com \
--cc=borntraeger@de.ibm.com \
--cc=cornelia.huck@de.ibm.com \
--cc=david@gibson.dropbear.id.au \
--cc=imammedo@redhat.com \
--cc=mimu@linux.vnet.ibm.com \
--cc=pbonzini@redhat.com \
--cc=peter.crosthwaite@xilinx.com \
--cc=peter.maydell@linaro.org \
--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).