Some prettification fixes to this interface... Make it look good, make it simple and make it more GObject'ific. This ...

Original commit message from CVS:
Some prettification fixes to this interface... Make it look good, make it simple and make it more GObject'ific. This means that it now works largely almost the same as GObject (concerning arguments that you give to the functions, and layout of the virtual functions). I've also got an OSS implementation for this, but it needs one small change before I commit that. Expect that this weekend or so.
This commit is contained in:
Ronald S. Bultje 2003-11-05 22:59:46 +00:00
parent 7475046f04
commit 97beb82173
4 changed files with 398 additions and 186 deletions

View file

@ -23,15 +23,17 @@
#include "config.h" #include "config.h"
#endif #endif
#include <gst/propertyprobe/propertyprobe.h> #include <string.h>
static void gst_property_probe_iface_init (GstPropertyProbeInterface *iface); #include "propertyprobe.h"
enum { enum {
NEED_PROBE, SIGNAL_PROBE_NEEDED,
LAST_SIGNAL LAST_SIGNAL
}; };
static void gst_property_probe_iface_init (GstPropertyProbeInterface *iface);
static guint gst_property_probe_signals[LAST_SIGNAL] = { 0 }; static guint gst_property_probe_signals[LAST_SIGNAL] = { 0 };
GType GType
@ -52,11 +54,10 @@ gst_property_probe_get_type (void)
NULL, NULL,
}; };
gst_property_probe_type = g_type_register_static (G_TYPE_INTERFACE, gst_property_probe_type =
"GstPropertyProbe", g_type_register_static (G_TYPE_INTERFACE,
&gst_property_probe_info, 0); "GstPropertyProbe",
&gst_property_probe_info, 0);
g_type_interface_add_prerequisite (gst_property_probe_type, G_TYPE_OBJECT);
} }
return gst_property_probe_type; return gst_property_probe_type;
@ -68,109 +69,190 @@ gst_property_probe_iface_init (GstPropertyProbeInterface *iface)
static gboolean initialized = FALSE; static gboolean initialized = FALSE;
if (!initialized) { if (!initialized) {
gst_property_probe_signals[NEED_PROBE] = gst_property_probe_signals[SIGNAL_PROBE_NEEDED] =
g_signal_new ("need_probe", g_signal_new ("probe_needed", G_TYPE_FROM_CLASS (iface), G_SIGNAL_RUN_LAST,
GST_TYPE_PROPERTY_PROBE, G_STRUCT_OFFSET (GstPropertyProbeInterface, probe_needed),
G_SIGNAL_RUN_LAST, NULL, NULL, g_cclosure_marshal_VOID__POINTER,
G_STRUCT_OFFSET (GstPropertyProbeInterface, need_probe), G_TYPE_NONE, 1, G_TYPE_POINTER);
NULL,
NULL,
gst_marshal_VOID__STRING,
G_TYPE_NONE, 1,
G_TYPE_STRING);
initialized = TRUE; initialized = TRUE;
} }
/* default virtual functions */ /* default virtual functions */
iface->get_list = NULL; iface->get_properties = NULL;
iface->probe_property = NULL; iface->get_values = NULL;
iface->get_property_info = NULL;
iface->is_probed = NULL;
} }
char ** const GList *
gst_property_probe_get_list (GstElement *element) gst_property_probe_get_properties (GstPropertyProbe *probe)
{ {
GstPropertyProbeInterface *iface; GstPropertyProbeInterface *iface;
g_return_val_if_fail (GST_IS_PROPERTY_PROBE (element), NULL);
iface = GST_PROPERTY_PROBE_GET_IFACE (element); g_return_val_if_fail (probe != NULL, NULL);
if (iface->get_list) {
return iface->get_list (element); iface = GST_PROPERTY_PROBE_GET_IFACE (probe);
if (iface->get_properties)
return iface->get_properties (probe);
return NULL;
}
const GParamSpec *
gst_property_probe_get_property (GstPropertyProbe *probe,
const gchar *name)
{
const GList *pspecs = gst_property_probe_get_properties (probe);
g_return_val_if_fail (probe != NULL, NULL);
g_return_val_if_fail (name != NULL, NULL);
while (pspecs) {
const GParamSpec *pspec = pspecs->data;
if (!strcmp (pspec->name, name))
return pspec;
pspecs = pspecs->next;
} }
return NULL; return NULL;
} }
void void
gst_property_probe_probe_property (GstElement *element, gst_property_probe_probe_property (GstPropertyProbe *probe,
const char *property) const GParamSpec *pspec)
{ {
GstPropertyProbeInterface *iface; GstPropertyProbeInterface *iface;
GParamSpec *ps;
g_return_if_fail (GST_IS_PROPERTY_PROBE (element));
g_return_if_fail (GST_STATE (element) == GST_STATE_NULL);
ps = g_object_class_find_property (G_OBJECT_CLASS (element), property); g_return_if_fail (probe != NULL);
if (ps == NULL) return; g_return_if_fail (pspec != NULL);
iface = GST_PROPERTY_PROBE_GET_IFACE (element); iface = GST_PROPERTY_PROBE_GET_IFACE (probe);
if (iface->probe_property) {
iface->probe_property (element, ps); if (iface->probe_property)
} iface->probe_property (probe, pspec->param_id, pspec);
} }
gchar ** void
gst_property_probe_get_property_info (GstElement *element, gst_property_probe_probe_property_name (GstPropertyProbe *probe,
const gchar *property) const gchar *name)
{ {
GstPropertyProbeInterface *iface; const GParamSpec *pspec;
GParamSpec *ps;
g_return_val_if_fail (GST_IS_PROPERTY_PROBE (element), NULL);
ps = g_object_class_find_property (G_OBJECT_CLASS (element), property); g_return_if_fail (probe != NULL);
if (ps == NULL) return NULL; g_return_if_fail (name != NULL);
iface = GST_PROPERTY_PROBE_GET_IFACE (element); pspec = g_object_class_find_property (G_OBJECT_CLASS (probe), name);
if (iface->get_property_info) { if (!pspec) {
return iface->get_property_info (element, ps); g_warning ("No such property %s", name);
return;
} }
return NULL;
gst_property_probe_probe_property (probe, pspec);
} }
gboolean gboolean
gst_property_probe_is_probed (GstElement *element, gst_property_probe_needs_probe (GstPropertyProbe *probe,
const char *property) const GParamSpec *pspec)
{ {
GstPropertyProbeInterface *iface; GstPropertyProbeInterface *iface;
GParamSpec *ps;
g_return_val_if_fail (GST_IS_PROPERTY_PROBE (element), FALSE);
ps = g_object_class_find_property (G_OBJECT_CLASS (element), property); g_return_val_if_fail (probe != NULL, FALSE);
if (ps == NULL) return FALSE; g_return_val_if_fail (pspec != NULL, FALSE);
iface = GST_PROPERTY_PROBE_GET_IFACE (probe);
if (iface->needs_probe)
return iface->needs_probe (probe, pspec->param_id, pspec);
iface = GST_PROPERTY_PROBE_GET_IFACE (element);
if (iface->is_probed) {
return iface->is_probed (element, ps);
}
return FALSE; return FALSE;
} }
gchar ** gboolean
gst_property_probe_get_possibilities (GstElement *element, gst_property_probe_needs_probe_name (GstPropertyProbe *probe,
const char *property) const gchar *name)
{ {
g_return_val_if_fail (GST_IS_PROPERTY_PROBE (element), NULL); const GParamSpec *pspec;
if (!gst_property_probe_is_probed (element, property)){ g_return_val_if_fail (probe != NULL, FALSE);
gst_property_probe_probe_property (element, property); g_return_val_if_fail (name != NULL, FALSE);
pspec = g_object_class_find_property (G_OBJECT_CLASS (probe), name);
if (!pspec) {
g_warning ("No such property %s", name);
return FALSE;
} }
return gst_property_probe_get_property_info (element, property); return gst_property_probe_needs_probe (probe, pspec);
}
GValueArray *
gst_property_probe_get_values (GstPropertyProbe *probe,
const GParamSpec *pspec)
{
GstPropertyProbeInterface *iface;
g_return_val_if_fail (probe != NULL, NULL);
g_return_val_if_fail (pspec != NULL, NULL);
iface = GST_PROPERTY_PROBE_GET_IFACE (probe);
if (iface->get_values)
return iface->get_values (probe, pspec->param_id, pspec);
return NULL;
} }
GValueArray *
gst_property_probe_get_values_name (GstPropertyProbe *probe,
const gchar *name)
{
const GParamSpec *pspec;
g_return_val_if_fail (probe != NULL, NULL);
g_return_val_if_fail (name != NULL, NULL);
pspec = g_object_class_find_property (G_OBJECT_CLASS (probe), name);
if (!pspec) {
g_warning ("No such property %s", name);
return NULL;
}
return gst_property_probe_get_values (probe, pspec);
}
GValueArray *
gst_property_probe_probe_and_get_values (GstPropertyProbe *probe,
const GParamSpec *pspec)
{
GstPropertyProbeInterface *iface;
g_return_val_if_fail (probe != NULL, NULL);
g_return_val_if_fail (pspec != NULL, NULL);
iface = GST_PROPERTY_PROBE_GET_IFACE (probe);
if (gst_property_probe_needs_probe (probe, pspec))
gst_property_probe_probe_property (probe, pspec);
return gst_property_probe_get_values (probe, pspec);
}
GValueArray *
gst_property_probe_probe_and_get_values_name (GstPropertyProbe *probe,
const gchar *name)
{
const GParamSpec *pspec;
g_return_val_if_fail (probe != NULL, NULL);
g_return_val_if_fail (name != NULL, NULL);
pspec = g_object_class_find_property (G_OBJECT_CLASS (probe), name);
if (!pspec) {
g_warning ("No such property %s", name);
return NULL;
}
return gst_property_probe_probe_and_get_values (probe, pspec);
}

