From patchwork Wed Nov 30 21:03:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 128581 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BB01FB6F67 for ; Thu, 1 Dec 2011 08:05:14 +1100 (EST) Received: from localhost ([::1]:37422 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RVrKp-00065T-E0 for incoming@patchwork.ozlabs.org; Wed, 30 Nov 2011 16:04:55 -0500 Received: from eggs.gnu.org ([140.186.70.92]:35181) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RVrKW-0005e8-CQ for qemu-devel@nongnu.org; Wed, 30 Nov 2011 16:04:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RVrKV-0000YT-0a for qemu-devel@nongnu.org; Wed, 30 Nov 2011 16:04:36 -0500 Received: from cpe-70-123-132-139.austin.res.rr.com ([70.123.132.139]:37005 helo=localhost6.localdomain6) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RVrKU-0000YP-M3 for qemu-devel@nongnu.org; Wed, 30 Nov 2011 16:04:34 -0500 Received: from localhost6.localdomain6 (localhost.localdomain [127.0.0.1]) by localhost6.localdomain6 (8.14.4/8.14.4/Debian-2ubuntu1) with ESMTP id pAUL4NN1030024; Wed, 30 Nov 2011 15:04:23 -0600 Received: (from anthony@localhost) by localhost6.localdomain6 (8.14.4/8.14.4/Submit) id pAUL4Llw030021; Wed, 30 Nov 2011 15:04:21 -0600 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Wed, 30 Nov 2011 15:03:37 -0600 Message-Id: <1322687028-29714-8-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1322687028-29714-1-git-send-email-aliguori@us.ibm.com> References: <1322687028-29714-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 70.123.132.139 Cc: Kevin Wolf , Peter Maydell , Anthony Liguori , Stefan Hajnoczi , Jan Kiszka , Markus Armbruster , Luiz Capitulino Subject: [Qemu-devel] [PATCH 07/18] qom: add link properties X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Links represent an ephemeral relationship between devices. They are meant to replace the qdev concept of busses by allowing more informal relationships between devices. Links are fairly limited in their usefulness without implementing QOM-style subclassing and interfaces. Signed-off-by: Anthony Liguori --- hw/qdev.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 23 ++++++++++++++++++++ 2 files changed, 92 insertions(+), 0 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index b09d22a..658ed2c 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -1180,6 +1180,75 @@ void qdev_property_add_child(DeviceState *dev, const char *name, g_free(type); } +static void qdev_get_link_property(DeviceState *dev, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + DeviceState **child = opaque; + gchar *path; + + if (*child) { + path = qdev_get_canonical_path(*child); + visit_type_str(v, &path, name, errp); + g_free(path); + } else { + path = (gchar *)""; + visit_type_str(v, &path, name, errp); + } +} + +static void qdev_set_link_property(DeviceState *dev, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + DeviceState **child = opaque; + bool ambiguous = false; + const char *type; + char *path; + + type = qdev_property_get_type(dev, name, NULL); + + visit_type_str(v, &path, name, errp); + + if (strcmp(path, "") != 0) { + DeviceState *target; + + target = qdev_resolve_path(path, &ambiguous); + if (target) { + gchar *target_type; + + target_type = g_strdup_printf("link<%s>", target->info->name); + if (strcmp(target_type, type) == 0) { + *child = target; + } else { + error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, type); + } + + g_free(target_type); + } else { + error_set(errp, QERR_DEVICE_NOT_FOUND, path); + } + } else { + *child = NULL; + } + + g_free(path); +} + +void qdev_property_add_link(DeviceState *dev, const char *name, + const char *type, DeviceState **child, + Error **errp) +{ + gchar *full_type; + + full_type = g_strdup_printf("link<%s>", type); + + qdev_property_add(dev, name, full_type, + qdev_get_link_property, + qdev_set_link_property, + NULL, child, errp); + + g_free(full_type); +} + static gchar *qdev_get_path_in(DeviceState *parent, DeviceState *dev) { GSList *i; diff --git a/hw/qdev.h b/hw/qdev.h index 905a02c..e8c9e76 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -519,4 +519,27 @@ DeviceState *qdev_resolve_path(const char *path, bool *ambiguous); void qdev_property_add_child(DeviceState *dev, const char *name, DeviceState *child, Error **errp); +/** + * @qdev_property_add_link - Add a link property to a device + * + * Links establish relationships between devices. Links are unidirection + * although two links can be combined to form a bidirectional relationship + * between devices. + * + * Links form the graph in the device model. + * + * @dev - the device to add a property to + * + * @name - the name of the property + * + * @type - the qdev type of the link + * + * @child - a pointer to where the link device reference is stored + * + * @errp - if an error occurs, a pointer to an area to store the area + */ +void qdev_property_add_link(DeviceState *dev, const char *name, + const char *type, DeviceState **child, + Error **errp); + #endif