validate: Move enums and flags deserialization from scenario to utilities
authorThibault Saunier <thibault.saunier@collabora.com>
Tue, 18 Feb 2014 17:13:39 +0000 (18:13 +0100)
committerThibault Saunier <thibault.saunier@collabora.com>
Tue, 18 Feb 2014 20:07:31 +0000 (21:07 +0100)
This way it can be reused.

validate/gst/validate/gst-validate-scenario.c
validate/gst/validate/gst-validate-utils.c
validate/gst/validate/gst-validate-utils.h

index e52b6f36f6e3467c64be21c68a7873f32c1e20b4..c48b7b2c158570edfe14685cf5dd58057ba95f18 100644 (file)
@@ -91,39 +91,6 @@ typedef struct KeyFileGroupName
   gchar *group_name;
 } KeyFileGroupName;
 
-static guint
-get_flags_from_string (GType type, const gchar * str_flags)
-{
-  guint i;
-  gint flags = 0;
-  GFlagsClass *class = g_type_class_ref (type);
-
-  for (i = 0; i < class->n_values; i++) {
-    if (g_strrstr (str_flags, class->values[i].value_nick)) {
-      flags |= class->values[i].value;
-    }
-  }
-  g_type_class_unref (class);
-
-  return flags;
-}
-
-static void
-get_enum_from_string (GType type, const gchar * str_enum, guint * enum_value)
-{
-  guint i;
-  GEnumClass *class = g_type_class_ref (type);
-
-  for (i = 0; i < class->n_values; i++) {
-    if (g_strrstr (str_enum, class->values[i].value_nick)) {
-      *enum_value = class->values[i].value;
-      break;
-    }
-  }
-
-  g_type_class_unref (class);
-}
-
 static void
 _free_scenario_action (GstValidateAction * act)
 {
@@ -179,7 +146,8 @@ gst_validate_action_get_clocktime (GstValidateScenario * scenario,
       GST_DEBUG_OBJECT (scenario, "Could not find %s", name);
       return FALSE;
     }
-    val = parse_expression (strval, _set_variable_func, scenario, &error);
+    val = gst_validate_utils_parse_expression (strval,
+        _set_variable_func, scenario, &error);
 
     if (error) {
       GST_WARNING ("Error while parsing %s: %s", strval, error);
@@ -219,18 +187,18 @@ _execute_seek (GstValidateScenario * scenario, GstValidateAction * action)
 
   gst_structure_get_double (action->structure, "rate", &rate);
   if ((str_format = gst_structure_get_string (action->structure, "format")))
-    get_enum_from_string (GST_TYPE_FORMAT, str_format, &format);
+    gst_validate_utils_enum_from_str (GST_TYPE_FORMAT, str_format, &format);
 
   if ((str_start_type =
           gst_structure_get_string (action->structure, "start_type")))
-    get_enum_from_string (GST_TYPE_SEEK_TYPE, str_start_type, &start_type);
+    gst_validate_utils_enum_from_str (GST_TYPE_SEEK_TYPE, str_start_type, &start_type);
 
   if ((str_stop_type =
           gst_structure_get_string (action->structure, "stop_type")))
-    get_enum_from_string (GST_TYPE_SEEK_TYPE, str_stop_type, &stop_type);
+    gst_validate_utils_enum_from_str (GST_TYPE_SEEK_TYPE, str_stop_type, &stop_type);
 
   if ((str_flags = gst_structure_get_string (action->structure, "flags")))
-    flags = get_flags_from_string (GST_TYPE_SEEK_FLAGS, str_flags);
+    flags = gst_validate_utils_flags_from_str (GST_TYPE_SEEK_FLAGS, str_flags);
 
   gst_validate_action_get_clocktime (scenario, action, "stop", &stop);
 
@@ -616,8 +584,9 @@ get_position (GstValidateScenario * scenario)
           "repeat");
 
       if (repeat_expr) {
-        act->repeat = parse_expression (repeat_expr, _set_variable_func,
-            scenario, &error);
+        act->repeat =
+            gst_validate_utils_parse_expression (repeat_expr,
+            _set_variable_func, scenario, &error);
       }
     }
 
index d25cd6b07c9c5f8dc9ea0c24f5fcdd96309d5407..f2db381a9277fd5a239a8dff7df5423e00550938 100644 (file)
@@ -27,6 +27,7 @@
 #include<stdlib.h>
 
 #include "gst-validate-utils.h"
+#include <gst/gst.h>
 
 #define PARSER_BOOLEAN_EQUALITY_THRESHOLD (1e-10)
 #define PARSER_MAX_TOKEN_SIZE 256
@@ -444,7 +445,7 @@ _read_power (MathParser * parser)
 }
 
 gdouble
-parse_expression (const gchar * expr, ParseVariableFunc variable_func,
+gst_validate_utils_parse_expression (const gchar * expr, ParseVariableFunc variable_func,
     gpointer user_data, gchar ** error)
 {
   gdouble val;
@@ -465,3 +466,36 @@ parse_expression (const gchar * expr, ParseVariableFunc variable_func,
   }
   return val;
 }
+
+guint
+gst_validate_utils_flags_from_str (GType type, const gchar * str_flags)
+{
+  guint i;
+  gint flags = 0;
+  GFlagsClass *class = g_type_class_ref (type);
+
+  for (i = 0; i < class->n_values; i++) {
+    if (g_strrstr (str_flags, class->values[i].value_nick)) {
+      flags |= class->values[i].value;
+    }
+  }
+  g_type_class_unref (class);
+
+  return flags;
+}
+
+void
+gst_validate_utils_enum_from_str (GType type, const gchar * str_enum, guint * enum_value)
+{
+  guint i;
+  GEnumClass *class = g_type_class_ref (type);
+
+  for (i = 0; i < class->n_values; i++) {
+    if (g_strrstr (str_enum, class->values[i].value_nick)) {
+      *enum_value = class->values[i].value;
+      break;
+    }
+  }
+
+  g_type_class_unref (class);
+}
index 510a2111088db128b85f57afd15d34cac3eaa664..9d8e7172226a005c8681b6380de315fc6599996a 100644 (file)
 #include<setjmp.h>
 #include<stdlib.h>
 #include<glib.h>
+#include <gst/gst.h>
 
 typedef int (*ParseVariableFunc) (const gchar *name,
     double *value, gpointer user_data);
 
-gdouble parse_expression (const gchar *expr,
-                          ParseVariableFunc variable_func,
-                          gpointer user_data,
-                          gchar **error);
+gdouble gst_validate_utils_parse_expression (const gchar *expr,
+                                             ParseVariableFunc variable_func,
+                                             gpointer user_data,
+                                             gchar **error);
+guint gst_validate_utils_flags_from_str     (GType type, const gchar * str_flags);
+void gst_validate_utils_enum_from_str       (GType type,
+                                             const gchar * str_enum,
+                                             guint * enum_value);
 #endif