gst/gstmessage.c (gst_message_parse_state_changed): Use gst_structure_get_enum instea...
authorJohan Dahlin <johan@gnome.org>
Thu, 29 Sep 2005 02:32:37 +0000 (02:32 +0000)
committerJohan Dahlin <johan@gnome.org>
Thu, 29 Sep 2005 02:32:37 +0000 (02:32 +0000)
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

ChangeLog
docs/gst/gstreamer-sections.txt
gst/gstmessage.c
gst/gststructure.c
gst/gststructure.h

index 68cf7b317b9dd5a6376dc2ac4ce569d342a32112..9d4dd33b4ad5477d3727e0e3d70064e6bec7a346 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
index 280ddac83c548f8061fa85f5c695cbc0ffab875f..e03b3a86f0104ed3b0d6b2bfbf97d1daf3fc0d91 100644 (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
index 762853fcce4ed0b56953d4d38fd4d8e9fb4f683a..492693215c5e6c2d4104c6ed4ff3199afe19fad5 100644 (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 ();
 }
 
index 6801ca073cd4d19f0234610fea451502dfed0afc..60f1538e6b1132cfb20e693b463526b63f94454f 100644 (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;
index 7659db86b1df8216b8cfba0a3a430a94a25abbec..b7c59fe55b52562caf0824064ac6478284d21c4d 100644 (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,