2 #include <glib-object.h>
4 #define MY_TYPE_BADGER (my_badger_get_type ())
5 #define MY_BADGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MY_TYPE_BADGER, MyBadger))
6 #define MY_IS_BADGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MY_TYPE_BADGER))
7 #define MY_BADGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MY_TYPE_BADGER, MyBadgerClass))
8 #define MY_IS_BADGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MY_TYPE_BADGER))
9 #define MY_BADGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MY_TYPE_BADGER, MyBadgerClass))
16 typedef struct _MyBadger MyBadger
;
17 typedef struct _MyBadgerClass MyBadgerClass
;
21 GObject parent_instance
;
24 guint mama_notify_count
;
29 GObjectClass parent_class
;
32 static GType
my_badger_get_type (void);
33 G_DEFINE_TYPE (MyBadger
, my_badger
, G_TYPE_OBJECT
);
35 static void my_badger_dispose (GObject
* object
);
37 static void my_badger_get_property (GObject
*object
,
41 static void my_badger_set_property (GObject
*object
,
46 static void my_badger_mama_notify (GObject
*object
,
50 my_badger_class_init (MyBadgerClass
* klass
)
52 GObjectClass
*gobject_class
;
54 gobject_class
= (GObjectClass
*) klass
;
56 gobject_class
->dispose
= my_badger_dispose
;
58 gobject_class
->get_property
= my_badger_get_property
;
59 gobject_class
->set_property
= my_badger_set_property
;
61 g_object_class_install_property (gobject_class
,
63 g_param_spec_object ("mama",
71 my_badger_init (MyBadger
* self
)
73 g_signal_connect (self
, "notify::mama", G_CALLBACK (my_badger_mama_notify
),
78 my_badger_dispose (GObject
* object
)
82 self
= MY_BADGER (object
);
84 if (self
->mama
!= NULL
)
86 g_object_unref (self
->mama
);
90 G_OBJECT_CLASS (my_badger_parent_class
)->dispose (object
);
94 my_badger_get_property (GObject
*object
,
101 self
= MY_BADGER (object
);
106 g_value_set_object (value
, self
->mama
);
109 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
115 my_badger_set_property (GObject
*object
,
122 self
= MY_BADGER (object
);
128 g_object_unref (self
->mama
);
129 self
->mama
= g_value_dup_object (value
);
131 g_object_set (self
->mama
, "mama", NULL
, NULL
); /* another notify */
134 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
140 my_badger_mama_notify (GObject
*object
,
145 self
= MY_BADGER (object
);
147 self
->mama_notify_count
++;
151 main (int argc
, char **argv
)
153 MyBadger
* badger1
, * badger2
;
156 g_print ("START: %s\n", argv
[0]);
157 g_log_set_always_fatal (G_LOG_LEVEL_WARNING
| G_LOG_LEVEL_CRITICAL
| g_log_set_always_fatal (G_LOG_FATAL_MASK
));
159 badger1
= g_object_new (MY_TYPE_BADGER
, NULL
);
160 badger2
= g_object_new (MY_TYPE_BADGER
, NULL
);
162 g_object_set (badger1
, "mama", badger2
, NULL
);
163 g_assert_cmpuint (badger1
->mama_notify_count
, ==, 1);
164 g_assert_cmpuint (badger2
->mama_notify_count
, ==, 1);
165 g_object_get (badger1
, "mama", &test
, NULL
);
166 g_assert (test
== badger2
);
167 g_object_unref (test
);
169 g_object_unref (badger1
);
170 g_object_unref (badger2
);