blob: 06dfc43498117c2e8c5a59fc36289b68ac90079f [file] [log] [blame]
Anthony Liguorif7e6b192009-11-11 10:37:39 -06001/*
2 * QBool Module
3 *
Anthony Liguorif7e6b192009-11-11 10:37:39 -06004 * Copyright IBM, Corp. 2009
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
10 * See the COPYING.LIB file in the top-level directory.
11 *
12 */
13
Peter Maydellf2ad72b2016-01-29 17:50:01 +000014#include "qemu/osdep.h"
Paolo Bonzini7b1b5d12012-12-17 18:19:43 +010015#include "qapi/qmp/qbool.h"
Anthony Liguorif7e6b192009-11-11 10:37:39 -060016
Anthony Liguorif7e6b192009-11-11 10:37:39 -060017/**
Eric Blakefc48ffc2015-05-15 16:24:59 -060018 * qbool_from_bool(): Create a new QBool from a bool
Anthony Liguorif7e6b192009-11-11 10:37:39 -060019 *
20 * Return strong reference.
21 */
Eric Blakefc48ffc2015-05-15 16:24:59 -060022QBool *qbool_from_bool(bool value)
Anthony Liguorif7e6b192009-11-11 10:37:39 -060023{
24 QBool *qb;
25
Anthony Liguori7267c092011-08-20 22:09:37 -050026 qb = g_malloc(sizeof(*qb));
Eric Blake55e18192015-12-01 22:20:45 -070027 qobject_init(QOBJECT(qb), QTYPE_QBOOL);
Anthony Liguorif7e6b192009-11-11 10:37:39 -060028 qb->value = value;
Anthony Liguorif7e6b192009-11-11 10:37:39 -060029
30 return qb;
31}
32
33/**
Eric Blakefc48ffc2015-05-15 16:24:59 -060034 * qbool_get_bool(): Get the stored bool
Anthony Liguorif7e6b192009-11-11 10:37:39 -060035 */
Eric Blakefc48ffc2015-05-15 16:24:59 -060036bool qbool_get_bool(const QBool *qb)
Anthony Liguorif7e6b192009-11-11 10:37:39 -060037{
38 return qb->value;
39}
40
41/**
Max Reitzb38dd672017-11-14 19:01:25 +010042 * qbool_is_equal(): Test whether the two QBools are equal
43 */
44bool qbool_is_equal(const QObject *x, const QObject *y)
45{
Max Reitz7dc847e2018-02-24 16:40:29 +010046 return qobject_to(QBool, x)->value == qobject_to(QBool, y)->value;
Max Reitzb38dd672017-11-14 19:01:25 +010047}
48
49/**
Anthony Liguorif7e6b192009-11-11 10:37:39 -060050 * qbool_destroy_obj(): Free all memory allocated by a
51 * QBool object
52 */
Eric Blake55e18192015-12-01 22:20:45 -070053void qbool_destroy_obj(QObject *obj)
Anthony Liguorif7e6b192009-11-11 10:37:39 -060054{
55 assert(obj != NULL);
Max Reitz7dc847e2018-02-24 16:40:29 +010056 g_free(qobject_to(QBool, obj));
Anthony Liguorif7e6b192009-11-11 10:37:39 -060057}