Debian Codegraph @

gstreamer/src/task.ccg

raw
1 /* gstreamermm - a C++ wrapper for gstreamer
2 *
3 * Copyright 2008 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 #include <gst/gst.h>
21 #include <gstreamermm/taskpool.h>
22 _PINCLUDE(gstreamermm/private/object_p.h)
23
24 namespace
25 {
26
27 extern "C"
28 {
29
30 static void Task_Task_gstreamermm_callback(void* data)
31 {
32 Gst::Task::SlotTask* the_slot = static_cast<Gst::Task::SlotTask*>(data);
33
34 try
35 {
36 (*the_slot)();
37 }
38 catch(...)
39 {
40 Glib::exception_handlers_invoke();
41 }
42 }
43
44 static void Task_Thread_gstreamermm_callback(GstTask* task, GThread* thread, gpointer user_data)
45 {
46 Gst::Task::TaskThreadSlot* the_slot = static_cast<Gst::Task::TaskThreadSlot*>(user_data);
47
48 try
49 {
50 (*the_slot)(Glib::wrap(task, true), Glib::Threads::wrap(thread));
51 }
52 catch(...)
53 {
54 Glib::exception_handlers_invoke();
55 }
56 }
57
58 static void Task_Callbacks_gstreamermm_callback_destroy(void* data)
59 {
60 delete static_cast<Gst::Task::TaskThreadSlot*>(data);
61 }
62
63 } // extern "C"
64
65 } // anonymous namespace
66
67 namespace Gst
68 {
69
70 Task::Task(const SlotTask& task_slot)
71 :
72 _CONSTRUCT()
73 {
74 // Create a copy of the slot. A pointer to this copy will be passed through
75 // the call back's data parameter. It will be destroyed with the
76 // std::unique_ptr<>.
77 m_slot.reset(new SlotTask(task_slot));
78
79 // These lines are taken verbatim from gst_task_create() after calling
80 // g_object_new().
81 gobj()->func = &Task_Task_gstreamermm_callback;
82 gobj()->user_data = m_slot.get();
83 }
84
85 void Task::set_leave_slot(const SlotLeave& leave_slot)
86 {
87 gst_task_set_leave_callback(gobj(), &Task_Thread_gstreamermm_callback, new SlotLeave(leave_slot), &Task_Callbacks_gstreamermm_callback_destroy);
88 }
89
90 void Task::set_enter_slot(const SlotEnter& enter_slot)
91 {
92 gst_task_set_enter_callback(gobj(), &Task_Thread_gstreamermm_callback, new SlotEnter(enter_slot), &Task_Callbacks_gstreamermm_callback_destroy);
93 }
94
95 } //namespace Gst