[gstreamermm] TaskPool: Wrap virtual functions.



commit 9e0c75e0101e6a0f9171819819c29fa84741faf3
Author: José Alburquerque <jaalburqu svn gnome org>
Date:   Fri Dec 4 00:40:45 2009 -0500

    	TaskPool: Wrap virtual functions.
    
    	* gstreamer/src/taskpool.ccg:
    	* gstreamer/src/taskpool.hg:
    	* gstreamer/src/gst_vfuncs.defs: Wrapped Gst::TaskPool vfuncs.
    	* examples/typefind/main.cc (main): Used #ifdefs for lines dealing
    	with properties for when properties are disabled.

 ChangeLog                     |   10 +++
 examples/typefind/main.cc     |    4 +
 gstreamer/src/gst_vfuncs.defs |   33 ++++++++
 gstreamer/src/taskpool.ccg    |  163 +++++++++++++++++++++++++++++++++++++++++
 gstreamer/src/taskpool.hg     |   43 +++++++++++-
 5 files changed, 252 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a001a4d..decfd3f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-12-03  José Alburquerque  <jaalburqu svn gnome org>
+
+	TaskPool: Wrap virtual functions.
+
+	* gstreamer/src/taskpool.ccg:
+	* gstreamer/src/taskpool.hg:
+	* gstreamer/src/gst_vfuncs.defs: Wrapped Gst::TaskPool vfuncs.
+	* examples/typefind/main.cc (main): Used #ifdefs for lines dealing
+	with properties for when properties are disabled.
+
 2009-12-02  José Alburquerque  <jaalburqu svn gnome org>
 
 	Message[Error|Warning|Info]: Fix the parse_debug() methods.
diff --git a/examples/typefind/main.cc b/examples/typefind/main.cc
index 07b751b..5e7975e 100644
--- a/examples/typefind/main.cc
+++ b/examples/typefind/main.cc
@@ -81,7 +81,11 @@ int main(int argc, char** argv)
 
   // Create elements:
   Glib::RefPtr<Gst::FileSrc> element_source = Gst::FileSrc::create();
+#ifdef GLIBMM_PROPERTIES_ENABLED
   element_source->property_location() = filename;
+#else
+  element_source->set_property("location", filename);
+#endif /* GLIBMM_PROPERTIES_ENABLED */
 
   //If using an MP3 file, this should provide more Caps information from typefind.
   //Glib::RefPtr<Gst::Element> element_id3demux = Gst::ElementFactory::create_element("id3demux");
diff --git a/gstreamer/src/gst_vfuncs.defs b/gstreamer/src/gst_vfuncs.defs
index 0d88f04..c44c462 100644
--- a/gstreamer/src/gst_vfuncs.defs
+++ b/gstreamer/src/gst_vfuncs.defs
@@ -332,6 +332,39 @@
   )
 )
 
+; GstTaskPool
+
+(define-vfunc prepare
+  (of-object "GstTaskPool")
+  (return-type "void")
+  (parameters
+   '("GError**" "error")
+  )
+)
+
+(define-vfunc cleanup
+  (of-object "GstTaskPool")
+  (return-type "void")
+)
+
+(define-vfunc push
+  (of-object "GstTaskPool")
+  (return-type "gpointer")
+  (parameters
+   '("GstTaskPoolFunction" "func")
+   '("gpointer" "user_data")
+   '("GError**" "error")
+  )
+)
+
+(define-vfunc join
+  (of-object "GstTaskPool")
+  (return-type "void")
+  (parameters
+   '("gpointer" "id")
+  )
+)
+
 ; GstURIHandler
 
 (define-vfunc get_uri
diff --git a/gstreamer/src/taskpool.ccg b/gstreamer/src/taskpool.ccg
index 80b8b09..b6a6a6e 100644
--- a/gstreamer/src/taskpool.ccg
+++ b/gstreamer/src/taskpool.ccg
@@ -75,4 +75,167 @@ gpointer TaskPool::push(const SlotPush& slot, std::auto_ptr<Glib::Error>& error)
   return ret_val;
 }
 
