urihandler: pass GError argument to gst_uri_handler_set_uri()

Also let gst_uri_handler_set_uri check already if the protocol
is supported, so that not every uri handler has to do that
itself.
This commit is contained in:
Tim-Philipp Müller 2011-11-13 17:44:06 +00:00
parent 35df64357f
commit 682704750c
5 changed files with 85 additions and 6 deletions

View file

@ -391,6 +391,18 @@ The 0.11 porting guide
allows bindings to properly use GstIterator and prevents complex allows bindings to properly use GstIterator and prevents complex
return value ownership issues. return value ownership issues.
* GstURIHandler
gst_uri_handler_get_uri() and the get_uri vfunc now return a copy of
the URI string
gst_uri_handler_set_uri() and the set_uri vfunc now take an additional
GError argument so the handler can notify the caller why it didn't
accept a particular URI.
gst_uri_handler_set_uri() now checks if the protocol of the URI passed
is one of the protocols advertised by the uri handler, so set_uri vfunc
implementations no longer need to check that as well.
* GstTagList * GstTagList
is now an opaque object instead of being typedefed to a GstStructure. Cast is now an opaque object instead of being typedefed to a GstStructure. Cast
to GstStructure or use gst_structure_* API on it at your own peril (it may to GstStructure or use gst_structure_* API on it at your own peril (it may

View file

@ -748,6 +748,7 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data,
g_type_class_ref (gst_task_state_get_type ()); g_type_class_ref (gst_task_state_get_type ());
g_type_class_ref (gst_alloc_trace_flags_get_type ()); g_type_class_ref (gst_alloc_trace_flags_get_type ());
g_type_class_ref (gst_type_find_probability_get_type ()); g_type_class_ref (gst_type_find_probability_get_type ());
g_type_class_ref (gst_uri_error_get_type ());
g_type_class_ref (gst_uri_type_get_type ()); g_type_class_ref (gst_uri_type_get_type ());
g_type_class_ref (gst_parse_error_get_type ()); g_type_class_ref (gst_parse_error_get_type ());
g_type_class_ref (gst_parse_flags_get_type ()); g_type_class_ref (gst_parse_flags_get_type ());
@ -1120,6 +1121,7 @@ gst_deinit (void)
g_type_class_unref (g_type_class_peek (gst_type_find_probability_get_type g_type_class_unref (g_type_class_peek (gst_type_find_probability_get_type
())); ()));
g_type_class_unref (g_type_class_peek (gst_uri_type_get_type ())); g_type_class_unref (g_type_class_peek (gst_uri_type_get_type ()));
g_type_class_unref (g_type_class_peek (gst_uri_error_get_type ()));
g_type_class_unref (g_type_class_peek (gst_parse_error_get_type ())); g_type_class_unref (g_type_class_peek (gst_parse_error_get_type ()));
g_type_class_unref (g_type_class_peek (gst_param_spec_fraction_get_type ())); g_type_class_unref (g_type_class_peek (gst_param_spec_fraction_get_type ()));
g_type_class_unref (g_type_class_peek (gst_progress_type_get_type ())); g_type_class_unref (g_type_class_peek (gst_progress_type_get_type ()));

View file

@ -47,6 +47,8 @@
#include "gstmarshal.h" #include "gstmarshal.h"
#include "gstregistry.h" #include "gstregistry.h"
#include "gst-i18n-lib.h"
#include <string.h> #include <string.h>
GST_DEBUG_CATEGORY_STATIC (gst_uri_handler_debug); GST_DEBUG_CATEGORY_STATIC (gst_uri_handler_debug);
@ -82,6 +84,12 @@ gst_uri_handler_get_type (void)
return urihandler_type; return urihandler_type;
} }
GQuark
gst_uri_error_quark (void)
{
return g_quark_from_static_string ("gst-uri-error-quark");
}
static const guchar acceptable[96] = { /* X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 XA XB XC XD XE XF */ static const guchar acceptable[96] = { /* X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 XA XB XC XD XE XF */
0x00, 0x3F, 0x20, 0x20, 0x20, 0x00, 0x2C, 0x3F, 0x3F, 0x3F, 0x3F, 0x22, 0x20, 0x3F, 0x3F, 0x1C, /* 2X !"#$%&'()*+,-./ */ 0x00, 0x3F, 0x20, 0x20, 0x20, 0x00, 0x2C, 0x3F, 0x3F, 0x3F, 0x3F, 0x22, 0x20, 0x3F, 0x3F, 0x1C, /* 2X !"#$%&'()*+,-./ */
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x38, 0x20, 0x20, 0x2C, 0x20, 0x2C, /* 3X 0123456789:;<=>? */ 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x38, 0x20, 0x20, 0x2C, 0x20, 0x2C, /* 3X 0123456789:;<=>? */
@ -589,7 +597,7 @@ gst_element_make_from_uri (const GstURIType type, const gchar * uri,
elementname)) != NULL) { elementname)) != NULL) {
GstURIHandler *handler = GST_URI_HANDLER (ret); GstURIHandler *handler = GST_URI_HANDLER (ret);
if (gst_uri_handler_set_uri (handler, uri)) if (gst_uri_handler_set_uri (handler, uri, NULL))
break; break;
gst_object_unref (ret); gst_object_unref (ret);
ret = NULL; ret = NULL;
@ -691,13 +699,16 @@ gst_uri_handler_get_uri (GstURIHandler * handler)
* gst_uri_handler_set_uri: * gst_uri_handler_set_uri:
* @handler: A #GstURIHandler * @handler: A #GstURIHandler
* @uri: URI to set * @uri: URI to set
* @error: (allow-none): address where to store a #GError in case of
* an error, or NULL
* *
* Tries to set the URI of the given handler. * Tries to set the URI of the given handler.
* *
* Returns: TRUE if the URI was set successfully, else FALSE. * Returns: TRUE if the URI was set successfully, else FALSE.
*/ */
gboolean gboolean
gst_uri_handler_set_uri (GstURIHandler * handler, const gchar * uri) gst_uri_handler_set_uri (GstURIHandler * handler, const gchar * uri,
GError ** error)
{ {
GstURIHandlerInterface *iface; GstURIHandlerInterface *iface;
gboolean ret; gboolean ret;
@ -705,6 +716,7 @@ gst_uri_handler_set_uri (GstURIHandler * handler, const gchar * uri)
g_return_val_if_fail (GST_IS_URI_HANDLER (handler), FALSE); g_return_val_if_fail (GST_IS_URI_HANDLER (handler), FALSE);
g_return_val_if_fail (gst_uri_is_valid (uri), FALSE); g_return_val_if_fail (gst_uri_is_valid (uri), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
iface = GST_URI_HANDLER_GET_INTERFACE (handler); iface = GST_URI_HANDLER_GET_INTERFACE (handler);
g_return_val_if_fail (iface != NULL, FALSE); g_return_val_if_fail (iface != NULL, FALSE);
@ -712,12 +724,34 @@ gst_uri_handler_set_uri (GstURIHandler * handler, const gchar * uri)
protocol = gst_uri_get_protocol (uri); protocol = gst_uri_get_protocol (uri);
if (iface->get_protocols) {
gchar **p, **protocols;
gboolean found_protocol = FALSE;
protocols = iface->get_protocols (G_OBJECT_TYPE (handler));
if (protocols != NULL) {
for (p = protocols; *p != NULL; ++p) {
if (g_ascii_strcasecmp (protocol, *p) == 0) {
found_protocol = TRUE;
break;
}
}
if (!found_protocol) {
g_set_error (error, GST_URI_ERROR, GST_URI_ERROR_BAD_PROTOCOL,
_("URI scheme '%s' not supported"), protocol);
g_free (protocol);
return FALSE;
}
}
}
colon = strstr (uri, ":"); colon = strstr (uri, ":");
location = g_strdup (colon); location = g_strdup (colon);
new_uri = g_strdup_printf ("%s%s", protocol, location); new_uri = g_strdup_printf ("%s%s", protocol, location);
ret = iface->set_uri (handler, uri); ret = iface->set_uri (handler, uri, error);
g_free (new_uri); g_free (new_uri);
g_free (location); g_free (location);

View file

@ -30,6 +30,34 @@
G_BEGIN_DECLS G_BEGIN_DECLS
GQuark gst_uri_error_quark (void);
/**
* GST_URI_ERROR:
*
* Get access to the error quark of the uri subsystem.
*/
#define GST_URI_ERROR gst_uri_error_quark ()
/**
* GstURIError:
* @GST_URI_ERROR_BAD_PROTOCOL: The protocol is not supported
* @GST_URI_ERROR_BAD_URI: There was a problem with the URI
* @GST_URI_ERROR_BAD_STATE: Could not set or change the URI because the
* URI handler was in a state where that is not possible or not permitted
* @GST_URI_ERROR_BAD_REFERENCE: There was a problem with the entity that
* the URI references
*
* Different URI-related errors that can occur.
*/
typedef enum
{
GST_URI_ERROR_BAD_PROTOCOL,
GST_URI_ERROR_BAD_URI,
GST_URI_ERROR_BAD_STATE,
GST_URI_ERROR_BAD_REFERENCE
} GstURIError;
/** /**
* GstURIType: * GstURIType:
* @GST_URI_UNKNOWN : The URI direction is unknown * @GST_URI_UNKNOWN : The URI direction is unknown
@ -89,7 +117,8 @@ struct _GstURIHandlerInterface {
/* using the interface */ /* using the interface */
gchar * (* get_uri) (GstURIHandler * handler); gchar * (* get_uri) (GstURIHandler * handler);
gboolean (* set_uri) (GstURIHandler * handler, gboolean (* set_uri) (GstURIHandler * handler,
const gchar * uri); const gchar * uri,
GError ** error);
}; };
/* general URI functions */ /* general URI functions */
@ -119,7 +148,8 @@ guint gst_uri_handler_get_uri_type (GstURIHandler * handler);
gchar ** gst_uri_handler_get_protocols (GstURIHandler * handler); gchar ** gst_uri_handler_get_protocols (GstURIHandler * handler);
gchar * gst_uri_handler_get_uri (GstURIHandler * handler); gchar * gst_uri_handler_get_uri (GstURIHandler * handler);
gboolean gst_uri_handler_set_uri (GstURIHandler * handler, gboolean gst_uri_handler_set_uri (GstURIHandler * handler,
const gchar * uri); const gchar * uri,
GError ** error);
G_END_DECLS G_END_DECLS

View file

@ -1154,13 +1154,14 @@ EXPORTS
gst_type_find_suggest_simple gst_type_find_suggest_simple
gst_update_registry gst_update_registry
gst_uri_construct gst_uri_construct
gst_uri_error_get_type
gst_uri_error_quark
gst_uri_get_location gst_uri_get_location
gst_uri_get_protocol gst_uri_get_protocol
gst_uri_handler_get_protocols gst_uri_handler_get_protocols
gst_uri_handler_get_type gst_uri_handler_get_type
gst_uri_handler_get_uri gst_uri_handler_get_uri
gst_uri_handler_get_uri_type gst_uri_handler_get_uri_type
gst_uri_handler_new_uri
gst_uri_handler_set_uri gst_uri_handler_set_uri
gst_uri_has_protocol gst_uri_has_protocol
gst_uri_is_valid gst_uri_is_valid