qbool.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 "qbool.h"
  14. #include "qobject.h"
  15. #include "qemu-common.h"
  16. static void qbool_destroy_obj(QObject *obj);
  17. static const QType qbool_type = {
  18. .code = QTYPE_QBOOL,
  19. .destroy = qbool_destroy_obj,
  20. };
  21. /**
  22. * qbool_from_int(): Create a new QBool from an int
  23. *
  24. * Return strong reference.
  25. */
  26. QBool *qbool_from_int(int value)
  27. {
  28. QBool *qb;
  29. qb = qemu_malloc(sizeof(*qb));
  30. qb->value = value;
  31. QOBJECT_INIT(qb, &qbool_type);
  32. return qb;
  33. }
  34. /**
  35. * qbool_get_int(): Get the stored int
  36. */
  37. int qbool_get_int(const QBool *qb)
  38. {
  39. return qb->value;
  40. }
  41. /**
  42. * qobject_to_qbool(): Convert a QObject into a QBool
  43. */
  44. QBool *qobject_to_qbool(const QObject *obj)
  45. {
  46. if (qobject_type(obj) != QTYPE_QBOOL)
  47. return NULL;
  48. return container_of(obj, QBool, base);
  49. }
  50. /**
  51. * qbool_destroy_obj(): Free all memory allocated by a
  52. * QBool object
  53. */
  54. static void qbool_destroy_obj(QObject *obj)
  55. {
  56. assert(obj != NULL);
  57. qemu_free(qobject_to_qbool(obj));
  58. }