meson-sample.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #include "meson-sample.h"
  2. struct _MesonSample
  3. {
  4. GObject parent_instance;
  5. gchar *msg;
  6. };
  7. G_DEFINE_TYPE (MesonSample, meson_sample, G_TYPE_OBJECT)
  8. enum {
  9. PROP_0,
  10. PROP_MSG,
  11. LAST_PROP
  12. };
  13. static GParamSpec *gParamSpecs [LAST_PROP];
  14. /**
  15. * meson_sample_new:
  16. *
  17. * Allocates a new #MesonSample.
  18. *
  19. * Returns: (transfer full): a #MesonSample.
  20. */
  21. MesonSample *
  22. meson_sample_new (void)
  23. {
  24. return g_object_new (MESON_TYPE_SAMPLE, NULL);
  25. }
  26. static void
  27. meson_sample_finalize (GObject *object)
  28. {
  29. MesonSample *self = (MesonSample *)object;
  30. g_clear_pointer (&self->msg, g_free);
  31. G_OBJECT_CLASS (meson_sample_parent_class)->finalize (object);
  32. }
  33. static void
  34. meson_sample_get_property (GObject *object,
  35. guint prop_id,
  36. GValue *value,
  37. GParamSpec *pspec)
  38. {
  39. MesonSample *self = MESON_SAMPLE (object);
  40. switch (prop_id)
  41. {
  42. case PROP_MSG:
  43. g_value_set_string (value, self->msg);
  44. break;
  45. default:
  46. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  47. }
  48. }
  49. static void
  50. meson_sample_set_property (GObject *object,
  51. guint prop_id,
  52. const GValue *value,
  53. GParamSpec *pspec)
  54. {
  55. MesonSample *self = MESON_SAMPLE (object);
  56. switch (prop_id)
  57. {
  58. case PROP_MSG:
  59. self->msg = g_value_dup_string (value);
  60. break;
  61. default:
  62. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  63. }
  64. }
  65. static void
  66. meson_sample_class_init (MesonSampleClass *klass)
  67. {
  68. GObjectClass *object_class = G_OBJECT_CLASS (klass);
  69. object_class->finalize = meson_sample_finalize;
  70. object_class->get_property = meson_sample_get_property;
  71. object_class->set_property = meson_sample_set_property;
  72. gParamSpecs [PROP_MSG] =
  73. g_param_spec_string ("message",
  74. "Message",
  75. "The message to print.",
  76. NULL,
  77. (G_PARAM_READWRITE |
  78. G_PARAM_CONSTRUCT_ONLY |
  79. G_PARAM_STATIC_STRINGS));
  80. g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs);
  81. }
  82. static void
  83. meson_sample_init (MesonSample *self)
  84. {
  85. }
  86. /**
  87. * meson_sample_print_message:
  88. * @self: a #MesonSample.
  89. *
  90. * Prints the message.
  91. *
  92. * Returns: Nothing.
  93. */
  94. void
  95. meson_sample_print_message (MesonSample *self, MesonDep1 *dep1, MesonDep2 *dep2)
  96. {
  97. MesonDep2 *samedep;
  98. g_return_if_fail (MESON_IS_SAMPLE (self));
  99. samedep = meson_dep1_just_return_it (dep1, dep2);
  100. g_print ("Message: %s\n", meson_dep2_return_message (samedep));
  101. }