qbool.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. /**
  16. * qbool_from_bool(): Create a new QBool from a bool
  17. *
  18. * Return strong reference.
  19. */
  20. QBool *qbool_from_bool(bool value)
  21. {
  22. QBool *qb;
  23. qb = g_malloc(sizeof(*qb));
  24. qobject_init(QOBJECT(qb), QTYPE_QBOOL);
  25. qb->value = value;
  26. return qb;
  27. }
  28. /**
  29. * qbool_get_bool(): Get the stored bool
  30. */
  31. bool qbool_get_bool(const QBool *qb)
  32. {
  33. return qb->value;
  34. }
  35. /**
  36. * qbool_is_equal(): Test whether the two QBools are equal
  37. */
  38. bool qbool_is_equal(const QObject *x, const QObject *y)
  39. {
  40. return qobject_to(QBool, x)->value == qobject_to(QBool, y)->value;
  41. }
  42. /**
  43. * qbool_destroy_obj(): Free all memory allocated by a
  44. * QBool object
  45. */
  46. void qbool_destroy_obj(QObject *obj)
  47. {
  48. assert(obj != NULL);
  49. g_free(qobject_to(QBool, obj));
  50. }