View file

@ -41,32 +41,56 @@ typedef struct _GstPropertyProbeInterface {
GTypeInterface klass; GTypeInterface klass;
/* signals */ /* signals */
void (*need_probe) (GstPropertyProbe *property_probe, const gchar *property); void (*probe_needed) (GstPropertyProbe *probe,
const GParamSpec *pspec);
/* virtual functions */ /* virtual functions */
gchar ** (*get_list) (GstElement *property_probe); const GList * (*get_properties) (GstPropertyProbe *probe);
void (*probe_property) (GstElement *property_probe, const GParamSpec *property); gboolean (*needs_probe) (GstPropertyProbe *probe,
gchar ** (*get_property_info) (GstElement *property_probe, guint prop_id,
const GParamSpec *property); const GParamSpec *pspec);
gboolean (*is_probed) (GstElement *element, const GParamSpec *property); void (*probe_property) (GstPropertyProbe *probe,
guint prop_id,
const GParamSpec *pspec);
GValueArray * (*get_values) (GstPropertyProbe *probe,
guint prop_id,
const GParamSpec *pspec);
GST_CLASS_PADDING GST_CLASS_PADDING
} GstPropertyProbeInterface; } GstPropertyProbeInterface;
GType gst_property_probe_get_type (void); GType gst_property_probe_get_type (void);
/* virtual class function wrappers */ /* virtual class function wrappers */
gchar ** gst_property_probe_get_list (GstElement *element);
void gst_property_probe_probe_property (GstElement *element,
const gchar *property);
gchar ** gst_property_probe_get_property_info (GstElement *element,
const gchar *property);
gboolean gst_property_probe_is_probed (GstElement *element,
const gchar *property);
/* utility functions */ /* returns list of GParamSpecs */
gchar ** gst_property_probe_get_possibilities (GstElement *element, const GList * gst_property_probe_get_properties (GstPropertyProbe *probe);
const gchar *property); const GParamSpec *gst_property_probe_get_property (GstPropertyProbe *probe,
const gchar *name);
/* probe one property */
void gst_property_probe_probe_property (GstPropertyProbe *probe,
const GParamSpec *pspec);
void gst_property_probe_probe_property_name (GstPropertyProbe *probe,
const gchar *name);
/* do we need a probe? */
gboolean gst_property_probe_needs_probe (GstPropertyProbe *probe,
const GParamSpec *pspec);
gboolean gst_property_probe_needs_probe_name (GstPropertyProbe *probe,
const gchar *name);
/* returns list of GValues */
GValueArray * gst_property_probe_get_values (GstPropertyProbe *probe,
const GParamSpec *pspec);
GValueArray * gst_property_probe_get_values_name (GstPropertyProbe *probe,
const gchar *name);
/* sugar */
GValueArray * gst_property_probe_probe_and_get_values (GstPropertyProbe *probe,
const GParamSpec *pspec);
GValueArray * gst_property_probe_probe_and_get_values_name (GstPropertyProbe *probe,
const gchar *name);
G_END_DECLS G_END_DECLS

