From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:44486) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYITt-0001I5-JP for qemu-devel@nongnu.org; Fri, 03 May 2013 12:05:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UYITs-0007d3-D1 for qemu-devel@nongnu.org; Fri, 03 May 2013 12:05:09 -0400 Received: from mail-ve0-x230.google.com ([2607:f8b0:400c:c01::230]:36960) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYITs-0007cy-75 for qemu-devel@nongnu.org; Fri, 03 May 2013 12:05:08 -0400 Received: by mail-ve0-f176.google.com with SMTP id b10so1629224vea.21 for ; Fri, 03 May 2013 09:05:07 -0700 (PDT) Sender: fluxion From: Michael Roth Date: Fri, 3 May 2013 11:03:45 -0500 Message-Id: <1367597032-28934-3-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1367597032-28934-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1367597032-28934-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 2/9] qom: add object_property_add_unnamed_child List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, aliguori@us.ibm.com, qemulist@gmail.com, stefanha@redhat.com This interface allows us to add a child property without specifying a name. Instead, a unique name is created and passed back after adding the property. Signed-off-by: Michael Roth --- include/qom/object.h | 16 ++++++++++++++++ qom/object.c | 25 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index 86f1e2e..ca0fce8 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1041,6 +1041,22 @@ void object_property_add_child(Object *obj, const char *name, Object *child, struct Error **errp); /** + * object_property_add_unnamed_child: + * + * @obj: the object to add a property to + * @name: the name of the property + * @child: the child object + * @errp: if an error occurs, a pointer to an area to store the area + * + * Same as object_property_add_child, but will allocate a unique name to + * identify the child property. + * + * Returns: The name assigned to the child property, or NULL on failure. + */ +char *object_property_add_unnamed_child(Object *obj, Object *child, + struct Error **errp); + +/** * object_property_add_link: * @obj: the object to add a property to * @name: the name of the property diff --git a/qom/object.c b/qom/object.c index c932f64..229a9a7 100644 --- a/qom/object.c +++ b/qom/object.c @@ -926,6 +926,31 @@ static void object_finalize_child_property(Object *obj, const char *name, object_unref(child); } +char *object_property_add_unnamed_child(Object *obj, Object *child, Error **errp) +{ + int idx = 0; + bool next_idx_found = false; + char name[64]; + ObjectProperty *prop; + + while (!next_idx_found) { + sprintf(name, "unnamed[%d]", idx); + QTAILQ_FOREACH(prop, &obj->properties, node) { + if (strcmp(name, prop->name) == 0) { + idx++; + break; + } + } + if (!prop) { + next_idx_found = true; + } + } + + object_property_add_child(obj, name, child, errp); + + return error_is_set(errp) ? NULL : g_strdup(name); +} + void object_property_add_child(Object *obj, const char *name, Object *child, Error **errp) { -- 1.7.9.5