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