View file

@ -23,15 +23,17 @@
#include "config.h" #include "config.h"
#endif #endif
#include <gst/propertyprobe/propertyprobe.h> #include <string.h>
static void gst_property_probe_iface_init (GstPropertyProbeInterface *iface); #include "propertyprobe.h"
enum { enum {
NEED_PROBE, SIGNAL_PROBE_NEEDED,
LAST_SIGNAL LAST_SIGNAL
}; };
static void gst_property_probe_iface_init (GstPropertyProbeInterface *iface);
static guint gst_property_probe_signals[LAST_SIGNAL] = { 0 }; static guint gst_property_probe_signals[LAST_SIGNAL] = { 0 };
GType GType
@ -52,11 +54,10 @@ gst_property_probe_get_type (void)
NULL, NULL,
}; };
gst_property_probe_type = g_type_register_static (G_TYPE_INTERFACE, gst_property_probe_type =
"GstPropertyProbe", g_type_register_static (G_TYPE_INTERFACE,
&gst_property_probe_info, 0); "GstPropertyProbe",
&gst_property_probe_info, 0);
g_type_interface_add_prerequisite (gst_property_probe_type, G_TYPE_OBJECT);
} }
return gst_property_probe_type; return gst_property_probe_type;
@ -68,109 +69,190 @@ gst_property_probe_iface_init (GstPropertyProbeInterface *iface)
static gboolean initialized = FALSE; static gboolean initialized = FALSE;
if (!initialized) { if (!initialized) {
gst_property_probe_signals[NEED_PROBE] = gst_property_probe_signals[SIGNAL_PROBE_NEEDED] =
g_signal_new ("need_probe", g_signal_new ("probe_needed", G_TYPE_FROM_CLASS (iface), G_SIGNAL_RUN_LAST,
GST_TYPE_PROPERTY_PROBE, G_STRUCT_OFFSET (GstPropertyProbeInterface, probe_needed),
G_SIGNAL_RUN_LAST, NULL, NULL, g_cclosure_marshal_VOID__POINTER,
G_STRUCT_OFFSET (GstPropertyProbeInterface, need_probe), G_TYPE_NONE, 1, G_TYPE_POINTER);
NULL,
NULL,
gst_marshal_VOID__STRING,
G_TYPE_NONE, 1,
G_TYPE_STRING);
initialized = TRUE; initialized = TRUE;
} }
/* default virtual functions */ /* default virtual functions */
iface->get_list = NULL; iface->get_properties = NULL;
iface->probe_property = NULL; iface->get_values = NULL;
iface->get_property_info = NULL;
iface->is_probed = NULL;
} }
char ** const GList *
gst_property_probe_get_list (GstElement *element) gst_property_probe_get_properties (GstPropertyProbe *probe)
{ {
GstPropertyProbeInterface *iface; GstPropertyProbeInterface *iface;
g_return_val_if_fail (GST_IS_PROPERTY_PROBE (element), NULL);
iface = GST_PROPERTY_PROBE_GET_IFACE (element); g_return_val_if_fail (probe != NULL, NULL);
if (iface->get_list) {
return iface->get_list (element); iface = GST_PROPERTY_PROBE_GET_IFACE (probe);
if (iface->get_properties)
return iface->get_properties (probe);
return NULL;
}
const GParamSpec *
gst_property_probe_get_property (GstPropertyProbe *probe,
const gchar *name)
{
const GList *pspecs = gst_property_probe_get_properties (probe);
g_return_val_if_fail (probe != NULL, NULL);
g_return_val_if_fail (name != NULL, NULL);
while (pspecs) {
const GParamSpec *pspec = pspecs->data;
if (!strcmp (pspec->name, name))
return pspec;
pspecs = pspecs->next;
} }
return NULL; return NULL;
} }
void void
gst_property_probe_probe_property (GstElement *element, gst_property_probe_probe_property (GstPropertyProbe *probe,
const char *property) const GParamSpec *pspec)
{ {
GstPropertyProbeInterface *iface; GstPropertyProbeInterface *iface;
GParamSpec *ps;
g_return_if_fail (GST_IS_PROPERTY_PROBE (element));
g_return_if_fail (GST_STATE (element) == GST_STATE_NULL);
ps = g_object_class_find_property (G_OBJECT_CLASS (element), property); g_return_if_fail (probe != NULL);
if (ps == NULL) return; g_return_if_fail (pspec != NULL);
iface = GST_PROPERTY_PROBE_GET_IFACE (element); iface = GST_PROPERTY_PROBE_GET_IFACE (probe);
if (iface->probe_property) {
iface->probe_property (element, ps); if (iface->probe_property)
} iface->probe_property (probe, pspec->param_id, pspec);
} }
gchar ** void
gst_property_probe_get_property_info (GstElement *element, gst_property_probe_probe_property_name (GstPropertyProbe *probe,
const gchar *property) const gchar *name)
{ {
GstPropertyProbeInterface *iface; const GParamSpec *pspec;
GParamSpec *ps;
g_return_val_if_fail (GST_IS_PROPERTY_PROBE (element), NULL);
ps = g_object_class_find_property (G_OBJECT_CLASS (element), property); g_return_if_fail (probe != NULL);
if (ps == NULL) return NULL; g_return_if_fail (name != NULL);
iface = GST_PROPERTY_PROBE_GET_IFACE (element); pspec = g_object_class_find_property (G_OBJECT_CLASS (probe), name);
if (iface->get_property_info) { if (!pspec) {
return iface->get_property_info (element, ps); g_warning ("No such property %s", name);
return;
} }
return NULL;
gst_property_probe_probe_property (probe, pspec);
} }
gboolean gboolean
gst_property_probe_is_probed (GstElement *element, gst_property_probe_needs_probe (GstPropertyProbe *probe,
const char *property) const GParamSpec *pspec)
{ {
GstPropertyProbeInterface *iface; GstPropertyProbeInterface *iface;
GParamSpec *ps;
g_return_val_if_fail (GST_IS_PROPERTY_PROBE (element), FALSE);
ps = g_object_class_find_property (G_OBJECT_CLASS (element), property); g_return_val_if_fail (probe != NULL, FALSE);
if (ps == NULL) return FALSE; g_return_val_if_fail (pspec != NULL, FALSE);
iface = GST_PROPERTY_PROBE_GET_IFACE (probe);
if (iface->needs_probe)
return iface->needs_probe (probe, pspec->param_id, pspec);
iface = GST_PROPERTY_PROBE_GET_IFACE (element);
if (iface->is_probed) {
return iface->is_probed (element, ps);
}
return FALSE; return FALSE;
} }
gchar ** gboolean
gst_property_probe_get_possibilities (GstElement *element, gst_property_probe_needs_probe_name (GstPropertyProbe *probe,
const char *property) const gchar *name)
{ {
g_return_val_if_fail (GST_IS_PROPERTY_PROBE (element), NULL); const GParamSpec *pspec;
if (!gst_property_probe_is_probed (element, property)){ g_return_val_if_fail (probe != NULL, FALSE);
gst_property_probe_probe_property (element, property); g_return_val_if_fail (name != NULL, FALSE);
pspec = g_object_class_find_property (G_OBJECT_CLASS (probe), name);
if (!pspec) {
g_warning ("No such property %s", name);
return FALSE;
} }
return gst_property_probe_get_property_info (element, property); return gst_property_probe_needs_probe (probe, pspec);
}
GValueArray *
gst_property_probe_get_values (GstPropertyProbe *probe,
const GParamSpec *pspec)
{
GstPropertyProbeInterface *iface;
g_return_val_if_fail (probe != NULL, NULL);
g_return_val_if_fail (pspec != NULL, NULL);
iface = GST_PROPERTY_PROBE_GET_IFACE (probe);
if (iface->get_values)
return iface->get_values (probe, pspec->param_id, pspec);
return NULL;
} }
GValueArray *
gst_property_probe_get_values_name (GstPropertyProbe *probe,
const gchar *name)
{
const GParamSpec *pspec;
g_return_val_if_fail (probe != NULL, NULL);
g_return_val_if_fail (name != NULL, NULL);
pspec = g_object_class_find_property (G_OBJECT_CLASS (probe), name);
if (!pspec) {
g_warning ("No such property %s", name);
return NULL;
}
return gst_property_probe_get_values (probe, pspec);
}
GValueArray *
gst_property_probe_probe_and_get_values (GstPropertyProbe *probe,
const GParamSpec *pspec)
{
GstPropertyProbeInterface *iface;
g_return_val_if_fail (probe != NULL, NULL);
g_return_val_if_fail (pspec != NULL, NULL);
iface = GST_PROPERTY_PROBE_GET_IFACE (probe);
if (gst_property_probe_needs_probe (probe, pspec))
gst_property_probe_probe_property (probe, pspec);
return gst_property_probe_get_values (probe, pspec);
}
GValueArray *
gst_property_probe_probe_and_get_values_name (GstPropertyProbe *probe,
const gchar *name)
{
const GParamSpec *pspec;
g_return_val_if_fail (probe != NULL, NULL);
g_return_val_if_fail (name != NULL, NULL);
pspec = g_object_class_find_property (G_OBJECT_CLASS (probe), name);
if (!pspec) {
g_warning ("No such property %s", name);
return NULL;
}
return gst_property_probe_probe_and_get_values (probe, pspec);
}

