formatter: Pass a dummy instance of formatter to virtual method

Instead of passing the class itself
This commit is contained in:
Thibault Saunier 2013-04-22 17:34:09 -03:00
parent adf5ec9fe0
commit f3372dfb0f
4 changed files with 30 additions and 22 deletions

View file

@ -182,26 +182,22 @@ failed:
***********************************************/ ***********************************************/
static gboolean static gboolean
_can_load_uri (GESFormatterClass * class, const gchar * uri, GError ** error) _can_load_uri (GESFormatter * dummy_formatter, const gchar * uri,
GError ** error)
{ {
gboolean ret = FALSE;
GMarkupParseContext *ctx; GMarkupParseContext *ctx;
GESBaseXmlFormatter *self = GES_BASE_XML_FORMATTER (dummy_formatter);
/* we create a temporary object so we can use it as a context */ /* we create a temporary object so we can use it as a context */
GESBaseXmlFormatter *self = g_object_new (G_OBJECT_CLASS_TYPE (class), NULL);
_GET_PRIV (self)->check_only = TRUE; _GET_PRIV (self)->check_only = TRUE;
ctx = create_parser_context (self, uri, error); ctx = create_parser_context (self, uri, error);
if (!ctx) if (!ctx)
goto done; return FALSE;
ret = TRUE;
g_markup_parse_context_free (ctx); g_markup_parse_context_free (ctx);
return TRUE;
done:
gst_object_unref (self);
return ret;
} }
static gboolean static gboolean

View file

