gst/gstbin.c: Help the compiler a bit with type registration.
[platform/upstream/gstreamer.git] / gst / gstindexfactory.c
1 /* GStreamer
2  * Copyright (C) 2001 RidgeRun (http://www.ridgerun.com/)
3  * Written by Erik Walthinsen <omega@ridgerun.com>
4  *
5  * gstindexfactory.c: Index for mappings and other data
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 /**
24  * SECTION:gstindexfactory
25  * @short_description: Create GstIndexes from a factory
26  * @see_also: #GstIndex
27  *
28  * GstIndexFactory is used to dynamically create GstIndex implementations.
29  */
30
31
32 #include "gst_private.h"
33
34 #include "gstinfo.h"
35 #include "gstindex.h"
36 #include "gstindexfactory.h"
37 #include "gstmarshal.h"
38 #include "gstregistry.h"
39
40 static void gst_index_factory_class_init (GstIndexFactoryClass * klass);
41 static void gst_index_factory_init (GstIndexFactory * factory);
42 static void gst_index_factory_finalize (GObject * object);
43
44 static GstPluginFeatureClass *factory_parent_class = NULL;
45
46 /* static guint gst_index_factory_signals[LAST_SIGNAL] = { 0 }; */
47
48 GType
49 gst_index_factory_get_type (void)
50 {
51   static GType indexfactory_type = 0;
52
53   if (G_UNLIKELY (indexfactory_type == 0)) {
54     static const GTypeInfo indexfactory_info = {
55       sizeof (GstIndexFactoryClass),
56       NULL,
57       NULL,
58       (GClassInitFunc) gst_index_factory_class_init,
59       NULL,
60       NULL,
61       sizeof (GstIndexFactory),
62       0,
63       (GInstanceInitFunc) gst_index_factory_init,
64       NULL
65     };
66
67     indexfactory_type = g_type_register_static (GST_TYPE_PLUGIN_FEATURE,
68         "GstIndexFactory", &indexfactory_info, 0);
69   }
70   return indexfactory_type;
71 }
72
73 static void
74 gst_index_factory_class_init (GstIndexFactoryClass * klass)
75 {
76   GObjectClass *gobject_class;
77   GstObjectClass *gstobject_class;
78   GstPluginFeatureClass *gstpluginfeature_class;
79
80   gobject_class = (GObjectClass *) klass;
81   gstobject_class = (GstObjectClass *) klass;
82   gstpluginfeature_class = (GstPluginFeatureClass *) klass;
83
84   factory_parent_class = g_type_class_ref (GST_TYPE_PLUGIN_FEATURE);
85
86   gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_index_factory_finalize);
87 }
88
89 static void
90 gst_index_factory_init (GstIndexFactory * factory)
91 {
92 }
93
94 static void
95 gst_index_factory_finalize (GObject * object)
96 {
97   GstIndexFactory *factory = GST_INDEX_FACTORY (object);
98
99   g_free (factory->longdesc);
100
101   G_OBJECT_CLASS (factory_parent_class)->finalize (object);
102
103 }
104
105 /**
106  * gst_index_factory_new:
107  * @name: name of indexfactory to create
108  * @longdesc: long description of indexfactory to create
109  * @type: the GType of the GstIndex element of this factory
110  *
111  * Create a new indexfactory with the given parameters
112  *
113  * Returns: a new #GstIndexFactory.
114  */
115 GstIndexFactory *
116 gst_index_factory_new (const gchar * name, const gchar * longdesc, GType type)
117 {
118   GstIndexFactory *factory;
119
120   g_return_val_if_fail (name != NULL, NULL);
121   factory = GST_INDEX_FACTORY (g_object_new (GST_TYPE_INDEX_FACTORY, NULL));
122
123   GST_PLUGIN_FEATURE_NAME (factory) = g_strdup (name);
124   if (factory->longdesc)
125     g_free (factory->longdesc);
126   factory->longdesc = g_strdup (longdesc);
127   factory->type = type;
128
129   return factory;
130 }
131
132 /**
133  * gst_index_factory_destroy:
134  * @factory: factory to destroy
135  *
136  * Removes the index from the global list.
137  */
138 void
139 gst_index_factory_destroy (GstIndexFactory * factory)
140 {
141   g_return_if_fail (factory != NULL);
142
143   /* we don't free the struct bacause someone might  have a handle to it.. */
144 }
145
146 /**
147  * gst_index_factory_find:
148  * @name: name of indexfactory to find
149  *
150  * Search for an indexfactory of the given name.
151  *
152  * Returns: #GstIndexFactory if found, NULL otherwise
153  */
154 GstIndexFactory *
155 gst_index_factory_find (const gchar * name)
156 {
157   GstPluginFeature *feature;
158
159   g_return_val_if_fail (name != NULL, NULL);
160
161   GST_DEBUG ("gstindex: find \"%s\"", name);
162
163   feature = gst_registry_find_feature (gst_registry_get_default (), name,
164       GST_TYPE_INDEX_FACTORY);
165   if (feature)
166     return GST_INDEX_FACTORY (feature);
167
168   return NULL;
169 }
170
171 /**
172  * gst_index_factory_create:
173  * @factory: the factory used to create the instance
174  *
175  * Create a new #GstIndex instance from the
176  * given indexfactory.
177  *
178  * Returns: A new #GstIndex instance.
179  */
180 GstIndex *
181 gst_index_factory_create (GstIndexFactory * factory)
182 {
183   GstIndexFactory *newfactory;
184   GstIndex *new = NULL;
185
186   g_return_val_if_fail (factory != NULL, NULL);
187
188   newfactory =
189       GST_INDEX_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
190           (factory)));
191   if (newfactory == NULL)
192     return NULL;
193
194   new = GST_INDEX (g_object_new (newfactory->type, NULL));
195
196   gst_object_unref (newfactory);
197
198   return new;
199 }
200
201 /**
202  * gst_index_factory_make:
203  * @name: the name of the factory used to create the instance
204  *
205  * Create a new #GstIndex instance from the
206  * indexfactory with the given name.
207  *
208  * Returns: A new #GstIndex instance.
209  */
210 GstIndex *
211 gst_index_factory_make (const gchar * name)
212 {
213   GstIndexFactory *factory;
214
215   g_return_val_if_fail (name != NULL, NULL);
216
217   factory = gst_index_factory_find (name);
218
219   if (factory == NULL)
220     return NULL;
221
222   return gst_index_factory_create (factory);
223 }