2 * Copyright (C) 2010 Ole André Vadla Ravnås <oravnas@cisco.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 #include "dynapi-internal.h"
27 GST_DEBUG_CATEGORY (gst_dyn_api_debug);
28 #define GST_CAT_DEFAULT gst_dyn_api_debug
36 struct _GstDynApiPrivate
42 G_DEFINE_TYPE (GstDynApi, gst_dyn_api, G_TYPE_OBJECT);
45 gst_dyn_api_init (GstDynApi * self)
47 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GST_TYPE_DYN_API,
52 gst_dyn_api_dispose (GObject * object)
54 GstDynApi *self = GST_DYN_API_CAST (object);
55 GstDynApiPrivate *priv = self->priv;
57 if (priv->module != NULL) {
58 g_module_close (priv->module);
62 G_OBJECT_CLASS (gst_dyn_api_parent_class)->dispose (object);
66 gst_dyn_api_finalize (GObject * object)
68 GstDynApi *self = GST_DYN_API_CAST (object);
69 GstDynApiPrivate *priv = self->priv;
71 g_free (priv->filename);
73 G_OBJECT_CLASS (gst_dyn_api_parent_class)->finalize (object);
77 gst_dyn_api_get_property (GObject * object, guint prop_id,
78 GValue * value, GParamSpec * pspec)
80 GstDynApi *self = GST_DYN_API (object);
84 g_value_set_string (value, self->priv->filename);
87 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
93 gst_dyn_api_set_property (GObject * object, guint prop_id,
94 const GValue * value, GParamSpec * pspec)
96 GstDynApi *self = GST_DYN_API (object);
100 g_free (self->priv->filename);
101 self->priv->filename = g_value_dup_string (value);
104 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
110 gst_dyn_api_class_init (GstDynApiClass * klass)
112 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
114 gobject_class->dispose = gst_dyn_api_dispose;
115 gobject_class->finalize = gst_dyn_api_finalize;
116 gobject_class->get_property = gst_dyn_api_get_property;
117 gobject_class->set_property = gst_dyn_api_set_property;
119 g_type_class_add_private (klass, sizeof (GstDynApiPrivate));
121 g_object_class_install_property (gobject_class, PROP_FILENAME,
122 g_param_spec_string ("filename", "Filename", "Filename", NULL,
123 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
127 _gst_dyn_api_new (GType derived_type, const gchar * filename,
128 const GstDynSymSpec * symbols, GError ** error)
131 GstDynApiPrivate *priv;
133 GArray *names_not_found;
135 api = g_object_new (derived_type, "filename", filename, NULL);
138 priv->module = g_module_open (priv->filename, 0);
139 if (priv->module == NULL)
142 names_not_found = g_array_new (TRUE, FALSE, sizeof (gchar *));
144 for (i = 0; symbols[i].name != NULL; i++) {
145 const GstDynSymSpec *s = &symbols[i];
146 if (!g_module_symbol (priv->module, s->name,
147 (gpointer *) (((guint8 *) api) + s->offset)) && s->is_required) {
148 g_array_append_val (names_not_found, s->name);
152 if (names_not_found->len > 0)
153 goto one_or_more_name_not_found;
155 g_array_free (names_not_found, TRUE);
164 basename = g_path_get_basename (filename);
165 g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_FAILED,
166 "failed to open %s", basename);
171 one_or_more_name_not_found:
173 gchar *basename, *names_joined;
175 basename = g_path_get_basename (filename);
176 names_joined = g_strjoinv (", ", (gchar **) names_not_found->data);
177 g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_FAILED,
178 "missing %u symbol%s in %s: %s",
179 names_not_found->len, (names_not_found->len == 1) ? "" : "s",
180 basename, names_joined);
181 g_free (names_joined);
183 g_array_free (names_not_found, TRUE);
189 g_object_unref (api);