@ -46,9 +46,9 @@ struct _GESFormatterPrivate
}; };
static void ges_formatter_dispose (GObject * object); static void ges_formatter_dispose (GObject * object);
static gboolean default_can_load_uri (GESFormatterClass * class, static gboolean default_can_load_uri (GESFormatter * dummy_instance,
const gchar * uri, GError ** error); const gchar * uri, GError ** error);
static gboolean default_can_save_uri (GESFormatterClass * class, static gboolean default_can_save_uri (GESFormatter * dummy_instance,
const gchar * uri, GError ** error); const gchar * uri, GError ** error);
/* GESExtractable implementation */ /* GESExtractable implementation */
@ -146,20 +146,21 @@ ges_formatter_dispose (GObject * object)
} }
static gboolean static gboolean
default_can_load_uri (GESFormatterClass * class, const gchar * uri, default_can_load_uri (GESFormatter * dummy_instance, const gchar * uri,
GError ** error) GError ** error)
{ {
GST_DEBUG ("%s: no 'can_load_uri' vmethod implementation", GST_DEBUG ("%s: no 'can_load_uri' vmethod implementation",
g_type_name (G_OBJECT_CLASS_TYPE (class))); G_OBJECT_TYPE_NAME (dummy_instance));
return FALSE; return FALSE;
} }
static gboolean static gboolean
default_can_save_uri (GESFormatterClass * class, default_can_save_uri (GESFormatter * dummy_instance,
const gchar * uri, GError ** error) const gchar * uri, GError ** error)
{ {
GST_DEBUG ("%s: no 'can_save_uri' vmethod implementation", GST_DEBUG ("%s: no 'can_save_uri' vmethod implementation",
g_type_name (G_OBJECT_CLASS_TYPE (class))); G_OBJECT_TYPE_NAME (dummy_instance));
return FALSE; return FALSE;
} }
@ -236,6 +237,7 @@ ges_formatter_can_load_uri (const gchar * uri, GError ** error)
formatter_assets = ges_list_assets (GES_TYPE_FORMATTER); formatter_assets = ges_list_assets (GES_TYPE_FORMATTER);
for (tmp = formatter_assets; tmp; tmp = tmp->next) { for (tmp = formatter_assets; tmp; tmp = tmp->next) {
GESAsset *asset = GES_ASSET (tmp->data); GESAsset *asset = GES_ASSET (tmp->data);
GESFormatter *dummy_instance;
if (extension if (extension
&& g_strcmp0 (extension, && g_strcmp0 (extension,
@ -244,12 +246,16 @@ ges_formatter_can_load_uri (const gchar * uri, GError ** error)
continue; continue;
class = g_type_class_ref (ges_asset_get_extractable_type (asset)); class = g_type_class_ref (ges_asset_get_extractable_type (asset));
if (class->can_load_uri (class, uri, error)) { dummy_instance =
g_object_new (ges_asset_get_extractable_type (asset), NULL);
if (class->can_load_uri (dummy_instance, uri, error)) {
g_type_class_unref (class); g_type_class_unref (class);
gst_object_unref (dummy_instance);
ret = TRUE; ret = TRUE;
break; break;
} }
g_type_class_unref (class); g_type_class_unref (class);
gst_object_unref (dummy_instance);
} }
g_list_free (formatter_assets); g_list_free (formatter_assets);
@ -303,8 +309,8 @@ ges_formatter_can_save_uri (const gchar * uri, GError ** error)
*/ */
gboolean gboolean
ges_formatter_load_from_uri (GESFormatter * formatter, GESTimeline * timeline, ges_formatter_load_from_uri (GESFormatter * formatter,
const gchar * uri, GError ** error) GESTimeline * timeline, const gchar * uri, GError ** error)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
GESFormatterClass *klass = GES_FORMATTER_GET_CLASS (formatter); GESFormatterClass *klass = GES_FORMATTER_GET_CLASS (formatter);
@ -464,16 +470,22 @@ _find_formatter_asset_for_uri (const gchar * uri)
formatter_assets = ges_list_assets (GES_TYPE_FORMATTER); formatter_assets = ges_list_assets (GES_TYPE_FORMATTER);
for (tmp = formatter_assets; tmp; tmp = tmp->next) { for (tmp = formatter_assets; tmp; tmp = tmp->next) {
GESFormatter *dummy_instance;
asset = GES_ASSET (tmp->data); asset = GES_ASSET (tmp->data);
class = g_type_class_ref (ges_asset_get_extractable_type (asset)); class = g_type_class_ref (ges_asset_get_extractable_type (asset));
if (class->can_load_uri (class, uri, NULL)) { dummy_instance =
g_object_new (ges_asset_get_extractable_type (asset), NULL);
if (class->can_load_uri (dummy_instance, uri, NULL)) {
g_type_class_unref (class); g_type_class_unref (class);
asset = gst_object_ref (asset); asset = gst_object_ref (asset);
gst_object_unref (dummy_instance);
break; break;
} }
asset = NULL; asset = NULL;
g_type_class_unref (class); g_type_class_unref (class);
gst_object_unref (dummy_instance);
} }
g_list_free (formatter_assets); g_list_free (formatter_assets);

View file

@ -63,8 +63,8 @@ struct _GESFormatter {
gpointer _ges_reserved[GES_PADDING]; gpointer _ges_reserved[GES_PADDING];
}; };
typedef gboolean (*GESFormatterCanLoadURIMethod) (GESFormatterClass *class, const gchar * uri, GError **error); typedef gboolean (*GESFormatterCanLoadURIMethod) (GESFormatter *dummy_instance, const gchar * uri, GError **error);
typedef gboolean (*GESFormatterCanSaveURIMethod) (GESFormatterClass *class, const gchar * uri, GError **error); typedef gboolean (*GESFormatterCanSaveURIMethod) (GESFormatter *dummy_instance, const gchar * uri, GError **error);
/** /**
* GESFormatterLoadFromURIMethod: * GESFormatterLoadFromURIMethod:

View file

@ -99,7 +99,7 @@ list_table_destroyer (gpointer key, gpointer value, void *unused)
} }
static gboolean static gboolean
pitivi_can_load_uri (GESFormatterClass * class, const gchar * uri, pitivi_can_load_uri (GESFormatter * dummy_instance, const gchar * uri,
GError ** error) GError ** error)
{ {
xmlDocPtr doc; xmlDocPtr doc;