blob: e5a7a538793277dc8bcf9a53dc79becafa88e08d [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/**
43 * qobject_to_qbool(): Convert a QObject into a QBool
44 */
45QBool *qobject_to_qbool(const QObject *obj)
46{
Markus Armbruster14b61602015-10-15 16:15:33 +020047 if (!obj || qobject_type(obj) != QTYPE_QBOOL) {
Anthony Liguorif7e6b192009-11-11 10:37:39 -060048 return NULL;
Markus Armbruster14b61602015-10-15 16:15:33 +020049 }
Anthony Liguorif7e6b192009-11-11 10:37:39 -060050 return container_of(obj, QBool, base);
51}
52
53/**
Max Reitzb38dd672017-11-14 19:01:25 +010054 * qbool_is_equal(): Test whether the two QBools are equal
55 */
56bool qbool_is_equal(const QObject *x, const QObject *y)
57{
58 return qobject_to_qbool(x)->value == qobject_to_qbool(y)->value;
59}
60
61/**
Anthony Liguorif7e6b192009-11-11 10:37:39 -060062 * qbool_destroy_obj(): Free all memory allocated by a
63 * QBool object
64 */
Eric Blake55e18192015-12-01 22:20:45 -070065void qbool_destroy_obj(QObject *obj)
Anthony Liguorif7e6b192009-11-11 10:37:39 -060066{
67 assert(obj != NULL);
Anthony Liguori7267c092011-08-20 22:09:37 -050068 g_free(qobject_to_qbool(obj));
Anthony Liguorif7e6b192009-11-11 10:37:39 -060069}