validate: Factor out a function to print action types parametters

+ Remove playback-type from the list and just print it
This commit is contained in:
Thibault Saunier 2014-11-26 17:50:11 +01:00
parent db67a92b3f
commit 582f1cfc06
4 changed files with 80 additions and 76 deletions

View file

@ -504,6 +504,66 @@ gst_validate_printf (gpointer source, const gchar * format, ...)
va_end (var_args);
}
static void
print_action_parametter (GString * string, GstValidateActionType * type,
GstValidateActionParameter * param)
{
gint nw = 0;
gchar *desc, *tmp;
gchar *param_head = g_strdup_printf (" %s", param->name);
gchar *tmp_head = g_strdup_printf ("\n %-30s : %s",
param_head, "something");
while (tmp_head[nw] != ':')
nw++;
g_free (tmp_head);
tmp = g_strdup_printf ("\n%*s", nw + 1, " ");
if (g_strcmp0 (param->description, "")) {
desc =
g_regex_replace (newline_regex, param->description,
-1, 0, tmp, 0, NULL);
} else {
desc = g_strdup_printf ("No description");
}
g_string_append_printf (string, "\n %-30s : %s", param_head, desc);
g_free (desc);
if (param->possible_variables) {
gchar *tmp1 = g_strdup_printf ("\n%*s", nw + 4, " ");
desc =
g_regex_replace (newline_regex,
param->possible_variables, -1, 0, tmp1, 0, NULL);
g_string_append_printf (string, "%sPossible variables:%s%s", tmp,
tmp1, desc);
g_free (tmp1);
}
if (param->types) {
gchar *tmp1 = g_strdup_printf ("\n%*s", nw + 4, " ");
desc = g_regex_replace (newline_regex, param->types, -1, 0, tmp1, 0, NULL);
g_string_append_printf (string, "%sPossible types:%s%s", tmp, tmp1, desc);
g_free (tmp1);
}
if (!param->mandatory) {
g_string_append_printf (string, "%sDefault: %s", tmp, param->def);
}
g_string_append_printf (string, "%s%s", tmp,
param->mandatory ? "Mandatory." : "Optional.");
g_free (tmp);
g_free (param_head);
}
void
gst_validate_printf_valist (gpointer source, const gchar * format, va_list args)
{
@ -524,6 +584,18 @@ gst_validate_printf_valist (gpointer source, const gchar * format, va_list args)
gint i;
gchar *desc, *tmp;
GstValidateActionParameter playback_time_param = {
.name = "playback-time",
.description =
"The playback time at which the action " "will be executed",
.mandatory = FALSE,
.types = "double,string",
.possible_variables =
"position: The current position in the stream\n"
"duration: The duration of the stream",
.def = "0.0"
};
GstValidateActionType *type = GST_VALIDATE_ACTION_TYPE (source);
g_string_printf (string, "\nAction type:");
@ -544,69 +616,15 @@ gst_validate_printf_valist (gpointer source, const gchar * format, va_list args)
g_free (desc);
g_free (tmp);
if (!IS_CONFIG_ACTION_TYPE (type->flags))
print_action_parametter (string, type, &playback_time_param);
if (type->parameters) {
g_string_append_printf (string, "\n\n Parametters:");
for (i = 0; type->parameters[i].name; i++) {
gint nw = 0;
gchar *param_head =
g_strdup_printf (" %s", type->parameters[i].name);
gchar *tmp_head = g_strdup_printf ("\n %-30s : %s",
param_head, "something");
while (tmp_head[nw] != ':')
nw++;
g_free (tmp_head);
tmp = g_strdup_printf ("\n%*s", nw + 1, " ");
if (g_strcmp0 (type->parameters[i].description, "")) {
desc =
g_regex_replace (newline_regex, type->parameters[i].description,
-1, 0, tmp, 0, NULL);
} else {
desc = g_strdup_printf ("No description");
}
g_string_append_printf (string, "\n %-30s : %s", param_head, desc);
g_free (desc);
if (type->parameters[i].possible_variables) {
gchar *tmp1 = g_strdup_printf ("\n%*s", nw + 4, " ");
desc =
g_regex_replace (newline_regex,
type->parameters[i].possible_variables, -1, 0, tmp1, 0, NULL);
g_string_append_printf (string, "%sPossible variables:%s%s", tmp,
tmp1, desc);
g_free (tmp1);
}
if (type->parameters[i].types) {
gchar *tmp1 = g_strdup_printf ("\n%*s", nw + 4, " ");
desc =
g_regex_replace (newline_regex,
type->parameters[i].types, -1, 0, tmp1, 0, NULL);
g_string_append_printf (string, "%sPossible types:%s%s", tmp,
tmp1, desc);
g_free (tmp1);
}
if (!type->parameters[i].mandatory) {
g_string_append_printf (string, "%sDefault: %s", tmp,
type->parameters[i].def);
}
g_string_append_printf (string, "%s%s", tmp,
type->parameters[i].mandatory ? "Mandatory." : "Optional.");
g_free (tmp);
g_free (param_head);
print_action_parametter (string, type, &type->parameters[i]);
}
} else {
g_string_append_printf (string, "\n\n No Parameters");

View file

@ -1999,9 +1999,7 @@ gst_validate_register_action_type (const gchar * type_name,
if (parameters) {
for (n_params = 0; parameters[n_params].name != NULL; n_params++);
if (is_config)
n_params += 1;
n_params += 1;
}
if (n_params) {
@ -2013,18 +2011,6 @@ gst_validate_register_action_type (const gchar * type_name,
sizeof (GstValidateActionParameter) * (n_params));
}
if (!is_config) {
type->parameters[n_params - 1].name = "playback-time";
type->parameters[n_params - 1].description =
"The playback time at which the action " "will be executed";
type->parameters[n_params - 1].mandatory = FALSE;
type->parameters[n_params - 1].types = "double,string";
type->parameters[n_params - 1].possible_variables =
"position: The current position in the stream\n"
"duration: The duration of the stream";
type->parameters[n_params - 1].def = "0.0";
}
type->execute = function;
type->name = g_strdup (type_name);
type->implementer_namespace = g_strdup (implementer_namespace);

View file

@ -1,5 +1,5 @@
/**
* Insanity QA system
* GstValidate
*
* Copyright (c) 2012, Collabora Ltd
* Author: Thibault Saunier <thibault.saunier@collabora.com>

View file

@ -1,5 +1,5 @@
/**
* Gstreamer
* GstValidate
*
* Copyright (c) 2012, Collabora Ltd.
* Author: Thibault Saunier <thibault.saunier@collabora.com>