Small cleanup
[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 #include "gstregistry.h"
27 #include "gstlog.h"
28
29 static void             gst_plugin_feature_class_init           (GstPluginFeatureClass *klass);
30 static void             gst_plugin_feature_init                 (GstPluginFeature *feature);
31
32 static GObjectClass *parent_class = NULL;
33 /* static guint gst_plugin_feature_signals[LAST_SIGNAL] = { 0 }; */
34
35 GType
36 gst_plugin_feature_get_type (void)
37 {
38   static GType plugin_feature_type = 0;
39
40   if (!plugin_feature_type) {
41     static const GTypeInfo plugin_feature_info = {
42       sizeof (GObjectClass),
43       NULL,
44       NULL,
45       (GClassInitFunc) gst_plugin_feature_class_init,
46       NULL,
47       NULL,
48       sizeof (GObject),
49       32,
50       (GInstanceInitFunc) gst_plugin_feature_init,
51       NULL
52     };
53     plugin_feature_type = g_type_register_static (G_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
64   gobject_class = (GObjectClass*) klass;
65
66   parent_class = g_type_class_ref (G_TYPE_OBJECT);
67 }
68
69 static void
70 gst_plugin_feature_init (GstPluginFeature *feature)
71 {
72   feature->manager = NULL;
73 }
74
75 /**
76  * gst_plugin_feature_ensure_loaded:
77  * @feature: the plugin feature to check
78  *
79  * Check if the plugin containing the feature is loaded,
80  * if not, the plugin will be loaded.
81  *
82  * Returns: a boolean indicating the feature is loaded.
83  */
84 gboolean
85 gst_plugin_feature_ensure_loaded (GstPluginFeature *feature)
86 {
87   GstPlugin *plugin;
88   
89   g_return_val_if_fail (feature != NULL, FALSE);
90   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
91
92   plugin = (GstPlugin *) (feature->manager);
93
94   if (plugin && !gst_plugin_is_loaded (plugin)) {
95     if (GST_IS_REGISTRY (plugin->manager)) {
96       GST_DEBUG (GST_CAT_PLUGIN_LOADING, 
97                  "loading plugin %s for feature", plugin->name);
98
99       if (gst_registry_load_plugin (GST_REGISTRY (plugin->manager), plugin) != GST_REGISTRY_OK)
100         return FALSE;
101     }
102     else
103       return FALSE;
104   }
105   return TRUE;
106 }
107
108 /**
109  * gst_plugin_feature_unload_thyself:
110  * @feature: the plugin feature to check
111  *
112  * Unload the given feature. This will decrease the refcount
113  * in the plugin and will eventually unload the plugin
114  */
115 void
116 gst_plugin_feature_unload_thyself (GstPluginFeature *feature)
117 {
118   GstPluginFeatureClass *oclass; 
119
120   g_return_if_fail (feature != NULL);
121   g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
122   
123   oclass = GST_PLUGIN_FEATURE_GET_CLASS (feature);
124
125   if (oclass->unload_thyself)
126     oclass->unload_thyself (feature);
127 }
128
129
130