blob: b58249925c2dc2c3d2a87de9b890287043b36184 [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#include "qemu-common.h"
17
Anthony Liguorif7e6b192009-11-11 10:37:39 -060018/**
Eric Blakefc48ffc2015-05-15 16:24:59 -060019 * qbool_from_bool(): Create a new QBool from a bool
Anthony Liguorif7e6b192009-11-11 10:37:39 -060020 *
21 * Return strong reference.
22 */
Eric Blakefc48ffc2015-05-15 16:24:59 -060023QBool *qbool_from_bool(bool value)
Anthony Liguorif7e6b192009-11-11 10:37:39 -060024{
25 QBool *qb;
26
Anthony Liguori7267c092011-08-20 22:09:37 -050027 qb = g_malloc(sizeof(*qb));
Eric Blake55e18192015-12-01 22:20:45 -070028 qobject_init(QOBJECT(qb), QTYPE_QBOOL);
Anthony Liguorif7e6b192009-11-11 10:37:39 -060029 qb->value = value;
Anthony Liguorif7e6b192009-11-11 10:37:39 -060030
31 return qb;
32}
33
34/**
Eric Blakefc48ffc2015-05-15 16:24:59 -060035 * qbool_get_bool(): Get the stored bool
Anthony Liguorif7e6b192009-11-11 10:37:39 -060036 */
Eric Blakefc48ffc2015-05-15 16:24:59 -060037bool qbool_get_bool(const QBool *qb)
Anthony Liguorif7e6b192009-11-11 10:37:39 -060038{
39 return qb->value;
40}
41
42/**
Max Reitzb38dd672017-11-14 19:01:25 +010043 * qbool_is_equal(): Test whether the two QBools are equal
44 */
45bool qbool_is_equal(const QObject *x, const QObject *y)
46{
Max Reitz7dc847e2018-02-24 16:40:29 +010047 return qobject_to(QBool, x)->value == qobject_to(QBool, y)->value;
Max Reitzb38dd672017-11-14 19:01:25 +010048}
49
50/**
Anthony Liguorif7e6b192009-11-11 10:37:39 -060051 * qbool_destroy_obj(): Free all memory allocated by a
52 * QBool object
53 */
Eric Blake55e18192015-12-01 22:20:45 -070054void qbool_destroy_obj(QObject *obj)
Anthony Liguorif7e6b192009-11-11 10:37:39 -060055{
56 assert(obj != NULL);
Max Reitz7dc847e2018-02-24 16:40:29 +010057 g_free(qobject_to(QBool, obj));
Anthony Liguorif7e6b192009-11-11 10:37:39 -060058}