View file

@ -41,32 +41,56 @@ typedef struct _GstPropertyProbeInterface {
GTypeInterface klass; GTypeInterface klass;
/* signals */ /* signals */
void (*need_probe) (GstPropertyProbe *property_probe, const gchar *property); void (*probe_needed) (GstPropertyProbe *probe,
const GParamSpec *pspec);
/* virtual functions */ /* virtual functions */
gchar ** (*get_list) (GstElement *property_probe); const GList * (*get_properties) (GstPropertyProbe *probe);
void (*probe_property) (GstElement *property_probe, const GParamSpec *property); gboolean (*needs_probe) (GstPropertyProbe *probe,
gchar ** (*get_property_info) (GstElement *property_probe, guint prop_id,
const GParamSpec *property); const GParamSpec *pspec);
gboolean (*is_probed) (GstElement *element, const GParamSpec *property); void (*probe_property) (GstPropertyProbe *probe,
guint prop_id,
const GParamSpec *pspec);
GValueArray * (*get_values) (GstPropertyProbe *probe,
guint prop_id,
const GParamSpec *pspec);
GST_CLASS_PADDING GST_CLASS_PADDING
} GstPropertyProbeInterface; } GstPropertyProbeInterface;
GType gst_property_probe_get_type (void); GType gst_property_probe_get_type (void);
/* virtual class function wrappers */ /* virtual class function wrappers */
gchar ** gst_property_probe_get_list (GstElement *element);
void gst_property_probe_probe_property (GstElement *element,
const gchar *property);
gchar ** gst_property_probe_get_property_info (GstElement *element,
const gchar *property);
gboolean gst_property_probe_is_probed (GstElement *element,
const gchar *property);
/* utility functions */ /* returns list of GParamSpecs */
gchar ** gst_property_probe_get_possibilities (GstElement *element, const GList * gst_property_probe_get_properties (GstPropertyProbe *probe);
const gchar *property); const GParamSpec *gst_property_probe_get_property (GstPropertyProbe *probe,
const gchar *name);
/* probe one property */
void gst_property_probe_probe_property (GstPropertyProbe *probe,
const GParamSpec *pspec);
void gst_property_probe_probe_property_name (GstPropertyProbe *probe,
const gchar *name);
/* do we need a probe? */
gboolean gst_property_probe_needs_probe (GstPropertyProbe *probe,
const GParamSpec *pspec);
gboolean gst_property_probe_needs_probe_name (GstPropertyProbe *probe,
const gchar *name);
/* returns list of GValues */
GValueArray * gst_property_probe_get_values (GstPropertyProbe *probe,
const GParamSpec *pspec);
GValueArray * gst_property_probe_get_values_name (GstPropertyProbe *probe,
const gchar *name);
/* sugar */
GValueArray * gst_property_probe_probe_and_get_values (GstPropertyProbe *probe,
const GParamSpec *pspec);
GValueArray * gst_property_probe_probe_and_get_values_name (GstPropertyProbe *probe,
const gchar *name);
G_END_DECLS G_END_DECLS