fix doc build fix autogen
[platform/upstream/gstreamer.git] / gst / gstprobe.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wim.taymans@chello.be>
4  *
5  * gstprobe.h: Header for GstProbe object
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23
24 #include "gstlog.h"
25 #include "gstprobe.h"
26
27 /**
28  * gst_probe_new:
29  * @single_shot: TRUE if a single shot probe is required
30  * @callback: the function to call when the probe is triggered
31  * @user_data: data passed to the callback function
32  *
33  * Create a new probe with the specified parameters
34  *
35  * Returns: a new #GstProbe.
36  */
37 GstProbe*
38 gst_probe_new (gboolean single_shot, 
39                GstProbeCallback callback, 
40                gpointer user_data)
41 {
42   GstProbe *probe;
43
44   g_return_val_if_fail (callback, NULL);
45
46   probe = g_new0 (GstProbe, 1);
47
48   probe->single_shot = single_shot;
49   probe->callback    = callback;
50   probe->user_data   = user_data;
51   
52   return probe;
53 }
54
55 /**
56  * gst_probe_destroy:
57  * @probe: The probe to destroy
58  *
59  * Free the memeory associated with the probe.
60  */
61 void
62 gst_probe_destroy (GstProbe *probe)
63 {
64   g_return_if_fail (probe);
65
66 #ifdef USE_POISONING
67   memset(probe, 0xff, sizeof(*probe));
68 #endif
69
70   g_free (probe);
71 }
72
73 /**
74  * gst_probe_perform:
75  * @probe: The probe to trigger
76  * @data: the GstData that triggered the probe.
77  *
78  * Perform the callback associated with the given probe.
79  *
80  * Returns: the result of the probe callback function.
81  */
82 gboolean
83 gst_probe_perform (GstProbe *probe, GstData **data)
84 {
85   gboolean res = TRUE;
86
87   g_return_val_if_fail (probe, res);
88   
89   if (probe->callback)
90     res = probe->callback (probe, data, probe->user_data);
91   
92   return res;
93 }
94
95 /**
96  * gst_probe_dispatcher_new:
97  *
98  * Create a new probe dispatcher
99  *
100  * Returns: a new probe dispatcher.
101  */
102 GstProbeDispatcher*
103 gst_probe_dispatcher_new (void)
104 {
105   GstProbeDispatcher *disp;
106   
107   disp = g_new0 (GstProbeDispatcher, 1);
108
109   gst_probe_dispatcher_init (disp);
110   
111   return disp;
112 }
113
114 /**
115  * gst_probe_dispatcher_destroy:
116  * @disp: the dispatcher to destroy
117  *
118  * Free the memory allocated by the probe dispatcher. All pending
119  * probes are removed first.
120  */
121 void            
122 gst_probe_dispatcher_destroy (GstProbeDispatcher *disp)
123 {
124   g_return_if_fail (disp);
125   
126 #ifdef USE_POISONING
127   memset(disp, 0xff, sizeof(*disp));
128 #endif
129
130   /* FIXME, free pending probes */
131   g_free (disp);
132 }
133
134 /**
135  * gst_probe_dispatcher_init:
136  * @disp: the dispatcher to initialize
137  *
138  * Initialize the dispatcher. Useful for statically allocated probe
139  * dispatchers.
140  */
141 void
142 gst_probe_dispatcher_init (GstProbeDispatcher *disp)
143 {
144   g_return_if_fail (disp);
145
146   disp->active = TRUE;
147   disp->probes = NULL;
148 }
149
150 /**
151  * gst_probe_dispatcher_set_active:
152  * @disp: the dispatcher to activate
153  * @active: boolean to indicate activation or deactivation
154  *
155  * Activate or deactivate the given dispatcher
156  * dispatchers.
157  */
158 void            
159 gst_probe_dispatcher_set_active (GstProbeDispatcher *disp, gboolean active)
160 {
161   g_return_if_fail (disp);
162
163   disp->active = active;
164 }
165
166 /**
167  * gst_probe_dispatcher_add_probe:
168  * @disp: the dispatcher to add the probe to
169  * @probe: the probe to add to the dispatcher
170  *
171  * Adds the given probe to the dispatcher.
172  */
173 void
174 gst_probe_dispatcher_add_probe (GstProbeDispatcher *disp, GstProbe *probe)
175 {
176   g_return_if_fail (disp);
177   g_return_if_fail (probe);
178   
179   disp->probes = g_slist_prepend (disp->probes, probe);
180 }
181
182 /**
183  * gst_probe_dispatcher_remove_probe:
184  * @disp: the dispatcher to remove the probe from
185  * @probe: the probe to remove from the dispatcher
186  *
187  * Removes the given probe from the dispatcher.
188  */
189 void
190 gst_probe_dispatcher_remove_probe (GstProbeDispatcher *disp, GstProbe *probe)
191 {
192   g_return_if_fail (disp);
193   g_return_if_fail (probe);
194   
195   disp->probes = g_slist_remove (disp->probes, probe);
196 }
197
198 /**
199  * gst_probe_dispatcher_dispatch:
200  * @disp: the dispatcher to dispatch
201  * @data: the data that triggered the dispatch
202  *
203  * Trigger all registered probes on the given dispatcher.
204  *
205  * Returns: TRUE if all callbacks returned TRUE.
206  */
207 gboolean        
208 gst_probe_dispatcher_dispatch (GstProbeDispatcher *disp, GstData **data)
209 {
210   GSList *walk;
211   gboolean res = TRUE;
212
213   g_return_val_if_fail (disp, res);
214
215   walk = disp->probes;
216   while (walk) {
217     GstProbe *probe = (GstProbe *) walk->data;
218     walk = g_slist_next (walk);
219
220     res &= gst_probe_perform (probe, data);
221     if (probe->single_shot) {
222       disp->probes = g_slist_remove (disp->probes, probe);
223
224       gst_probe_destroy (probe);
225     }
226   }
227
228   return res;
229 }