1 #include "meson-subsample.h"
2 
3 struct _MesonSubSample
4 {
5   MesonSample parent_instance;
6 
7   gchar *msg;
8 };
9 
10 G_DEFINE_TYPE (MesonSubSample, meson_sub_sample, MESON_TYPE_SAMPLE)
11 
12 enum {
13   PROP_0,
14   PROP_MSG,
15   LAST_PROP
16 };
17 
18 static GParamSpec *gParamSpecs [LAST_PROP];
19 
20 /**
21  * meson_sub_sample_new:
22  * @msg: The message to set.
23  *
24  * Allocates a new #MesonSubSample.
25  *
26  * Returns: (transfer full): a #MesonSubSample.
27  */
28 MesonSubSample *
29 meson_sub_sample_new (const gchar *msg)
30 {
31   g_return_val_if_fail (msg != NULL, NULL);
32 
33   return g_object_new (MESON_TYPE_SUB_SAMPLE,
34                        "message", msg,
35                        NULL);
36 }
37 
38 static void
39 meson_sub_sample_finalize (GObject *object)
40 {
41   MesonSubSample *self = (MesonSubSample *)object;
42 
43   g_clear_pointer (&self->msg, g_free);
44 
45   G_OBJECT_CLASS (meson_sub_sample_parent_class)->finalize (object);
46 }
47 
48 static void
49 meson_sub_sample_get_property (GObject    *object,
50                            guint       prop_id,
51                            GValue     *value,
52                            GParamSpec *pspec)
53 {
54   MesonSubSample *self = MESON_SUB_SAMPLE (object);
55 
56   switch (prop_id)
57     {
58     case PROP_MSG:
59       g_value_set_string (value, self->msg);
60       break;
61     default:
62       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
63     }
64 }
65 
66 static void
67 meson_sub_sample_set_property (GObject      *object,
68                            guint         prop_id,
69                            const GValue *value,
70                            GParamSpec   *pspec)
71 {
72   MesonSubSample *self = MESON_SUB_SAMPLE (object);
73 
74   switch (prop_id)
75     {
76     case PROP_MSG:
77       self->msg = g_value_dup_string (value);
78       break;
79     default:
80       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
81     }
82 }
83 
84 static void
85 meson_sub_sample_class_init (MesonSubSampleClass *klass)
86 {
87   GObjectClass *object_class = G_OBJECT_CLASS (klass);
88 
89   object_class->finalize = meson_sub_sample_finalize;
90   object_class->get_property = meson_sub_sample_get_property;
91   object_class->set_property = meson_sub_sample_set_property;
92 
93   gParamSpecs [PROP_MSG] =
94     g_param_spec_string ("message",
95                          "Message",
96                          "The message to print.",
97                          NULL,
98                          (G_PARAM_READWRITE |
99                           G_PARAM_CONSTRUCT_ONLY |
100                           G_PARAM_STATIC_STRINGS));
101 
102   g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs);
103 }
104 
105 static void
106 meson_sub_sample_init (MesonSubSample *self)
107 {
108 }
109 
110 /**
111  * meson_sub_sample_print_message:
112  * @self: a #MesonSubSample.
113  *
114  * Prints the message.
115  *
116  * Returns: Nothing.
117  */
118 void
119 meson_sub_sample_print_message (MesonSubSample *self)
120 {
121   g_return_if_fail (MESON_IS_SUB_SAMPLE (self));
122 
123   g_print ("Message: %s\n", self->msg);
124 }
125