qbool.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * QBool Module
  3. *
  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. #include "qemu/osdep.h"
  14. #include "qapi/qmp/qbool.h"
  15. #include "qobject-internal.h"
  16. /**
  17. * qbool_from_bool(): Create a new QBool from a bool
  18. *
  19. * Return strong reference.
  20. */
  21. QBool *qbool_from_bool(bool value)
  22. {
  23. QBool *qb;
  24. qb = g_malloc(sizeof(*qb));
  25. qobject_init(QOBJECT(qb), QTYPE_QBOOL);
  26. qb->value = value;
  27. return qb;
  28. }
  29. /**
  30. * qbool_get_bool(): Get the stored bool
  31. */
  32. bool qbool_get_bool(const QBool *qb)
  33. {
  34. return qb->value;
  35. }
  36. /**
  37. * qbool_is_equal(): Test whether the two QBools are equal
  38. */
  39. bool qbool_is_equal(const QObject *x, const QObject *y)
  40. {
  41. return qobject_to(QBool, x)->value == qobject_to(QBool, y)->value;
  42. }
  43. /**
  44. * qbool_destroy_obj(): Free all memory allocated by a
  45. * QBool object
  46. */
  47. void qbool_destroy_obj(QObject *obj)
  48. {
  49. assert(obj != NULL);
  50. g_free(qobject_to(QBool, obj));
  51. }
  52. void qbool_unref(QBool *q)
  53. {
  54. qobject_unref(q);
  55. }