Documentation updates
[platform/upstream/gstreamer.git] / gst / gstobject.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gstobject.c: Fundamental class used for all of GStreamer
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include "gst_private.h"
24
25 #include "gstobject.h"
26 #include "gstlog.h"
27
28 /* Object signals and args */
29 enum {
30   PARENT_SET,
31   PARENT_UNSET,
32 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
33   OBJECT_SAVED,
34 #endif
35   DEEP_NOTIFY,
36   LAST_SIGNAL
37 };
38
39 enum {
40   ARG_0,
41   ARG_NAME,
42   /* FILL ME */
43 };
44
45 enum {
46   SO_OBJECT_LOADED,
47   SO_LAST_SIGNAL
48 };
49
50 GType _gst_object_type = 0;
51 static GHashTable *object_name_counts = NULL;
52 G_LOCK_DEFINE_STATIC (object_name_mutex);
53
54 typedef struct _GstSignalObject GstSignalObject;
55 typedef struct _GstSignalObjectClass GstSignalObjectClass;
56
57 static GType            gst_signal_object_get_type      (void);
58 static void             gst_signal_object_class_init    (GstSignalObjectClass *klass);
59 static void             gst_signal_object_init          (GstSignalObject *object);
60
61 static guint gst_signal_object_signals[SO_LAST_SIGNAL] = { 0 };
62
63 static void             gst_object_class_init           (GstObjectClass *klass);
64 static void             gst_object_init                 (GstObject *object);
65
66 static void             gst_object_set_property         (GObject * object, guint prop_id, const GValue * value,
67                                                          GParamSpec * pspec);
68 static void             gst_object_get_property         (GObject * object, guint prop_id, GValue * value,
69                                                          GParamSpec * pspec);
70 static void             gst_object_dispatch_properties_changed (GObject     *object,
71                                                          guint        n_pspecs,
72                                                          GParamSpec **pspecs);
73
74 static void             gst_object_dispose              (GObject *object);
75 static void             gst_object_finalize             (GObject *object);
76
77 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
78 static void             gst_object_real_restore_thyself (GstObject *object, xmlNodePtr self);
79 #endif
80
81 static GObjectClass *parent_class = NULL;
82 static guint gst_object_signals[LAST_SIGNAL] = { 0 };
83
84 GType
85 gst_object_get_type (void)
86 {
87   if (!_gst_object_type) {
88     static const GTypeInfo object_info = {
89       sizeof (GstObjectClass),
90       NULL,
91       NULL,
92       (GClassInitFunc) gst_object_class_init,
93       NULL,
94       NULL,
95       sizeof (GstObject),
96       32,
97       (GInstanceInitFunc) gst_object_init,
98       NULL
99     };
100     _gst_object_type = g_type_register_static (G_TYPE_OBJECT, "GstObject", &object_info, G_TYPE_FLAG_ABSTRACT);
101   }
102   return _gst_object_type;
103 }
104
105 static void
106 gst_object_class_init (GstObjectClass *klass)
107 {
108   GObjectClass *gobject_class;
109
110   gobject_class = (GObjectClass*) klass;
111
112   parent_class = g_type_class_ref (G_TYPE_OBJECT);
113
114   gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_object_set_property);
115   gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_object_get_property);
116
117   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NAME,
118     g_param_spec_string ("name", "Name", "The name of the object",
119                          NULL, G_PARAM_READWRITE));
120
121   gst_object_signals[PARENT_SET] =
122     g_signal_new ("parent_set", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
123                   G_STRUCT_OFFSET (GstObjectClass, parent_set), NULL, NULL,
124                   g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
125                   G_TYPE_OBJECT);
126   gst_object_signals[PARENT_UNSET] =
127     g_signal_new ("parent_unset", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
128                   G_STRUCT_OFFSET (GstObjectClass, parent_unset), NULL, NULL,
129                   g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
130                   G_TYPE_OBJECT);
131 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
132   gst_object_signals[OBJECT_SAVED] =
133     g_signal_new ("object_saved", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
134                   G_STRUCT_OFFSET (GstObjectClass, object_saved), NULL, NULL,
135                   g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
136                   G_TYPE_POINTER);
137   
138   klass->restore_thyself = gst_object_real_restore_thyself;
139 #endif
140   gst_object_signals[DEEP_NOTIFY] =
141     g_signal_new ("deep_notify", G_TYPE_FROM_CLASS (klass),
142                   G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
143                   G_STRUCT_OFFSET (GstObjectClass, deep_notify), NULL, NULL,
144                   gst_marshal_VOID__OBJECT_PARAM, G_TYPE_NONE,
145                   2, G_TYPE_OBJECT, G_TYPE_PARAM);
146
147   klass->path_string_separator = "/";
148
149   klass->signal_object = g_object_new (gst_signal_object_get_type (), NULL);
150     /* see the comments at gst_element_dispatch_properties_changed */
151
152   gobject_class->dispatch_properties_changed
153                 = GST_DEBUG_FUNCPTR (gst_object_dispatch_properties_changed);
154
155   gobject_class->dispose = gst_object_dispose;
156   gobject_class->finalize = gst_object_finalize;
157 }
158
159 static void
160 gst_object_init (GstObject *object)
161 {
162   object->lock = g_mutex_new();
163   object->parent = NULL;
164   object->name = NULL;
165
166   object->flags = 0;
167   GST_FLAG_SET (object, GST_FLOATING);
168 }
169
170 /**
171  * gst_object_ref:
172  * @object: GstObject to reference
173  *
174  * Increments the refence count on the object.
175  *
176  * Returns: A pointer to the object
177  */
178 GstObject*
179 gst_object_ref (GstObject *object)
180 {
181   g_return_val_if_fail (GST_IS_OBJECT (object), NULL);
182
183   GST_DEBUG (GST_CAT_REFCOUNTING, "ref '%s' %d->%d",GST_OBJECT_NAME(object),
184              G_OBJECT(object)->ref_count,G_OBJECT(object)->ref_count+1);
185
186   g_object_ref (G_OBJECT (object));
187   return object;
188 }
189
190 /**
191  * gst_object_unref:
192  * @object: GstObject to unreference
193  *
194  * Decrements the refence count on the object.  If reference count hits
195  * zero, destroy the object.
196  */
197 void
198 gst_object_unref (GstObject *object)
199 {
200   g_return_if_fail (GST_IS_OBJECT (object));
201
202   GST_DEBUG (GST_CAT_REFCOUNTING, "unref '%s' %d->%d",GST_OBJECT_NAME(object),
203              G_OBJECT(object)->ref_count,G_OBJECT(object)->ref_count-1);
204
205   g_object_unref (G_OBJECT (object));
206 }
207
208 /**
209  * gst_object_sink:
210  * @object: GstObject to sink
211  *
212  * Removes floating reference on an object.  Any newly created object has
213  * a refcount of 1 and is FLOATING.  This function should be used when
214  * creating a new object to symbolically 'take ownership of' the object.
215  * Use #gst_object_set_parent to have this done for you.
216  */
217 void
218 gst_object_sink (GstObject *object)
219 {
220   g_return_if_fail (object != NULL);
221   g_return_if_fail (GST_IS_OBJECT (object));
222
223   GST_DEBUG (GST_CAT_REFCOUNTING, "sink '%s'",GST_OBJECT_NAME(object));
224   if (GST_OBJECT_FLOATING (object))
225   {
226     GST_FLAG_UNSET (object, GST_FLOATING);
227     gst_object_unref (object);
228   }
229 }
230
231 /**
232  * gst_object_destroy:
233  * @object: GstObject to destroy
234  *
235  * Destroy the object.
236  * 
237  */
238 void
239 gst_object_destroy (GstObject *object)
240 {
241   g_return_if_fail (object != NULL);
242   g_return_if_fail (GST_IS_OBJECT (object));
243
244   GST_DEBUG (GST_CAT_REFCOUNTING, "destroy '%s'",GST_OBJECT_NAME(object));
245   if (!GST_OBJECT_DESTROYED (object))
246   {
247     /* need to hold a reference count around all class method
248      * invocations.
249      */
250     g_object_run_dispose (G_OBJECT (object));
251   }
252 }
253
254 static void
255 gst_object_dispose (GObject *object)
256 {
257   GST_DEBUG (GST_CAT_REFCOUNTING, "dispose '%s'",GST_OBJECT_NAME(object));
258   GST_FLAG_SET (GST_OBJECT (object), GST_DESTROYED);
259   GST_OBJECT_PARENT (object) = NULL;
260
261   parent_class->dispose (object);
262 }
263
264 /* finilize is called when the object has to free its resources */
265 static void
266 gst_object_finalize (GObject *object)
267 {
268   GstObject *gstobject = GST_OBJECT (object);
269
270   GST_DEBUG (GST_CAT_REFCOUNTING, "finalize '%s'",GST_OBJECT_NAME(object));
271
272   g_signal_handlers_destroy (object);
273
274   if (gstobject->name != NULL)
275     g_free (gstobject->name);
276
277   g_mutex_free (gstobject->lock);
278
279   parent_class->finalize (object);
280 }
281
282 /* Changing a GObject property of an element will result in "deep_notify"
283  * signals being emitted by the element itself, as well as in each parent
284  * element. This is so that an application can connect a listener to the
285  * top-level bin to catch property-change notifications for all contained
286  * elements. */
287 static void
288 gst_object_dispatch_properties_changed (GObject     *object,
289                                         guint        n_pspecs,
290                                         GParamSpec **pspecs)
291 {
292   GstObject *gst_object;
293   guint i;
294
295   /* do the standard dispatching */
296   G_OBJECT_CLASS (parent_class)->dispatch_properties_changed (object, n_pspecs, pspecs);
297
298   /* now let the parent dispatch those, too */
299   gst_object = GST_OBJECT_PARENT (object);
300   while (gst_object) {
301     /* need own category? */
302     for (i = 0; i < n_pspecs; i++) {
303       GST_DEBUG (GST_CAT_EVENT, "deep notification from %s to %s (%s)", GST_OBJECT_NAME (object),
304                  GST_OBJECT_NAME (gst_object), pspecs[i]->name);
305       g_signal_emit (gst_object, gst_object_signals[DEEP_NOTIFY], g_quark_from_string (pspecs[i]->name),
306                      (GstObject *) object, pspecs[i]);
307     }
308
309     gst_object = GST_OBJECT_PARENT (gst_object);
310   }
311 }
312
313 /** 
314  * gst_object_default_deep_notify:
315  * @object: the #GObject that signalled the notify.
316  * @orig: a #GstObject that initiated the notify.
317  * @pspec: a #GParamSpec of the property.
318  * @excluded_props: a set of user-specified properties to exclude or
319  *  NULL to show all changes.
320  *
321  * Adds a default deep_notify signal callback to an
322  * element. The user data should contain a pointer to an array of
323  * strings that should be excluded from the notify.
324  * The default handler will print the new value of the property 
325  * using g_print.
326  */
327 void
328 gst_object_default_deep_notify (GObject *object, GstObject *orig,
329                                 GParamSpec *pspec, gchar **excluded_props)
330 {
331   GValue value = { 0, }; /* the important thing is that value.type = 0 */
332   gchar *str = 0;
333   gchar *name = NULL;
334
335   if (pspec->flags & G_PARAM_READABLE) {
336     /* let's not print these out for excluded properties... */
337     while (excluded_props != NULL && *excluded_props != NULL) {
338       if (strcmp (pspec->name, *excluded_props) == 0)
339         return;
340       excluded_props++;
341     }
342     g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
343     g_object_get_property (G_OBJECT (orig), pspec->name, &value);
344
345     if (G_IS_PARAM_SPEC_ENUM (pspec)) {
346       GEnumValue *enum_value;
347       enum_value = g_enum_get_value (G_ENUM_CLASS (g_type_class_ref (pspec->value_type)),
348       g_value_get_enum (&value));
349
350       str = g_strdup_printf ("%s (%d)", enum_value->value_nick,
351                                         enum_value->value);
352     }
353     else {
354       str = g_strdup_value_contents (&value);
355     }
356     name = gst_object_get_path_string (orig);
357     g_print ("%s: %s = %s\n", name, pspec->name, str);
358     g_free (name);
359     g_free (str);
360     g_value_unset (&value);
361   } else {
362     name = gst_object_get_path_string (orig);
363     g_warning ("Parameter %s not readable in %s.",
364                pspec->name, name);
365     g_free (name);
366   }
367 }
368
369 static void
370 gst_object_set_name_default (GstObject *object)
371 {
372   gint count;
373   gchar *name, *tmp;
374   const gchar *type_name;
375   
376   type_name = G_OBJECT_TYPE_NAME (object);
377
378   /* to ensure guaranteed uniqueness across threads, only one thread
379    * may ever assign a name */
380   G_LOCK (object_name_mutex);
381
382   if (!object_name_counts)
383     object_name_counts = g_hash_table_new (g_str_hash, g_str_equal);
384
385   count = GPOINTER_TO_INT (g_hash_table_lookup (object_name_counts, type_name));
386   g_hash_table_insert (object_name_counts, g_strdup (type_name), 
387                        GINT_TO_POINTER (count + 1));
388   
389   G_UNLOCK (object_name_mutex);
390
391   /* GstFooSink -> foosinkN */
392   if (strncmp (type_name, "Gst", 3) == 0)
393     type_name += 3;
394   tmp = g_strdup_printf ("%s%d", type_name, count);
395   name = g_ascii_strdown (tmp, strlen (tmp));
396   g_free (tmp);
397   
398   gst_object_set_name (object, name);
399   g_free (name);
400 }
401
402 /**
403  * gst_object_set_name:
404  * @object: GstObject to set the name of
405  * @name: new name of object
406  *
407  * Sets the name of the object, or gives the element a guaranteed unique
408  * name (if @name is NULL).
409  */
410 void
411 gst_object_set_name (GstObject *object, const gchar *name)
412 {
413   g_return_if_fail (object != NULL);
414   g_return_if_fail (GST_IS_OBJECT (object));
415
416   if (object->name != NULL)
417     g_free (object->name);
418
419   if (name != NULL)
420     object->name = g_strdup (name);
421   else
422     gst_object_set_name_default (object);
423 }
424
425 /**
426  * gst_object_get_name:
427  * @object: GstObject to get the name of
428  *
429  * Get the name of the object.
430  *
431  * Returns: name of the object
432  */
433 const gchar*
434 gst_object_get_name (GstObject *object)
435 {
436   g_return_val_if_fail (GST_IS_OBJECT (object), NULL);
437
438   return object->name;
439 }
440
441 /**
442  * gst_object_set_parent:
443  * @object: GstObject to set parent of
444  * @parent: new parent of object
445  *
446  * Set the parent of the object.  The object's reference count is
447  * incremented.
448  * signals the parent-set signal
449  */
450 void
451 gst_object_set_parent (GstObject *object, GstObject *parent)
452 {
453   g_return_if_fail (object != NULL);
454   g_return_if_fail (GST_IS_OBJECT (object));
455   g_return_if_fail (parent != NULL);
456   g_return_if_fail (GST_IS_OBJECT (parent));
457   g_return_if_fail (object != parent);
458
459   if (object->parent != NULL) {
460     GST_ERROR_OBJECT (object,object->parent, "object's parent is already set, must unparent first");
461     return;
462   }
463
464   gst_object_ref (object);
465   gst_object_sink (object);
466   object->parent = parent;
467
468   g_signal_emit (G_OBJECT (object), gst_object_signals[PARENT_SET], 0, parent);
469 }
470
471 /**
472  * gst_object_get_parent:
473  * @object: GstObject to get parent of
474  *
475  * Return the parent of the object.
476  *
477  * Returns: parent of the object
478  */
479 GstObject*
480 gst_object_get_parent (GstObject *object)
481 {
482   g_return_val_if_fail (object != NULL, NULL);
483   g_return_val_if_fail (GST_IS_OBJECT (object), NULL);
484
485   return object->parent;
486 }
487
488 /**
489  * gst_object_unparent:
490  * @object: GstObject to unparent
491  *
492  * Clear the parent of the object, removing the associated reference.
493  */
494 void
495 gst_object_unparent (GstObject *object)
496 {
497   g_return_if_fail (object != NULL);
498   g_return_if_fail (GST_IS_OBJECT(object));
499   if (object->parent == NULL)
500     return;
501
502   GST_DEBUG (GST_CAT_REFCOUNTING, "unparent '%s'",GST_OBJECT_NAME(object));
503   
504   g_signal_emit (G_OBJECT (object), gst_object_signals[PARENT_UNSET], 0, object->parent);
505
506   object->parent = NULL;
507   gst_object_unref (object);
508 }
509
510 /**
511  * gst_object_check_uniqueness:
512  * @list: a list of #GstObject to check through
513  * @name: the name to search for
514  *
515  * This function checks through the list of objects to see if the name
516  * given appears in the list as the name of an object.  It returns TRUE if
517  * the name does not exist in the list.
518  *
519  * Returns: TRUE if the name doesn't appear in the list, FALSE if it does.
520  */
521 gboolean
522 gst_object_check_uniqueness (GList *list, const gchar *name)
523 {
524   g_return_val_if_fail (name != NULL, FALSE);
525
526   while (list) {
527     GstObject *child = GST_OBJECT (list->data);
528
529     list = g_list_next (list);
530       
531     if (strcmp (GST_OBJECT_NAME (child), name) == 0) 
532       return FALSE;
533   }
534
535   return TRUE;
536 }
537
538
539 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
540 /**
541  * gst_object_save_thyself:
542  * @object: GstObject to save
543  * @parent: The parent XML node to save the object into
544  *
545  * Saves the given object into the parent XML node.
546  *
547  * Returns: the new xmlNodePtr with the saved object
548  */
549 xmlNodePtr
550 gst_object_save_thyself (GstObject *object, xmlNodePtr parent)
551 {
552   GstObjectClass *oclass;
553
554   g_return_val_if_fail (object != NULL, parent);
555   g_return_val_if_fail (GST_IS_OBJECT (object), parent);
556   g_return_val_if_fail (parent != NULL, parent);
557
558   oclass = (GstObjectClass *)G_OBJECT_GET_CLASS(object);
559   if (oclass->save_thyself)
560     oclass->save_thyself (object, parent);
561
562   g_signal_emit (G_OBJECT (object), gst_object_signals[OBJECT_SAVED], 0, parent);
563
564   return parent;
565 }
566
567 /**
568  * gst_object_restore_thyself:
569  * @object: GstObject to load into
570  * @self: The XML node to load the object from
571  *
572  * Restores the given object with the data from the parent XML node.
573  */
574 void
575 gst_object_restore_thyself (GstObject *object, xmlNodePtr self)
576 {
577   GstObjectClass *oclass;
578
579   g_return_if_fail (object != NULL);
580   g_return_if_fail (GST_IS_OBJECT (object));
581   g_return_if_fail (self != NULL);
582
583   oclass = (GstObjectClass *) G_OBJECT_GET_CLASS(object);
584   if (oclass->restore_thyself)
585     oclass->restore_thyself (object, self);
586 }
587
588 static void
589 gst_object_real_restore_thyself (GstObject *object, xmlNodePtr self)
590 {
591   g_return_if_fail (object != NULL);
592   g_return_if_fail (GST_IS_OBJECT (object));
593   g_return_if_fail (self != NULL);
594   
595 /* FIXME: the signalobject stuff doesn't work
596  *  gst_class_signal_emit_by_name (object, "object_loaded", self); */
597 }
598 #endif /* GST_DISABLE_LOADSAVE_REGISTRY */
599
600 static void
601 gst_object_set_property (GObject* object, guint prop_id, 
602                          const GValue* value, GParamSpec* pspec)
603 {
604   GstObject *gstobject;
605             
606   /* it's not null if we got it, but it might not be ours */
607   g_return_if_fail (GST_IS_OBJECT (object));
608               
609   gstobject = GST_OBJECT (object);
610
611   switch (prop_id) {
612     case ARG_NAME:
613       gst_object_set_name (gstobject, g_value_get_string (value));
614       break;
615     default:
616       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
617       break;
618   }
619 }
620
621 static void
622 gst_object_get_property (GObject* object, guint prop_id, 
623                          GValue* value, GParamSpec* pspec)
624 {
625   GstObject *gstobject;
626             
627   /* it's not null if we got it, but it might not be ours */
628   g_return_if_fail (GST_IS_OBJECT (object));
629               
630   gstobject = GST_OBJECT (object);
631
632   switch (prop_id) {
633     case ARG_NAME:
634       g_value_set_string (value, (gchar*)GST_OBJECT_NAME (gstobject));
635       break;
636     default:
637       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
638       break;
639   }
640 }
641
642 /**
643  * gst_object_get_path_string:
644  * @object: GstObject to get the path from
645  *
646  * Generates a string describing the path of the object in
647  * the object hierarchy. Only useful (or used) for debugging
648  *
649  * Returns: a string describing the path of the object
650  */
651 gchar*
652 gst_object_get_path_string (GstObject *object)
653 {
654   GSList *parentage = NULL;
655   GSList *parents;
656   void *parent;
657   gchar *prevpath, *path;
658   const char *component;
659   gchar *separator = "";
660   gboolean free_component;
661
662   parentage = g_slist_prepend (NULL, object);
663
664   path = g_strdup ("");
665
666   /* first walk the object hierarchy to build a list of the parents */
667   do {
668     if (GST_IS_OBJECT (object)) {
669       parent = gst_object_get_parent (object);
670     } else {
671       parentage = g_slist_prepend (parentage, NULL);
672       parent = NULL;
673     }
674
675     if (parent != NULL) {
676       parentage = g_slist_prepend (parentage, parent);
677     }
678
679     object = parent;
680   } while (object != NULL);
681
682   /* then walk the parent list and print them out */
683   parents = parentage;
684   while (parents) {
685     if (GST_IS_OBJECT (parents->data)) {
686       GstObjectClass *oclass = (GstObjectClass *)G_OBJECT_GET_CLASS(parents->data);
687
688       component = gst_object_get_name (parents->data);
689       separator = oclass->path_string_separator;
690       free_component = FALSE;
691     } else {
692       component = g_strdup_printf("%p",parents->data);
693       separator = "/";
694       free_component = TRUE;
695     }
696
697     prevpath = path;
698     path = g_strjoin (separator, prevpath, component, NULL);
699     g_free(prevpath);
700     if (free_component)
701       g_free((gchar *)component);
702
703     parents = g_slist_next(parents);
704   }
705
706   g_slist_free (parentage);
707
708   return path;
709 }
710
711
712
713 struct _GstSignalObject {
714   GObject object;
715 };
716
717 struct _GstSignalObjectClass {
718   GObjectClass        parent_class;
719
720   /* signals */
721 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
722   void          (*object_loaded)           (GstSignalObject *object, GstObject *new, xmlNodePtr self);
723 #endif /* GST_DISABLE_LOADSAVE_REGISTRY */
724 };
725
726 static GType
727 gst_signal_object_get_type (void)
728 {
729   static GType signal_object_type = 0;
730
731   if (!signal_object_type) {
732     static const GTypeInfo signal_object_info = {
733       sizeof(GstSignalObjectClass),
734       NULL,
735       NULL,
736       (GClassInitFunc)gst_signal_object_class_init,
737       NULL,
738       NULL,
739       sizeof(GstSignalObject),
740       16,
741       (GInstanceInitFunc)gst_signal_object_init,
742       NULL
743     };
744     signal_object_type = g_type_register_static(G_TYPE_OBJECT, "GstSignalObject", &signal_object_info, 0);
745   }
746   return signal_object_type;
747 }
748
749 static void
750 gst_signal_object_class_init (GstSignalObjectClass *klass)
751 {
752   GObjectClass *gobject_class;
753
754   gobject_class = (GObjectClass*) klass;
755
756   parent_class = g_type_class_ref (G_TYPE_OBJECT);
757
758 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
759   gst_signal_object_signals[SO_OBJECT_LOADED] =
760     g_signal_new("object_loaded", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
761                   G_STRUCT_OFFSET (GstObjectClass, parent_set), NULL, NULL,
762                   gst_marshal_VOID__OBJECT_POINTER,G_TYPE_NONE,2,
763                   G_TYPE_OBJECT,G_TYPE_POINTER);
764 #endif
765 }
766
767 static void
768 gst_signal_object_init (GstSignalObject *object)
769 {
770 }
771
772 /**
773  * gst_class_signal_connect
774  * @klass: the GstObjectClass to attach the signal to
775  * @name: the name of the signal to attach to
776  * @func: the signal function
777  * @func_data: a pointer to user data
778  *
779  * Connect to a class signal.
780  *
781  * Returns: the signal id.
782  */
783 guint
784 gst_class_signal_connect (GstObjectClass *klass,
785                           const gchar    *name,
786                           gpointer  func,
787                           gpointer       func_data)
788 {
789   return g_signal_connect (klass->signal_object, name, func, func_data);
790 }
791
792 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
793 /**
794  * gst_class_signal_emit_by_name:
795  * @object: the object that sends the signal
796  * @name: the name of the signal to emit
797  * @self: data for the signal
798  *
799  * emits the named class signal.
800  */
801 void
802 gst_class_signal_emit_by_name (GstObject *object,
803                                const gchar *name,
804                                xmlNodePtr self)
805 {
806   GstObjectClass *oclass;
807
808   oclass = (GstObjectClass *)G_OBJECT_GET_CLASS(object);
809
810   g_signal_emit_by_name (oclass->signal_object, name, object, self);
811 }
812
813 #endif /* GST_DISABLE_LOADSAVE_REGISTRY */