Lots of modifications to the plugin system.
[platform/upstream/gstreamer.git] / gst / gstpluginfeature.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gstpluginfeature.c: Abstract base class for all plugin features
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 #include "gstpluginfeature.h"
25 #include "gstplugin.h"
26
27 static void             gst_plugin_feature_class_init           (GstPluginFeatureClass *klass);
28 static void             gst_plugin_feature_init                 (GstPluginFeature *feature);
29
30 static xmlNodePtr       gst_plugin_feature_save_thyself         (GstObject *object, xmlNodePtr parent);
31 static void             gst_plugin_feature_restore_thyself      (GstObject *object, xmlNodePtr parent);
32
33 static GstObjectClass *parent_class = NULL;
34 //static guint gst_plugin_feature_signals[LAST_SIGNAL] = { 0 };
35
36 GType
37 gst_plugin_feature_get_type (void)
38 {
39   static GType plugin_feature_type = 0;
40
41   if (!plugin_feature_type) {
42     static const GTypeInfo plugin_feature_info = {
43       sizeof (GstObjectClass),
44       NULL,
45       NULL,
46       (GClassInitFunc) gst_plugin_feature_class_init,
47       NULL,
48       NULL,
49       sizeof (GstObject),
50       32,
51       (GInstanceInitFunc) gst_plugin_feature_init,
52     };
53     plugin_feature_type = g_type_register_static (GST_TYPE_OBJECT, "GstPluginFeature", 
54                                                   &plugin_feature_info, G_TYPE_FLAG_ABSTRACT);
55   }
56   return plugin_feature_type;
57 }
58
59 static void
60 gst_plugin_feature_class_init (GstPluginFeatureClass *klass)
61 {
62   GObjectClass *gobject_class;
63   GstObjectClass *gstobject_class;
64
65   gobject_class = (GObjectClass*) klass;
66   gstobject_class = (GstObjectClass*) klass;
67
68   parent_class = g_type_class_ref (GST_TYPE_OBJECT);
69
70   gstobject_class->save_thyself =       GST_DEBUG_FUNCPTR (gst_plugin_feature_save_thyself);
71   gstobject_class->restore_thyself =    GST_DEBUG_FUNCPTR (gst_plugin_feature_restore_thyself);
72 }
73
74 static void
75 gst_plugin_feature_init (GstPluginFeature *feature)
76 {
77   feature->manager = NULL;
78 }
79
80 static xmlNodePtr
81 gst_plugin_feature_save_thyself (GstObject *object, xmlNodePtr parent)
82 {
83   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (object), parent);
84
85   xmlNewChild (parent, NULL, "name", GST_OBJECT_NAME (object));
86
87   return parent;
88 }
89
90 static void
91 gst_plugin_feature_restore_thyself (GstObject *object, xmlNodePtr parent)
92 {
93   xmlNodePtr field = parent->xmlChildrenNode;
94
95   g_return_if_fail (GST_IS_PLUGIN_FEATURE (object));
96
97   while (field) {
98     if (!strcmp (field->name, "name")) {
99       gst_object_set_name (object, xmlNodeGetContent (field));
100       break;
101     }
102     field = field->next;
103   }
104 }
105
106 void
107 gst_plugin_feature_ensure_loaded (GstPluginFeature *feature)
108 {
109   GstPlugin *plugin = (GstPlugin *) (feature->manager);
110
111   if (plugin && !gst_plugin_is_loaded (plugin)) {
112     GST_DEBUG (GST_CAT_PLUGIN_LOADING, "loading plugin %s for feature\n", plugin->name);
113     
114     gst_plugin_load_plugin (plugin);
115   }
116 }
117
118 void
119 gst_plugin_feature_unload_thyself (GstPluginFeature *feature)
120 {
121   GstPluginFeatureClass *oclass; 
122
123   g_return_if_fail (feature != NULL);
124   g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
125   
126   oclass = (GstPluginFeatureClass *)G_OBJECT_GET_CLASS (feature);
127
128   if (oclass->unload_thyself)
129     oclass->unload_thyself (feature);
130 }
131
132
133