gst/gstmessage.c (gst_message_parse_state_changed): Use gst_structure_get_enum instead of gst_structure_get_int

Original commit message from CVS:
* gst/gstmessage.c (gst_message_parse_state_changed): Use
gst_structure_get_enum instead of gst_structure_get_int

* gst/gststructure.c (gst_structure_get_enum): Impl.

* gst/gststructure.h (gst_structure_get_enum): Add

* docs/gst/gstreamer-sections.txt: Ditto
This commit is contained in:
Johan Dahlin 2005-09-29 02:32:37 +00:00
parent bdb214775d
commit d52d4b4a4d
5 changed files with 57 additions and 3 deletions

View file

@ -1,5 +1,14 @@
2005-09-28 Johan Dahlin <johan@gnome.org>
* gst/gstmessage.c (gst_message_parse_state_changed): Use
gst_structure_get_enum instead of gst_structure_get_int
* gst/gststructure.c (gst_structure_get_enum): Impl.
* gst/gststructure.h (gst_structure_get_enum): Add
* docs/gst/gstreamer-sections.txt: Ditto
* gst/gstmessage.c (gst_message_new_state_changed): Use
GST_TYPE_STATE instead of G_TYPE_INT, mainly for language bindings
which does introspection.

View file

@ -1633,6 +1633,7 @@ gst_structure_get_double
gst_structure_get_string
gst_structure_get_date
gst_structure_get_clock_time
gst_structure_get_enum
gst_structure_map_in_place
gst_structure_nth_field_name
gst_structure_set_parent_refcount

View file

@ -370,7 +370,7 @@ gst_message_new_state_changed (GstObject * src, GstState old, GstState new)
message = gst_message_new (GST_MESSAGE_STATE_CHANGED, src);
s = gst_structure_new ("GstMessageState", "old-state", GST_TYPE_STATE,
old, "new-state", GST_TYPE_STATE, new, NULL);
(gint) old, "new-state", GST_TYPE_STATE, (gint) new, NULL);
gst_structure_set_parent_refcount (s, &message->mini_object.refcount);
message->structure = s;
@ -520,9 +520,11 @@ gst_message_parse_state_changed (GstMessage * message, GstState * old,
g_return_if_fail (GST_IS_MESSAGE (message));
g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
if (!gst_structure_get_int (message->structure, "old-state", (gint *) old))
if (!gst_structure_get_enum (message->structure, "old-state",
GST_TYPE_STATE, (gint *) old))
g_assert_not_reached ();
if (!gst_structure_get_int (message->structure, "new-state", (gint *) new))
if (!gst_structure_get_enum (message->structure, "new-state",
GST_TYPE_STATE, (gint *) new))
g_assert_not_reached ();
}

View file

@ -1088,6 +1088,44 @@ gst_structure_get_string (const GstStructure * structure,
return g_value_get_string (&field->value);
}
/**
* gst_structure_get_enum:
* @structure: a #GstStructure
* @fieldname: the name of a field
* @enumtype: the enum type of a field
* @value: a pointer to an int to set
*
* Sets the int pointed to by @value corresponding to the value of the
* given field. Caller is responsible for making sure the field exists,
* has the correct type and that the enumtype is correct.
*
* Returns: TRUE if the value could be set correctly
*/
gboolean
gst_structure_get_enum (const GstStructure * structure,
const gchar * fieldname, GType enumtype, gint * value)
{
GstStructureField *field;
g_return_val_if_fail (structure != NULL, FALSE);
g_return_val_if_fail (fieldname != NULL, FALSE);
g_return_val_if_fail (enumtype != G_TYPE_INVALID, FALSE);
g_return_val_if_fail (value != NULL, FALSE);
field = gst_structure_get_field (structure, fieldname);
if (field == NULL)
return FALSE;
if (!G_VALUE_HOLDS_ENUM (&field->value))
return FALSE;
if (!G_TYPE_CHECK_VALUE_TYPE (&field->value, enumtype))
return FALSE;
*value = g_value_get_enum (&field->value);
return TRUE;
}
typedef struct _GstStructureAbbreviation
{
char *type_name;

View file

@ -139,6 +139,10 @@ gboolean gst_structure_get_clock_time (const GstStructure
GstClockTime *value);
G_CONST_RETURN gchar * gst_structure_get_string (const GstStructure *structure,
const gchar *fieldname);
gboolean gst_structure_get_enum (const GstStructure *structure,
const gchar *fieldname,
GType enumtype,
gint *value);
gchar * gst_structure_to_string (const GstStructure *structure);
GstStructure * gst_structure_from_string (const gchar *string,