+#ifdef GLIBMM_VFUNCS_ENABLED
+void TaskPool_Class::prepare_vfunc_callback(GstTaskPool* self, GError** error)
+{
+  Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
+      Glib::ObjectBase::_get_current_wrapper((GObject*)self));
+
+  // Non-gtkmmproc-generated custom classes implicitly call the default
+  // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
+  // generated classes can use this optimisation, which avoids the unnecessary
+  // parameter conversions if there is no possibility of the virtual function
+  // being overridden:
+  if(obj_base && obj_base->is_derived_())
+  {
+    CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
+    if(obj) // This can be NULL during destruction.
+    {
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      try // Trap C++ exceptions which would normally be lost because this is a C callback.
+      {
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+        // Call the virtual member method, which derived classes might override.
+        #ifdef GLIBMM_EXCEPTIONS_ENABLED
+        obj->prepare_vfunc();
+        #else
+        std::auto_ptr<Glib::Error> cpp_error(0);
+        obj->prepare_vfunc(cpp_error);
+        if (cpp_error.get())
+          *error = g_error_copy(cpp_error->gobj());
+        #endif //GLIBMM_EXCEPTIONS_ENABLED
+
+        return;
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      }
+      catch(...)
+      {
+        Glib::exception_handlers_invoke();
+      }
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+    }
+  }
+  
+  BaseClassType *const base = static_cast<BaseClassType*>(
+      g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
+  );
+
+  // Call the original underlying C function:
+  if(base && base->prepare)
+    (*base->prepare)(self, error);
+
+}
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+void Gst::TaskPool::prepare_vfunc() 
+#else
+void Gst::TaskPool::prepare_vfunc(std::auto_ptr<Glib::Error>& error) 
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+{
+  BaseClassType *const base = static_cast<BaseClassType*>(
+      g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
+  );
+
+  if(base && base->prepare)
+  {
+    GError* gerror = 0;
+    (*base->prepare)(gobj(),&gerror);
+
+    #ifdef GLIBMM_EXCEPTIONS_ENABLED
+    if(gerror)
+      ::Glib::Error::throw_exception(gerror);
+    #else
+    if(gerror)
+      error = ::Glib::Error::throw_exception(gerror);
+    #endif //GLIBMM_EXCEPTIONS_ENABLED
+  }
+}
+gpointer TaskPool_Class::push_vfunc_callback(GstTaskPool* self, GstTaskPoolFunction func, gpointer user_data, GError** error)
+{
+  Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
+      Glib::ObjectBase::_get_current_wrapper((GObject*)self));
+
+  // Non-gtkmmproc-generated custom classes implicitly call the default
+  // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
+  // generated classes can use this optimisation, which avoids the unnecessary
+  // parameter conversions if there is no possibility of the virtual function
+  // being overridden:
+  if(obj_base && obj_base->is_derived_())
+  {
+    CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
+    if(obj) // This can be NULL during destruction.
+    {
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      try // Trap C++ exceptions which would normally be lost because this is a C callback.
+      {
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+        // Call the virtual member method, which derived classes might override.
+        Gst::TaskPool::SlotPush* slot =
+          static_cast<Gst::TaskPool::SlotPush*>(user_data);
+
+        #ifdef GLIBMM_EXCEPTIONS_ENABLED
+        return obj->push_vfunc(*slot);
+        #else
+        std::auto_ptr<Glib::Error> cpp_error(0);
+        gpointer result = obj->push_vfunc(*slot, cpp_error);
+        if (cpp_error.get())
+          *error = g_error_copy(cpp_error->gobj());
+        return result;
+        #endif //GLIBMM_EXCEPTIONS_ENABLED
+
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      }
+      catch(...)
+      {
+        Glib::exception_handlers_invoke();
+      }
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+    }
+  }
+  
+  BaseClassType *const base = static_cast<BaseClassType*>(
+      g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
+  );
+
+  // Call the original underlying C function:
+  if(base && base->push)
+    return (*base->push)(self, func, user_data, error);
+
+
+  typedef gpointer RType;
+  return RType();
+}
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+gpointer Gst::TaskPool::push_vfunc(const SlotPush& slot) 
+#else
+gpointer Gst::TaskPool::push_vfunc(const SlotPush& slot,
+  std::auto_ptr<Glib::Error>& error) 
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+{
+  BaseClassType *const base = static_cast<BaseClassType*>(
+      g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
+  );
+
+  if(base && base->push)
+  {
+    GError* gerror = 0;
+    gpointer result = (*base->push)(gobj(),
+      &TaskPool_Push_gstreamermm_callback, const_cast<SlotPush*>(&slot),
+        &gerror);
+
+    #ifdef GLIBMM_EXCEPTIONS_ENABLED
+    if(gerror)
+      ::Glib::Error::throw_exception(gerror);
+    #else
+    if(gerror)
+      error = ::Glib::Error::throw_exception(gerror);
+    #endif //GLIBMM_EXCEPTIONS_ENABLED
+
+    return result;
+  }
+
+  typedef gpointer RType;
+  return RType();
+}
+#endif //GLIBMM_VFUNCS_ENABLED
+
 } //namespace Gst
