From 04029cb065166377b4635bac2c67ff10fa39a56d Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Tue, 18 Feb 2014 18:13:39 +0100 Subject: [PATCH] validate: Move enums and flags deserialization from scenario to utilities This way it can be reused. --- validate/gst/validate/gst-validate-scenario.c | 49 ++++--------------- validate/gst/validate/gst-validate-utils.c | 36 +++++++++++++- validate/gst/validate/gst-validate-utils.h | 13 +++-- 3 files changed, 53 insertions(+), 45 deletions(-) diff --git a/validate/gst/validate/gst-validate-scenario.c b/validate/gst/validate/gst-validate-scenario.c index e52b6f36f6..c48b7b2c15 100644 --- a/validate/gst/validate/gst-validate-scenario.c +++ b/validate/gst/validate/gst-validate-scenario.c @@ -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); } } diff --git a/validate/gst/validate/gst-validate-utils.c b/validate/gst/validate/gst-validate-utils.c index d25cd6b07c..f2db381a92 100644 --- a/validate/gst/validate/gst-validate-utils.c +++ b/validate/gst/validate/gst-validate-utils.c @@ -27,6 +27,7 @@ #include #include "gst-validate-utils.h" +#include #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); +} diff --git a/validate/gst/validate/gst-validate-utils.h b/validate/gst/validate/gst-validate-utils.h index 510a211108..9d8e717222 100644 --- a/validate/gst/validate/gst-validate-utils.h +++ b/validate/gst/validate/gst-validate-utils.h @@ -26,12 +26,17 @@ #include #include #include +#include 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