filter newlines out of GST_DEBUG statements to reflect new core behavior fixes to...
[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 #ifndef GST_DISABLE_REGISTRY
31 static xmlNodePtr       gst_plugin_feature_save_thyself         (GstObject *object, xmlNodePtr parent);
32 static void             gst_plugin_feature_restore_thyself      (GstObject *object, xmlNodePtr parent);
33 #endif /* GST_DISABLE_REGISTRY */
34
35 static GstObjectClass *parent_class = NULL;
36 /* static guint gst_plugin_feature_signals[LAST_SIGNAL] = { 0 }; */
37
38 GType
39 gst_plugin_feature_get_type (void)
40 {
41   static GType plugin_feature_type = 0;
42
43   if (!plugin_feature_type) {
44     static const GTypeInfo plugin_feature_info = {
45       sizeof (GstObjectClass),
46       NULL,
47       NULL,
48       (GClassInitFunc) gst_plugin_feature_class_init,
49       NULL,
50       NULL,
51       sizeof (GstObject),
52       32,
53       (GInstanceInitFunc) gst_plugin_feature_init,
54       NULL
55     };
56     plugin_feature_type = g_type_register_static (GST_TYPE_OBJECT, "GstPluginFeature", 
57                                                   &plugin_feature_info, G_TYPE_FLAG_ABSTRACT);
58   }
59   return plugin_feature_type;
60 }
61
62 static void
63 gst_plugin_feature_class_init (GstPluginFeatureClass *klass)
64 {
65   GObjectClass *gobject_class;
66   GstObjectClass *gstobject_class;
67
68   gobject_class = (GObjectClass*) klass;
69   gstobject_class = (GstObjectClass*) klass;
70
71   parent_class = g_type_class_ref (GST_TYPE_OBJECT);
72
73 #ifndef GST_DISABLE_REGISTRY
74   gstobject_class->save_thyself =       GST_DEBUG_FUNCPTR (gst_plugin_feature_save_thyself);
75   gstobject_class->restore_thyself =    GST_DEBUG_FUNCPTR (gst_plugin_feature_restore_thyself);
76 #endif /* GST_DISABLE_REGISTRY */
77 }
78
79 static void
80 gst_plugin_feature_init (GstPluginFeature *feature)
81 {
82   feature->manager = NULL;
83 }
84
85 #ifndef GST_DISABLE_REGISTRY
86 static xmlNodePtr
87 gst_plugin_feature_save_thyself (GstObject *object, xmlNodePtr parent)
88 {
89   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (object), parent);
90
91   xmlNewChild (parent, NULL, "name", GST_OBJECT_NAME (object));
92
93   return parent;
94 }
95
96 static void
97 gst_plugin_feature_restore_thyself (GstObject *object, xmlNodePtr parent)
98 {
99   xmlNodePtr field = parent->xmlChildrenNode;
100
101   g_return_if_fail (GST_IS_PLUGIN_FEATURE (object));
102
103   while (field) {
104     if (!strcmp (field->name, "name")) {
105       gst_object_set_name (object, xmlNodeGetContent (field));
106       break;
107     }
108     field = field->next;
109   }
110 }
111 #endif /* GST_DISABLE_REGISTRY */
112
113 /**
114  * gst_plugin_feature_ensure_loaded:
115  * @feature: the plugin feature to check
116  *
117  * Check if the plugin containing the feature is loaded,
118  * if not, the plugin will be loaded.
119  *
120  * Returns: a boolean indicating the feature is loaded.
121  */
122 gboolean
123 gst_plugin_feature_ensure_loaded (GstPluginFeature *feature)
124 {
125   GstPlugin *plugin = (GstPlugin *) (feature->manager);
126
127   if (plugin && !gst_plugin_is_loaded (plugin)) {
128     GST_DEBUG (GST_CAT_PLUGIN_LOADING, "loading plugin %s for feature", plugin->name);
129     
130     return gst_plugin_load_plugin (plugin);
131   }
132   return TRUE;
133 }
134
135 /**
136  * gst_plugin_feature_unload_thyself:
137  * @feature: the plugin feature to check
138  *
139  * Unload the given feature. This will decrease the refcount
140  * in the plugin and will eventually unload the plugin
141  */
142 void
143 gst_plugin_feature_unload_thyself (GstPluginFeature *feature)
144 {
145   GstPluginFeatureClass *oclass; 
146
147   g_return_if_fail (feature != NULL);
148   g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
149   
150   oclass = (GstPluginFeatureClass *)G_OBJECT_GET_CLASS (feature);
151
152   if (oclass->unload_thyself)
153     oclass->unload_thyself (feature);
154 }
155
156
157