2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wim.taymans@chello.be>
5 * gstprobe.h: Header for GstProbe object
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.
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.
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.
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
33 * Create a new probe with the specified parameters
35 * Returns: a new #GstProbe.
38 gst_probe_new (gboolean single_shot,
39 GstProbeCallback callback,
44 g_return_val_if_fail (callback, NULL);
46 probe = g_new0 (GstProbe, 1);
48 probe->single_shot = single_shot;
49 probe->callback = callback;
50 probe->user_data = user_data;
57 * @probe: The probe to destroy
59 * Free the memeory associated with the probe.
62 gst_probe_destroy (GstProbe *probe)
64 g_return_if_fail (probe);
67 memset(probe, 0xff, sizeof(*probe));
75 * @probe: The probe to trigger
76 * @data: the GstData that triggered the probe.
78 * Perform the callback associated with the given probe.
80 * Returns: the result of the probe callback function.
83 gst_probe_perform (GstProbe *probe, GstData **data)
87 g_return_val_if_fail (probe, res);
90 res = probe->callback (probe, data, probe->user_data);
96 * gst_probe_dispatcher_new:
98 * Create a new probe dispatcher
100 * Returns: a new probe dispatcher.
103 gst_probe_dispatcher_new (void)
105 GstProbeDispatcher *disp;
107 disp = g_new0 (GstProbeDispatcher, 1);
109 gst_probe_dispatcher_init (disp);
115 * gst_probe_dispatcher_destroy:
116 * @disp: the dispatcher to destroy
118 * Free the memory allocated by the probe dispatcher. All pending
119 * probes are removed first.
122 gst_probe_dispatcher_destroy (GstProbeDispatcher *disp)
124 g_return_if_fail (disp);
127 memset(disp, 0xff, sizeof(*disp));
130 /* FIXME, free pending probes */
135 * gst_probe_dispatcher_init:
136 * @disp: the dispatcher to initialize
138 * Initialize the dispatcher. Useful for statically allocated probe
142 gst_probe_dispatcher_init (GstProbeDispatcher *disp)
144 g_return_if_fail (disp);
151 * gst_probe_dispatcher_set_active:
152 * @disp: the dispatcher to activate
153 * @active: boolean to indicate activation or deactivation
155 * Activate or deactivate the given dispatcher
159 gst_probe_dispatcher_set_active (GstProbeDispatcher *disp, gboolean active)
161 g_return_if_fail (disp);
163 disp->active = active;
167 * gst_probe_dispatcher_add_probe:
168 * @disp: the dispatcher to add the probe to
169 * @probe: the probe to add to the dispatcher
171 * Adds the given probe to the dispatcher.
174 gst_probe_dispatcher_add_probe (GstProbeDispatcher *disp, GstProbe *probe)
176 g_return_if_fail (disp);
177 g_return_if_fail (probe);
179 disp->probes = g_slist_prepend (disp->probes, probe);
183 * gst_probe_dispatcher_remove_probe:
184 * @disp: the dispatcher to remove the probe from
185 * @probe: the probe to remove from the dispatcher
187 * Removes the given probe from the dispatcher.
190 gst_probe_dispatcher_remove_probe (GstProbeDispatcher *disp, GstProbe *probe)
192 g_return_if_fail (disp);
193 g_return_if_fail (probe);
195 disp->probes = g_slist_remove (disp->probes, probe);
199 * gst_probe_dispatcher_dispatch:
200 * @disp: the dispatcher to dispatch
201 * @data: the data that triggered the dispatch
203 * Trigger all registered probes on the given dispatcher.
205 * Returns: TRUE if all callbacks returned TRUE.
208 gst_probe_dispatcher_dispatch (GstProbeDispatcher *disp, GstData **data)
213 g_return_val_if_fail (disp, res);
217 GstProbe *probe = (GstProbe *) walk->data;
218 walk = g_slist_next (walk);
220 res &= gst_probe_perform (probe, data);
221 if (probe->single_shot) {
222 disp->probes = g_slist_remove (disp->probes, probe);
224 gst_probe_destroy (probe);