Skip to content

Commit

Permalink
gst/gstmessage.c (gst_message_parse_state_changed): Use gst_structure…
Browse files Browse the repository at this point in the history
…_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
  • Loading branch information
boondocksaints-debug committed Sep 29, 2005
1 parent bdb2147 commit d52d4b4
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions docs/gst/gstreamer-sections.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions gst/gstmessage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 ();
}

Expand Down
38 changes: 38 additions & 0 deletions gst/gststructure.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions gst/gststructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d52d4b4

Please sign in to comment.