root / qbool.c @ 658788c5
History | View | Annotate | Download (1.4 kB)
1 | f7e6b192 | Anthony Liguori | /*
|
---|---|---|---|
2 | f7e6b192 | Anthony Liguori | * QBool Module
|
3 | f7e6b192 | Anthony Liguori | *
|
4 | f7e6b192 | Anthony Liguori | * Copyright (C) 2009 Red Hat Inc.
|
5 | f7e6b192 | Anthony Liguori | *
|
6 | f7e6b192 | Anthony Liguori | * Authors:
|
7 | f7e6b192 | Anthony Liguori | * Luiz Capitulino <lcapitulino@redhat.com>
|
8 | f7e6b192 | Anthony Liguori | *
|
9 | f7e6b192 | Anthony Liguori | * This work is licensed under the terms of the GNU GPL, version 2. See
|
10 | f7e6b192 | Anthony Liguori | * the COPYING file in the top-level directory.
|
11 | f7e6b192 | Anthony Liguori | *
|
12 | f7e6b192 | Anthony Liguori | * Copyright IBM, Corp. 2009
|
13 | f7e6b192 | Anthony Liguori | *
|
14 | f7e6b192 | Anthony Liguori | * Authors:
|
15 | f7e6b192 | Anthony Liguori | * Anthony Liguori <aliguori@us.ibm.com>
|
16 | f7e6b192 | Anthony Liguori | *
|
17 | f7e6b192 | Anthony Liguori | * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
18 | f7e6b192 | Anthony Liguori | * See the COPYING.LIB file in the top-level directory.
|
19 | f7e6b192 | Anthony Liguori | *
|
20 | f7e6b192 | Anthony Liguori | */
|
21 | f7e6b192 | Anthony Liguori | |
22 | f7e6b192 | Anthony Liguori | #include "qbool.h" |
23 | f7e6b192 | Anthony Liguori | #include "qobject.h" |
24 | f7e6b192 | Anthony Liguori | #include "qemu-common.h" |
25 | f7e6b192 | Anthony Liguori | |
26 | f7e6b192 | Anthony Liguori | static void qbool_destroy_obj(QObject *obj); |
27 | f7e6b192 | Anthony Liguori | |
28 | f7e6b192 | Anthony Liguori | static const QType qbool_type = { |
29 | f7e6b192 | Anthony Liguori | .code = QTYPE_QBOOL, |
30 | f7e6b192 | Anthony Liguori | .destroy = qbool_destroy_obj, |
31 | f7e6b192 | Anthony Liguori | }; |
32 | f7e6b192 | Anthony Liguori | |
33 | f7e6b192 | Anthony Liguori | /**
|
34 | f7e6b192 | Anthony Liguori | * qbool_from_int(): Create a new QBool from an int
|
35 | f7e6b192 | Anthony Liguori | *
|
36 | f7e6b192 | Anthony Liguori | * Return strong reference.
|
37 | f7e6b192 | Anthony Liguori | */
|
38 | f7e6b192 | Anthony Liguori | QBool *qbool_from_int(int value)
|
39 | f7e6b192 | Anthony Liguori | { |
40 | f7e6b192 | Anthony Liguori | QBool *qb; |
41 | f7e6b192 | Anthony Liguori | |
42 | f7e6b192 | Anthony Liguori | qb = qemu_malloc(sizeof(*qb));
|
43 | f7e6b192 | Anthony Liguori | qb->value = value; |
44 | f7e6b192 | Anthony Liguori | QOBJECT_INIT(qb, &qbool_type); |
45 | f7e6b192 | Anthony Liguori | |
46 | f7e6b192 | Anthony Liguori | return qb;
|
47 | f7e6b192 | Anthony Liguori | } |
48 | f7e6b192 | Anthony Liguori | |
49 | f7e6b192 | Anthony Liguori | /**
|
50 | f7e6b192 | Anthony Liguori | * qbool_get_int(): Get the stored int
|
51 | f7e6b192 | Anthony Liguori | */
|
52 | f7e6b192 | Anthony Liguori | int qbool_get_int(const QBool *qb) |
53 | f7e6b192 | Anthony Liguori | { |
54 | f7e6b192 | Anthony Liguori | return qb->value;
|
55 | f7e6b192 | Anthony Liguori | } |
56 | f7e6b192 | Anthony Liguori | |
57 | f7e6b192 | Anthony Liguori | /**
|
58 | f7e6b192 | Anthony Liguori | * qobject_to_qbool(): Convert a QObject into a QBool
|
59 | f7e6b192 | Anthony Liguori | */
|
60 | f7e6b192 | Anthony Liguori | QBool *qobject_to_qbool(const QObject *obj)
|
61 | f7e6b192 | Anthony Liguori | { |
62 | f7e6b192 | Anthony Liguori | if (qobject_type(obj) != QTYPE_QBOOL)
|
63 | f7e6b192 | Anthony Liguori | return NULL; |
64 | f7e6b192 | Anthony Liguori | |
65 | f7e6b192 | Anthony Liguori | return container_of(obj, QBool, base);
|
66 | f7e6b192 | Anthony Liguori | } |
67 | f7e6b192 | Anthony Liguori | |
68 | f7e6b192 | Anthony Liguori | /**
|
69 | f7e6b192 | Anthony Liguori | * qbool_destroy_obj(): Free all memory allocated by a
|
70 | f7e6b192 | Anthony Liguori | * QBool object
|
71 | f7e6b192 | Anthony Liguori | */
|
72 | f7e6b192 | Anthony Liguori | static void qbool_destroy_obj(QObject *obj) |
73 | f7e6b192 | Anthony Liguori | { |
74 | f7e6b192 | Anthony Liguori | assert(obj != NULL);
|
75 | f7e6b192 | Anthony Liguori | qemu_free(qobject_to_qbool(obj)); |
76 | f7e6b192 | Anthony Liguori | } |