meson-subsample.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #include "meson-subsample.h"
  2. struct _MesonSubSample
  3. {
  4. MesonSample parent_instance;
  5. gchar *msg;
  6. };
  7. G_DEFINE_TYPE (MesonSubSample, meson_sub_sample, MESON_TYPE_SAMPLE)
  8. enum {
  9. PROP_0,
  10. PROP_MSG,
  11. LAST_PROP
  12. };
  13. static GParamSpec *gParamSpecs [LAST_PROP];
  14. /**
  15. * meson_sub_sample_new:
  16. * @msg: The message to set.
  17. *
  18. * Allocates a new #MesonSubSample.
  19. *
  20. * Returns: (transfer full): a #MesonSubSample.
  21. */
  22. MesonSubSample *
  23. meson_sub_sample_new (const gchar *msg)
  24. {
  25. g_return_val_if_fail (msg != NULL, NULL);
  26. return g_object_new (MESON_TYPE_SUB_SAMPLE,
  27. "message", msg,
  28. NULL);
  29. }
  30. static void
  31. meson_sub_sample_finalize (GObject *object)
  32. {
  33. MesonSubSample *self = (MesonSubSample *)object;
  34. g_clear_pointer (&self->msg, g_free);
  35. G_OBJECT_CLASS (meson_sub_sample_parent_class)->finalize (object);
  36. }
  37. static void
  38. meson_sub_sample_get_property (GObject *object,
  39. guint prop_id,
  40. GValue *value,
  41. GParamSpec *pspec)
  42. {
  43. MesonSubSample *self = MESON_SUB_SAMPLE (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_sub_sample_set_property (GObject *object,
  55. guint prop_id,
  56. const GValue *value,
  57. GParamSpec *pspec)
  58. {
  59. MesonSubSample *self = MESON_SUB_SAMPLE (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_sub_sample_class_init (MesonSubSampleClass *klass)
  71. {
  72. GObjectClass *object_class = G_OBJECT_CLASS (klass);
  73. object_class->finalize = meson_sub_sample_finalize;
  74. object_class->get_property = meson_sub_sample_get_property;
  75. object_class->set_property = meson_sub_sample_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_sub_sample_init (MesonSubSample *self)
  88. {
  89. }
  90. /**
  91. * meson_sub_sample_print_message:
  92. * @self: a #MesonSubSample.
  93. *
  94. * Prints the message.
  95. *
  96. * Returns: Nothing.
  97. */
  98. void
  99. meson_sub_sample_print_message (MesonSubSample *self)
  100. {
  101. g_return_if_fail (MESON_IS_SUB_SAMPLE (self));
  102. g_print ("Message: %s\n", self->msg);
  103. }