2.0 beta init
[framework/multimedia/gstreamer0.10.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_finalize (GObject * object);
41
42 static GstPluginFeatureClass *factory_parent_class = NULL;
43
44 /* static guint gst_index_factory_signals[LAST_SIGNAL] = { 0 }; */
45 G_DEFINE_TYPE (GstIndexFactory, gst_index_factory, GST_TYPE_PLUGIN_FEATURE);
46
47 static void
48 gst_index_factory_class_init (GstIndexFactoryClass * klass)
49 {
50   GObjectClass *gobject_class = (GObjectClass *) klass;
51
52   factory_parent_class = g_type_class_peek_parent (klass);
53
54   gobject_class->finalize = gst_index_factory_finalize;
55 }
56
57 static void
58 gst_index_factory_init (GstIndexFactory * factory)
59 {
60 }
61
62 static void
63 gst_index_factory_finalize (GObject * object)
64 {
65   GstIndexFactory *factory = GST_INDEX_FACTORY (object);
66
67   g_free (factory->longdesc);
68
69   G_OBJECT_CLASS (factory_parent_class)->finalize (object);
70
71 }
72
73 /**
74  * gst_index_factory_new:
75  * @name: name of indexfactory to create
76  * @longdesc: long description of indexfactory to create
77  * @type: the GType of the GstIndex element of this factory
78  *
79  * Create a new indexfactory with the given parameters
80  *
81  * Returns: (transfer full): a new #GstIndexFactory.
82  */
83 GstIndexFactory *
84 gst_index_factory_new (const gchar * name, const gchar * longdesc, GType type)
85 {
86   GstIndexFactory *factory;
87
88   g_return_val_if_fail (name != NULL, NULL);
89   factory = GST_INDEX_FACTORY (g_object_newv (GST_TYPE_INDEX_FACTORY, 0, NULL));
90
91   gst_plugin_feature_set_name (GST_PLUGIN_FEATURE (factory), name);
92   if (factory->longdesc)
93     g_free (factory->longdesc);
94   factory->longdesc = g_strdup (longdesc);
95   factory->type = type;
96
97   return factory;
98 }
99
100 /**
101  * gst_index_factory_destroy:
102  * @factory: factory to destroy
103  *
104  * Removes the index from the global list.
105  */
106 void
107 gst_index_factory_destroy (GstIndexFactory * factory)
108 {
109   g_return_if_fail (factory != NULL);
110
111   /* we don't free the struct bacause someone might  have a handle to it.. */
112   /* FIXME: gst_index_factory_destroy */
113 }
114
115 /**
116  * gst_index_factory_find:
117  * @name: name of indexfactory to find
118  *
119  * Search for an indexfactory of the given name.
120  *
121  * Returns: (transfer full): #GstIndexFactory if found, NULL otherwise
122  */
123 GstIndexFactory *
124 gst_index_factory_find (const gchar * name)
125 {
126   GstPluginFeature *feature;
127
128   g_return_val_if_fail (name != NULL, NULL);
129
130   GST_DEBUG ("gstindex: find \"%s\"", name);
131
132   feature = gst_registry_find_feature (gst_registry_get_default (), name,
133       GST_TYPE_INDEX_FACTORY);
134   if (feature)
135     return GST_INDEX_FACTORY (feature);
136
137   return NULL;
138 }
139
140 /**
141  * gst_index_factory_create:
142  * @factory: the factory used to create the instance
143  *
144  * Create a new #GstIndex instance from the
145  * given indexfactory.
146  *
147  * Returns: (transfer full): a new #GstIndex instance.
148  */
149 GstIndex *
150 gst_index_factory_create (GstIndexFactory * factory)
151 {
152   GstIndexFactory *newfactory;
153   GstIndex *new = NULL;
154
155   g_return_val_if_fail (factory != NULL, NULL);
156
157   newfactory =
158       GST_INDEX_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
159           (factory)));
160   if (newfactory == NULL)
161     return NULL;
162
163   new = GST_INDEX (g_object_newv (newfactory->type, 0, NULL));
164
165   gst_object_unref (newfactory);
166
167   return new;
168 }
169
170 /**
171  * gst_index_factory_make:
172  * @name: the name of the factory used to create the instance
173  *
174  * Create a new #GstIndex instance from the
175  * indexfactory with the given name.
176  *
177  * Returns: (transfer full): a new #GstIndex instance.
178  */
179 GstIndex *
180 gst_index_factory_make (const gchar * name)
181 {
182   GstIndexFactory *factory;
183   GstIndex *index;
184
185   g_return_val_if_fail (name != NULL, NULL);
186
187   factory = gst_index_factory_find (name);
188
189   if (factory == NULL)
190     goto no_factory;
191
192   index = gst_index_factory_create (factory);
193
194   if (index == NULL)
195     goto create_failed;
196
197   gst_object_unref (factory);
198   return index;
199
200   /* ERRORS */
201 no_factory:
202   {
203     GST_INFO ("no such index factory \"%s\"!", name);
204     return NULL;
205   }
206 create_failed:
207   {
208     GST_INFO_OBJECT (factory, "couldn't create instance!");
209     gst_object_unref (factory);
210     return NULL;
211   }
212 }