All of lore.kernel.org
 help / color / mirror / Atom feed
From: mtosatti@redhat.com
To: qemu-devel@nongnu.org
Cc: gleb@kernel.org, mprivozn@redhat.com,
	Marcelo Tosatti <mtosatti@redhat.com>,
	armbru@redhat.com, pbonzini@redhat.com
Subject: [Qemu-devel] [patch 2/3] add object_property_add_alias
Date: Mon, 02 Jun 2014 14:51:06 -0300	[thread overview]
Message-ID: <20140602175345.308193164@amt.cnet> (raw)
In-Reply-To: 20140602175104.579823673@amt.cnet

[-- Attachment #1: qom-add-alias --]
[-- Type: text/plain, Size: 4518 bytes --]

Allowing addition of a link without keeping pointer-to-pointer.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

Index: qemu/include/qom/object.h
===================================================================
--- qemu.orig/include/qom/object.h
+++ qemu/include/qom/object.h
@@ -1073,6 +1073,19 @@ typedef enum {
 } ObjectPropertyLinkFlags;
 
 /**
+ * object_property_add_alias:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @alias: the alias object
+ * @errp: if an error occurs, a pointer to an area to store the area
+ *
+ * Add a link under obj, named name, pointing to alias.
+ *
+ */
+void object_property_add_alias(Object *obj, const char *name,
+                               Object *alias, Error **errp);
+
+/**
  * object_property_allow_set_link:
  *
  * The default implementation of the object_property_add_link() check()
Index: qemu/qom/object.c
===================================================================
--- qemu.orig/qom/object.c
+++ qemu/qom/object.c
@@ -1023,27 +1023,71 @@ out:
     g_free(type);
 }
 
+typedef struct {
+    Object *child;
+    Object **childp;
+    void (*check)(Object *, const char *, Object *, Error **);
+    ObjectPropertyLinkFlags flags;
+} LinkProperty;
+
+static void object_get_alias_property(Object *obj, Visitor *v, void *opaque,
+                                      const char *name, Error **errp)
+{
+    LinkProperty *prop = opaque;
+    Object *child = prop->child;
+    gchar *path;
+
+    path = object_get_canonical_path(child);
+    visit_type_str(v, &path, name, errp);
+    g_free(path);
+}
+
+static void object_release_alias_property(Object *obj, const char *name,
+                                         void *opaque)
+{
+    LinkProperty *prop = opaque;
+
+    g_free(prop);
+}
+
+void object_property_add_alias(Object *obj, const char *name,
+                               Object *alias, Error **errp)
+{
+    Error *local_err = NULL;
+    gchar *type;
+    LinkProperty *prop = g_malloc(sizeof(*prop));
+
+    type = g_strdup_printf("link<%s>", object_get_typename(OBJECT(alias)));
+
+    prop->child = alias;
+    prop->check = NULL;
+    prop->flags = 0;
+
+    object_property_add(obj, name, type, object_get_alias_property, NULL,
+                        object_release_alias_property, prop, &local_err);
+    if (local_err) {
+        g_free(prop);
+        error_propagate(errp, local_err);
+    }
+
+    g_free(type);
+}
+
 void object_property_allow_set_link(Object *obj, const char *name,
                                     Object *val, Error **errp)
 {
     /* Allow the link to be set, always */
 }
 
-typedef struct {
-    Object **child;
-    void (*check)(Object *, const char *, Object *, Error **);
-    ObjectPropertyLinkFlags flags;
-} LinkProperty;
-
 static void object_get_link_property(Object *obj, Visitor *v, void *opaque,
                                      const char *name, Error **errp)
 {
     LinkProperty *lprop = opaque;
-    Object **child = lprop->child;
+    Object *child = lprop->child;
     gchar *path;
 
-    if (*child) {
-        path = object_get_canonical_path(*child);
+    if (child) {
+        path = object_get_canonical_path(child);
         visit_type_str(v, &path, name, errp);
         g_free(path);
     } else {
@@ -1096,7 +1140,7 @@ static void object_set_link_property(Obj
 {
     Error *local_err = NULL;
     LinkProperty *prop = opaque;
-    Object **child = prop->child;
+    Object **child = prop->childp;
     Object *old_target = *child;
     Object *new_target = NULL;
     char *path = NULL;
@@ -1133,8 +1177,8 @@ static void object_release_link_property
 {
     LinkProperty *prop = opaque;
 
-    if ((prop->flags & OBJ_PROP_LINK_UNREF_ON_RELEASE) && *prop->child) {
-        object_unref(*prop->child);
+    if ((prop->flags & OBJ_PROP_LINK_UNREF_ON_RELEASE) && prop->child) {
+        object_unref(prop->child);
     }
     g_free(prop);
 }
@@ -1150,7 +1194,8 @@ void object_property_add_link(Object *ob
     LinkProperty *prop = g_malloc(sizeof(*prop));
     gchar *full_type;
 
-    prop->child = child;
+    prop->childp = child;
+    prop->child = *child;
     prop->check = check;
     prop->flags = flags;
 
@@ -1227,7 +1272,7 @@ Object *object_resolve_path_component(Ob
 
     if (object_property_is_link(prop)) {
         LinkProperty *lprop = prop->opaque;
-        return *lprop->child;
+        return lprop->child;
     } else if (object_property_is_child(prop)) {
         return prop->opaque;
     } else {

  parent reply	other threads:[~2014-06-02 17:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20140530201145.194061806@amt.cnet>
2014-06-02 17:51 ` [Qemu-devel] [patch 0/3] add QMP command to reset rtc interrupt backlog (v3) mtosatti
2014-06-02 17:51   ` [Qemu-devel] [patch 1/3] mc146818rtc: add rtc_reset_reinjection QMP command mtosatti
2014-06-02 19:31     ` Eric Blake
2014-06-02 20:20       ` Marcelo Tosatti
2014-06-02 20:31         ` Eric Blake
2014-06-02 17:51   ` mtosatti [this message]
2014-06-02 17:51   ` [Qemu-devel] [patch 3/3] mc146818rtc: add "rtc" link to "/machine" mtosatti
2014-06-02 19:05   ` [Qemu-devel] [patch 0/3] add QMP command to reset rtc interrupt backlog (v3) Eric Blake
2014-06-02 19:20     ` Marcelo Tosatti
2014-06-02 19:41       ` Eric Blake
2014-06-04 17:52 [Qemu-devel] [patch 0/3] add QMP command to reset rtc interrupt backlog (v4) mtosatti
2014-06-04 17:52 ` [Qemu-devel] [patch 2/3] add object_property_add_alias mtosatti
2014-06-05 11:09   ` 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=20140602175345.308193164@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=armbru@redhat.com \
    --cc=gleb@kernel.org \
    --cc=mprivozn@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.