[gstreamermm] Gst::Task: update Task wrapper



commit a7c6846260add9db99f852cec46f48055b36a4a0
Author: Marcin Kolny <marcin kolny gmail com>
Date:   Wed Oct 14 22:35:18 2015 +0200

    Gst::Task: update Task wrapper
    
        * gstreamer/src/task.{ccg|hg}: add methods set_leave_slot() and
          set_enter_slot(), replace deprecated auto_ptr with unique_ptr.

 gstreamer/src/task.ccg |   32 ++++++++++-------------------
 gstreamer/src/task.hg  |   51 ++++++++++++++++++++++++++++-------------------
 2 files changed, 41 insertions(+), 42 deletions(-)
---
diff --git a/gstreamer/src/task.ccg b/gstreamer/src/task.ccg
index 856fc96..d8a83bf 100644
--- a/gstreamer/src/task.ccg
+++ b/gstreamer/src/task.ccg
@@ -41,9 +41,9 @@ static void Task_Task_gstreamermm_callback(void* data)
   }
 }
 
-static void Task_Enter_gstreamermm_callback(GstTask* task, GThread* thread, gpointer user_data)
+static void Task_Thread_gstreamermm_callback(GstTask* task, GThread* thread, gpointer user_data)
 {
-  Gst::Task::SlotEnter* the_slot = static_cast<Gst::Task::SlotEnter*>(user_data);
+  Gst::Task::TaskThreadSlot* the_slot = static_cast<Gst::Task::TaskThreadSlot*>(user_data);
 
   try
   {
@@ -55,22 +55,9 @@ static void Task_Enter_gstreamermm_callback(GstTask* task, GThread* thread, gpoi
   }
 }
 
-static void Task_Leave_gstreamermm_callback(GstTask *task, GThread *thread, gpointer user_data)
-{
-  Gst::Task::SlotLeave* the_slot = static_cast<Gst::Task::SlotLeave*>(user_data);
-  try
-  {
-    (*the_slot)(Glib::wrap(task, true), Glib::Threads::wrap(thread));
-  }
-  catch(...)
-  {
-    Glib::exception_handlers_invoke();
-  }
-}
-
 static void Task_Callbacks_gstreamermm_callback_destroy(void* data)
 {
-  delete static_cast<Gst::Task::BiSlot*>(data);
+  delete static_cast<Gst::Task::TaskThreadSlot*>(data);
 }
 
 } // extern "C"
@@ -86,7 +73,7 @@ Task::Task(const SlotTask& task_slot)
 {
   // Create a copy of the slot.  A pointer to this copy will be passed through
   // the call back's data parameter.  It will be destroyed with the
-  // std::auto_ptr<>.
+  // std::unique_ptr<>.
   m_slot.reset(new SlotTask(task_slot));
 
   // These lines are taken verbatim from gst_task_create() after calling
@@ -95,11 +82,14 @@ Task::Task(const SlotTask& task_slot)
   gobj()->user_data = m_slot.get();
 }
 
-void Task::set_thread_slots(const SlotEnter& enter_slot,
-  const SlotLeave& leave_slot)
+void Task::set_leave_slot(const SlotLeave& leave_slot)
+{
+  gst_task_set_leave_callback(gobj(), &Task_Thread_gstreamermm_callback, new SlotLeave(leave_slot), 
&Task_Callbacks_gstreamermm_callback_destroy);
+}
+
+void Task::set_enter_slot(const SlotEnter& enter_slot)
 {
-  gst_task_set_enter_callback(gobj(), &Task_Enter_gstreamermm_callback, new SlotEnter(enter_slot), 
&Task_Callbacks_gstreamermm_callback_destroy);
-  gst_task_set_leave_callback(gobj(), &Task_Leave_gstreamermm_callback, new SlotEnter(leave_slot), 
&Task_Callbacks_gstreamermm_callback_destroy);
+  gst_task_set_enter_callback(gobj(), &Task_Thread_gstreamermm_callback, new SlotEnter(enter_slot), 
&Task_Callbacks_gstreamermm_callback_destroy);
 }
 
 } //namespace Gst
