5cb5863156419b1c4690dc3f7cb54b5be04063c8
[platform/upstream/gstreamer.git] / validate / gst / validate / gst-validate-monitor-factory.c
1 /* GStreamer
2  *
3  * Copyright (C) 2013 Collabora Ltd.
4  *  Author: Thiago Sousa Santos <thiago.sousa.santos@collabora.com>
5  *
6  * gst-validate-monitor-factory.c - Validate Element monitors factory utility functions
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 /**
25  * SECTION:gst-validate-monitor-factory
26  * @title: GstValidateMonitorFactory
27  * @short_description: Lets you start monitoring a #GstObject with GstValidate
28  *
29  * To start monitoring and thus run GstValidate tests on a #GstPipeline, the only thing to
30  * do is to instanciate a #GstValidateRunner and then attach a #GstValidateMonitor
31  * to it with #gst_validate_monitor_factory_create
32  */
33
34 #ifdef HAVE_CONFIG_H
35 #  include "config.h"
36 #endif
37
38 #include "gst-validate-monitor-factory.h"
39 #include "gst-validate-bin-monitor.h"
40 #include "gst-validate-pipeline-monitor.h"
41 #include "gst-validate-pad-monitor.h"
42 #include "gst-validate-override-registry.h"
43
44 /**
45  * gst_validate_monitor_factory_create:
46  * @target: The #GstObject to create a #GstValidateMonitor for
47  * @runner: The #GstValidateRunner to use for the new monitor
48  * @parent: (nullable): The parent of the new monitor
49  *
50  * Create a new monitor for @target and starts monitoring it.
51  *
52  * Returns: (transfer full): The newly created #GstValidateMonitor
53  */
54 GstValidateMonitor *
55 gst_validate_monitor_factory_create (GstObject * target,
56     GstValidateRunner * runner, GstValidateMonitor * parent)
57 {
58   GstValidateMonitor *monitor = NULL;
59   g_return_val_if_fail (target != NULL, NULL);
60
61   monitor = g_object_get_data ((GObject *) target, "validate-monitor");
62   if (monitor) {
63     GST_INFO_OBJECT (target, "Is already monitored by %" GST_PTR_FORMAT,
64         monitor);
65
66     return g_object_ref (monitor);
67   }
68
69   if (GST_IS_PAD (target)) {
70     monitor =
71         GST_VALIDATE_MONITOR_CAST (gst_validate_pad_monitor_new (GST_PAD_CAST
72             (target), runner, GST_VALIDATE_ELEMENT_MONITOR_CAST (parent)));
73   } else if (GST_IS_PIPELINE (target)) {
74     monitor =
75         GST_VALIDATE_MONITOR_CAST (gst_validate_pipeline_monitor_new
76         (GST_PIPELINE_CAST (target), runner, parent));
77   } else if (GST_IS_BIN (target)) {
78     monitor =
79         GST_VALIDATE_MONITOR_CAST (gst_validate_bin_monitor_new (GST_BIN_CAST
80             (target), runner, parent));
81   } else if (GST_IS_ELEMENT (target)) {
82     monitor =
83         GST_VALIDATE_MONITOR_CAST (gst_validate_element_monitor_new
84         (GST_ELEMENT_CAST (target), runner, parent));
85   } else {
86     g_assert_not_reached ();
87   }
88
89   return monitor;
90 }