Debian Codegraph @

gstreamer/src/bus.ccg

raw
1 /* gstreamermm - a C++ wrapper for gstreamer
2 *
3 * Copyright 2008-2016 The gstreamermm Development Team
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 _PINCLUDE(glibmm/private/object_p.h)
21 _PINCLUDE(gstreamermm/private/object_p.h)
22
23 namespace
24 {
25
26 extern "C"
27 {
28
29 static gboolean Bus_Message_gstreamermm_callback(GstBus* bus, GstMessage* message, void* data)
30 {
31 Gst::Bus::SlotMessage* the_slot = static_cast<Gst::Bus::SlotMessage*>(data);
32
33 try
34 {
35 return (*the_slot)(Glib::wrap(bus, true), Glib::wrap(message, true));
36 }
37 catch(...)
38 {
39 Glib::exception_handlers_invoke();
40 }
41
42 return false;
43 }
44
45 static void Bus_Message_gstreamermm_callback_destroy(void* data)
46 {
47 delete static_cast<Gst::Bus::SlotMessage*>(data);
48 }
49
50 static GstBusSyncReply Bus_Message_Sync_gstreamermm_callback(GstBus* bus, GstMessage* message, void* data)
51 {
52 Gst::Bus::SlotMessageSync* the_slot = static_cast<Gst::Bus::SlotMessageSync*>(data);
53
54 try
55 {
56 return static_cast<GstBusSyncReply>((*the_slot)(Glib::wrap(bus, true), Glib::wrap(message, true)));
57 }
58 catch(...)
59 {
60 Glib::exception_handlers_invoke();
61 }
62
63 return GST_BUS_PASS;
64 }
65
66 } // extern "C"
67
68 } // anonymous namespace
69
70 namespace Gst
71 {
72
73 guint Bus::add_watch(const SlotMessage& slot, int priority)
74 {
75 //Create a copy of the slot. A pointer to this will be passed through the callback's data parameter.
76 //It will be deleted when Bus_Message_gstreamermm_callback_destroy() is called.
77 SlotMessage* slot_copy = new SlotMessage(slot);
78 return gst_bus_add_watch_full(gobj(), priority,
79 &Bus_Message_gstreamermm_callback, slot_copy,
80 &Bus_Message_gstreamermm_callback_destroy);
81 }
82
83 bool Bus::remove_watch(guint id)
84 {
85 return g_source_remove(id);
86 }
87
88 void Bus::set_sync_handler(const SlotMessageSync& slot)
89 {
90 // Clear a possibly existing sync handler by calling with 0 before setting
91 // a new one (see gst_bus_set_sync_handler docs)
92 gst_bus_set_sync_handler(gobj(), 0, 0, 0);
93
94 SlotMessageSync* slot_copy = new SlotMessageSync(slot);
95 gst_bus_set_sync_handler(gobj(), &Bus_Message_Sync_gstreamermm_callback, slot_copy, &Bus_Message_gstreamermm_callback_destroy);
96 }
97
98 } //namespace Gst