]> git.proxmox.com Git - qemu.git/blame - qbool.c
update VERSION for 1.1.2
[qemu.git] / qbool.c
CommitLineData
f7e6b192
AL
1/*
2 * QBool Module
3 *
f7e6b192
AL
4 * 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
14#include "qbool.h"
15#include "qobject.h"
16#include "qemu-common.h"
17
18static void qbool_destroy_obj(QObject *obj);
19
20static const QType qbool_type = {
21 .code = QTYPE_QBOOL,
22 .destroy = qbool_destroy_obj,
23};
24
25/**
26 * qbool_from_int(): Create a new QBool from an int
27 *
28 * Return strong reference.
29 */
30QBool *qbool_from_int(int value)
31{
32 QBool *qb;
33
7267c094 34 qb = g_malloc(sizeof(*qb));
f7e6b192
AL
35 qb->value = value;
36 QOBJECT_INIT(qb, &qbool_type);
37
38 return qb;
39}
40
41/**
42 * qbool_get_int(): Get the stored int
43 */
44int qbool_get_int(const QBool *qb)
45{
46 return qb->value;
47}
48
49/**
50 * qobject_to_qbool(): Convert a QObject into a QBool
51 */
52QBool *qobject_to_qbool(const QObject *obj)
53{
54 if (qobject_type(obj) != QTYPE_QBOOL)
55 return NULL;
56
57 return container_of(obj, QBool, base);
58}
59
60/**
61 * qbool_destroy_obj(): Free all memory allocated by a
62 * QBool object
63 */
64static void qbool_destroy_obj(QObject *obj)
65{
66 assert(obj != NULL);
7267c094 67 g_free(qobject_to_qbool(obj));
f7e6b192 68}