blob: 21ce22de94b71ac98ef9ac7f9b8747a8a64c91f7 [file] [log] [blame]
Paolo Bonzini9f5f1352012-02-01 16:58:47 +01001/*
2 * QEMU Object Model - QObject wrappers
3 *
4 * Copyright (C) 2012 Red Hat, Inc.
5 *
6 * Author: Paolo Bonzini <pbonzini@redhat.com>
7 *
8 * This work is licensed under the terms of the GNU GPL, version 2 or later.
9 * See the COPYING file in the top-level directory.
10 */
11
Peter Maydell9bbc8532016-01-29 17:50:02 +000012#include "qemu/osdep.h"
Markus Armbrusterda34e652016-03-14 09:01:28 +010013#include "qapi/error.h"
Paolo Bonzini14cccb62012-12-17 18:19:50 +010014#include "qom/object.h"
15#include "qom/qom-qobject.h"
Paolo Bonzini7b1b5d12012-12-17 18:19:43 +010016#include "qapi/visitor.h"
Daniel P. Berrangeb3db2112016-09-30 15:45:27 +010017#include "qapi/qobject-input-visitor.h"
18#include "qapi/qobject-output-visitor.h"
Paolo Bonzini9f5f1352012-02-01 16:58:47 +010019
Markus Armbruster6fd5bef2020-07-07 18:05:55 +020020bool object_property_set_qobject(Object *obj,
Markus Armbruster5325cc32020-07-07 18:05:54 +020021 const char *name, QObject *value,
22 Error **errp)
Paolo Bonzini9f5f1352012-02-01 16:58:47 +010023{
Eric Blakeb70ce102016-06-09 10:48:38 -060024 Visitor *v;
Markus Armbruster6fd5bef2020-07-07 18:05:55 +020025 bool ok;
Markus Armbruster05601ed2017-03-03 13:32:37 +010026
Markus Armbruster048abb72017-03-03 13:32:39 +010027 v = qobject_input_visitor_new(value);
Markus Armbruster6fd5bef2020-07-07 18:05:55 +020028 ok = object_property_set(obj, name, v, errp);
Eric Blakeb70ce102016-06-09 10:48:38 -060029 visit_free(v);
Markus Armbruster6fd5bef2020-07-07 18:05:55 +020030 return ok;
Paolo Bonzini9f5f1352012-02-01 16:58:47 +010031}
32
33QObject *object_property_get_qobject(Object *obj, const char *name,
34 Error **errp)
35{
36 QObject *ret = NULL;
Eric Blake3b098d52016-06-09 10:48:43 -060037 Visitor *v;
Paolo Bonzini9f5f1352012-02-01 16:58:47 +010038
Daniel P. Berrange7d5e1992016-09-30 15:45:28 +010039 v = qobject_output_visitor_new(&ret);
Markus Armbruster992861f2020-07-07 18:06:04 +020040 if (object_property_get(obj, name, v, errp)) {
Eric Blake3b098d52016-06-09 10:48:43 -060041 visit_complete(v, &ret);
Paolo Bonzini9f5f1352012-02-01 16:58:47 +010042 }
Eric Blake3b098d52016-06-09 10:48:43 -060043 visit_free(v);
Paolo Bonzini9f5f1352012-02-01 16:58:47 +010044 return ret;
45}