diff --git a/gstreamer/src/taskpool.hg b/gstreamer/src/taskpool.hg
index e47c430..2dc36f5 100644
--- a/gstreamer/src/taskpool.hg
+++ b/gstreamer/src/taskpool.hg
@@ -72,7 +72,48 @@ public:
   _WRAP_METHOD(void join(gpointer id), gst_task_pool_join)
   _WRAP_METHOD(void cleanup(), gst_task_pool_cleanup)
 
-  //TODO: Wrap vfuncs.
+#ifdef GLIBMM_VFUNCS_ENABLED
+  /** Virtual function which prepares the thread pool.
+   * @throw Glib::Error.
+   */
+  #ifdef GLIBMM_EXCEPTIONS_ENABLED
+  virtual void prepare_vfunc();
+  #else
+  virtual void prepare_vfunc(std::auto_ptr<Glib::Error>& error);
+  #endif //GLIBMM_EXCEPTIONS_ENABLED
+#endif //GLIBMM_VFUNCS_ENABLED
+
+  /** Virtual function to cleanup the thread pool.
+   */
+  _WRAP_VFUNC(void cleanup(), "cleanup")
+
+#ifdef GLIBMM_VFUNCS_ENABLED
+  /** Virtual function which starts a new thread.
+   * @throw Glib::Error.
+   */
+  #ifdef GLIBMM_EXCEPTIONS_ENABLED
+  virtual gpointer push_vfunc(const SlotPush& slot);
+  #else
+  virtual gpointer push_vfunc(const SlotPush& slot,
+    std::auto_ptr<Glib::Error>& error);
+  #endif //GLIBMM_EXCEPTIONS_ENABLED
+#endif //GLIBMM_VFUNCS_ENABLED
+
+  /** Virtual function to join a thread.
+   */
+  _WRAP_VFUNC(void join(gpointer id), "join")
+
+protected:
+#m4begin
+  _PUSH(SECTION_PCC_CLASS_INIT_VFUNCS)
+  klass->prepare = &prepare_vfunc_callback;
+  klass->push = &push_vfunc_callback;
+  _SECTION(SECTION_PH_VFUNCS)
+  static void prepare_vfunc_callback(GstTaskPool* self, GError** error);
+  static gpointer push_vfunc_callback(GstTaskPool* self,
+    GstTaskPoolFunction func, gpointer user_data, GError** error);
+  _POP()
+#m4end
 };
 
 } // namespace Gst



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