diff --git a/gstreamer/src/task.hg b/gstreamer/src/task.hg
index ea2ead2..1026ac4 100644
--- a/gstreamer/src/task.hg
+++ b/gstreamer/src/task.hg
@@ -1,6 +1,6 @@
 /* gstreamermm - a C++ wrapper for gstreamer
  *
- * Copyright 2008 The gstreamermm Development Team
+ * Copyright 2008-2015 The gstreamermm Development Team
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -59,7 +59,16 @@ class TaskPool;
  * running anymore. Use join() to make sure the task is completely stopped and
  * the thread is stopped.
  *
- * Last reviewed on 2006-02-13 (0.10.4)
+ * Task functions can send a Gst::Message to send out-of-band data to the
+ * application. The application can receive messages from the Gst::Bus in its
+ * mainloop.
+ *
+ * For debugging purposes, the task will configure its object name as the thread
+ * name on Linux. Please note that the object name should be configured before the
+ * task is started; changing the object name after the task has been started, has
+ * no effect on the thread name.
+ *
+ * Last reviewed on 2015-10-14 (1.5.2)
  */
 class Task : public Object
 {
@@ -75,14 +84,14 @@ public:
    * Bidirectional slot
    */
   typedef sigc::slot<void, const Glib::RefPtr<Gst::Task>&,
-          Glib::Threads::Thread*> BiSlot;
+          Glib::Threads::Thread*> TaskThreadSlot;
   /** For example,
    * void on_enter(const Glib::RefPtr<Gst::Task>& task, Glib::Threads::Thread&
    * thread);.
    * A thread is entered, this slot is called when the new thread enters its
    * function.
    */
-   typedef BiSlot SlotEnter;
+   typedef TaskThreadSlot SlotEnter;
 
   /** For example,
    * void on_leave(const Glib::RefPtr<Gst::Task>& task, Glib::Threads::Thread&
@@ -90,7 +99,7 @@ public:
    * A thread is exiting, this is called when the thread is about to leave its
    * function.
    */
-    typedef BiSlot SlotLeave;
+    typedef TaskThreadSlot SlotLeave;
 
 protected:
   explicit Task(const SlotTask& task_slot);
@@ -112,24 +121,19 @@ public:
   _WRAP_METHOD(Glib::RefPtr<Gst::TaskPool> get_pool(), gst_task_get_pool)
   _WRAP_METHOD(Glib::RefPtr<const Gst::TaskPool> get_pool() const, gst_task_get_pool)
 
-  /** Set slots which will be executed when a new thread is needed, the thread
-   * function is entered and left and when the thread is joined.
-   *
-   * By default a thread for the task will be created from a default thread
-   * pool.
-   *
-   * Objects can use custom Glib::Threads::Thread or can perform additional
-   * configuration of the threads (such as changing the thread priority) by
-   * installing slots.
+  /** Call enter_slot when the task function of task is entered.
    *
-   * MT safe.
-   *
-   * @param enter_slot A SlotEnter slot.
-   * @param leave_slot A SlotLeave slot.
+   * @param enter_slot
+   */
+  void set_enter_slot(const SlotEnter& enter_slot);
+  _IGNORE(gst_task_set_enter_callback)
+
+  /** Call leave_func when the task function of task is left.
    *
-   * Since 0.10.24.
+   * @param leave_slot
    */
-  void set_thread_slots(const SlotEnter& enter_slot, const SlotLeave& leave_slot);
+  void set_leave_slot(const SlotLeave& leave_slot);
+  _IGNORE(gst_task_set_leave_callback)
 
   _WRAP_METHOD(TaskState get_state() const, gst_task_get_state)
   _WRAP_METHOD(void set_state(Gst::TaskState state), gst_task_set_state)
@@ -141,7 +145,12 @@ public:
 
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
 private:
-  std::auto_ptr<SlotTask> m_slot;
+  // todo this slot should be moved in move constructor, but for now it's
+  // impossible to provide custom move constructor
+  // (see https://bugzilla.gnome.org/show_bug.cgi?id=756593).
+  // However, task should be managed by RefPtr class, so move constructor
+  // and move assignment operator will never be called.
+  std::unique_ptr<SlotTask> m_slot;
 #endif
 };
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]