dep2.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #include "dep2.h"
  2. struct _MesonDep2
  3. {
  4. GObject parent_instance;
  5. gchar *msg;
  6. };
  7. G_DEFINE_TYPE (MesonDep2, meson_dep2, G_TYPE_OBJECT)
  8. enum {
  9. PROP_0,
  10. PROP_MSG,
  11. LAST_PROP
  12. };
  13. static GParamSpec *gParamSpecs [LAST_PROP];
  14. /**
  15. * meson_dep2_new:
  16. * @msg: The message to set.
  17. *
  18. * Allocates a new #MesonDep2.
  19. *
  20. * Returns: (transfer full): a #MesonDep2.
  21. */
  22. MesonDep2 *
  23. meson_dep2_new (const gchar *msg)
  24. {
  25. g_return_val_if_fail (msg != NULL, NULL);
  26. return g_object_new (MESON_TYPE_DEP2,
  27. "message", msg,
  28. NULL);
  29. }
  30. static void
  31. meson_dep2_finalize (GObject *object)
  32. {
  33. MesonDep2 *self = (MesonDep2 *)object;
  34. g_clear_pointer (&self->msg, g_free);
  35. G_OBJECT_CLASS (meson_dep2_parent_class)->finalize (object);
  36. }
  37. static void
  38. meson_dep2_get_property (GObject *object,
  39. guint prop_id,
  40. GValue *value,
  41. GParamSpec *pspec)
  42. {
  43. MesonDep2 *self = MESON_DEP2 (object);
  44. switch (prop_id)
  45. {
  46. case PROP_MSG:
  47. g_value_set_string (value, self->msg);
  48. break;
  49. default:
  50. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  51. }
  52. }
  53. static void
  54. meson_dep2_set_property (GObject *object,
  55. guint prop_id,
  56. const GValue *value,
  57. GParamSpec *pspec)
  58. {
  59. MesonDep2 *self = MESON_DEP2 (object);
  60. switch (prop_id)
  61. {
  62. case PROP_MSG:
  63. self->msg = g_value_dup_string (value);
  64. break;
  65. default:
  66. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  67. }
  68. }
  69. static void
  70. meson_dep2_class_init (MesonDep2Class *klass)
  71. {
  72. GObjectClass *object_class = G_OBJECT_CLASS (klass);
  73. object_class->finalize = meson_dep2_finalize;
  74. object_class->get_property = meson_dep2_get_property;
  75. object_class->set_property = meson_dep2_set_property;
  76. gParamSpecs [PROP_MSG] =
  77. g_param_spec_string ("message",
  78. "Message",
  79. "The message to print.",
  80. NULL,
  81. (G_PARAM_READWRITE |
  82. G_PARAM_CONSTRUCT_ONLY |
  83. G_PARAM_STATIC_STRINGS));
  84. g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs);
  85. }
  86. static void
  87. meson_dep2_init (MesonDep2 *self)
  88. {
  89. }
  90. /**
  91. * meson_dep2_return_message:
  92. * @self: a #MesonDep2.
  93. *
  94. * Returns the message.
  95. *
  96. * Returns: (transfer none): a const gchar*
  97. */
  98. const gchar*
  99. meson_dep2_return_message (MesonDep2 *self)
  100. {
  101. g_return_val_if_fail (MESON_IS_DEP2 (self), NULL);
  102. return (const gchar*) self->msg;
  103. }