scenario: Add a signal to notify user when the scenario is DONE executing
authorThibault Saunier <tsaunier@gnome.org>
Wed, 10 Dec 2014 19:37:58 +0000 (20:37 +0100)
committerThibault Saunier <tsaunier@gnome.org>
Sat, 14 Feb 2015 15:31:57 +0000 (16:31 +0100)
https://bugzilla.gnome.org/show_bug.cgi?id=743994

validate/gst/validate/gst-validate-scenario.c

index 2c6867f..b03c9d6 100644 (file)
@@ -72,6 +72,14 @@ enum
   PROP_LAST
 };
 
+enum
+{
+  DONE,
+  LAST_SIGNAL
+};
+
+static guint scenario_signals[LAST_SIGNAL] = { 0 };
+
 static GList *action_types = NULL;
 static void gst_validate_scenario_dispose (GObject * object);
 static void gst_validate_scenario_finalize (GObject * object);
@@ -914,10 +922,12 @@ get_position (GstValidateScenario * scenario)
       gst_mini_object_unref (GST_MINI_OBJECT (act));
       g_list_free (tmp);
 
-      if (scenario->priv->actions)
+      if (scenario->priv->actions) {
         act = scenario->priv->actions->data;
-      else
+      } else {
+        g_signal_emit (scenario, scenario_signals[DONE], 0);
         act = NULL;
+      }
     } else if (act->state == GST_VALIDATE_EXECUTE_ACTION_ASYNC) {
       GST_DEBUG_OBJECT (scenario, "Action %" GST_PTR_FORMAT " still running",
           act->structure);
@@ -998,6 +1008,9 @@ get_position (GstValidateScenario * scenario)
     priv->actions = g_list_remove_link (priv->actions, tmp);
     gst_mini_object_unref (GST_MINI_OBJECT (act));
 
+    if (priv->actions == NULL)
+      g_signal_emit (scenario, scenario_signals[DONE], 0);
+
     g_list_free (tmp);
   }
 
@@ -1293,7 +1306,8 @@ message_cb (GstBus * bus, GstMessage * message, GstValidateScenario * scenario)
         gst_message_parse_state_changed (message, &pstate, &nstate, NULL);
 
         if (scenario->priv->target_state == nstate) {
-          if (_action_sets_state (scenario->priv->actions->data))
+          if (scenario->priv->actions &&
+              _action_sets_state (scenario->priv->actions->data))
             gst_validate_action_set_done (priv->actions->data);
           scenario->priv->changing_state = FALSE;
         }
@@ -1654,6 +1668,16 @@ gst_validate_scenario_class_init (GstValidateScenarioClass * klass)
           "True if the application should not set handle the first state change "
           " False if it is application responsibility",
           FALSE, G_PARAM_READABLE));
+
+  /**
+   * GstValidateScenario::done:
+   * @scenario: The scenario runing
+   *
+   * Emitted once all actions have been executed
+   */
+  scenario_signals[DONE] =
+      g_signal_new ("done", G_TYPE_FROM_CLASS (klass),
+      G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
 }
 
 static void
@@ -1724,6 +1748,9 @@ _element_added_cb (GstBin * bin, GstElement * element,
       tmp = tmp->next;
   }
 
+  if (priv->actions == NULL)
+    g_signal_emit (scenario, scenario_signals[DONE], 0);
+
   /* If it's a bin, listen to the child */
   if (GST_IS_BIN (element)) {
     g_signal_connect (element, "element-added", (GCallback) _element_added_cb,
@@ -1977,7 +2004,7 @@ gst_validate_action_set_done (GstValidateAction * action)
  * @type_name: The name of the new action type to add
  * @implementer_namespace: The namespace of the implementer of the action type
  * @function: (scope notified): The function to be called to execute the action
- * @parameters: The #GstValidateActionParameter usable as parameter of the type
+ * @parameters: (allow-none) (array zero-terminated=1) (element-type GstValidate.ActionParameter): The #GstValidateActionParameter usable as parameter of the type
  * @description: A description of the new type
  * @is_config: Whether the action is a config action or not. A config action will
  * be executed even before the pipeline starts processing