diff --git a/ChangeLog b/ChangeLog index 68cf7b317b..9d4dd33b4a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2005-09-28 Johan Dahlin + * 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. diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt index 280ddac83c..e03b3a86f0 100644 --- a/docs/gst/gstreamer-sections.txt +++ b/docs/gst/gstreamer-sections.txt @@ -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 diff --git a/gst/gstmessage.c b/gst/gstmessage.c index 762853fcce..492693215c 100644 --- a/gst/gstmessage.c +++ b/gst/gstmessage.c @@ -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 (); } diff --git a/gst/gststructure.c b/gst/gststructure.c index 6801ca073c..60f1538e6b 100644 --- a/gst/gststructure.c +++ b/gst/gststructure.c @@ -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; diff --git a/gst/gststructure.h b/gst/gststructure.h index 7659db86b1..b7c59fe55b 100644 --- a/gst/gststructure.h +++ b/gst/gststructure.h @@ -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,