[glibmm] giomm: AsyncInitable: Wrap virtual functions.



commit d240f079614fe024047891f89d5625c50f110123
Author: José Alburquerque <jaalburqu svn gnome org>
Date:   Mon Aug 30 19:35:04 2010 -0400

    	giomm: AsyncInitable: Wrap virtual functions.
    
    	* gio/src/gio_vfuncs.defs: Add the GAsyncInitable virutal functions.
    	* gio/src/asyncinitable.{ccg,hg} (init_async_vfunc): Handwrite virtual
    	function because of the slot parameter.
    	(init_finish_vfunc): Likewise, because of the GError parameter.

 ChangeLog                 |    9 +++
 gio/src/asyncinitable.ccg |  136 +++++++++++++++++++++++++++++++++++++++++++++
 gio/src/asyncinitable.hg  |   23 ++++++++
 gio/src/gio_vfuncs.defs   |   22 +++++++
 4 files changed, 190 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e5d7a17..c82b425 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2010-08-30  José Alburquerque  <jaalburqu svn gnome org>
 
+	giomm: AsyncInitable: Wrap virtual functions.
+
+	* gio/src/gio_vfuncs.defs: Add the GAsyncInitable virutal functions.
+	* gio/src/asyncinitable.{ccg,hg} (init_async_vfunc): Handwrite virtual
+	function because of the slot parameter.
+	(init_finish_vfunc): Likewise, because of the GError parameter.
+
+2010-08-30  José Alburquerque  <jaalburqu svn gnome org>
+
 	AsyncInitable: Remove duplicate license blocks.
 
 	* gio/src/asyncinitable.hg:
diff --git a/gio/src/asyncinitable.ccg b/gio/src/asyncinitable.ccg
index 608868b..6b9de1e 100644
--- a/gio/src/asyncinitable.ccg
+++ b/gio/src/asyncinitable.ccg
@@ -47,4 +47,140 @@ void AsyncInitable::init_async(const SlotAsyncReady& slot, int io_priority)
     &SignalProxy_async_callback, slot_copy);
 }
 
+void AsyncInitable_Class::init_async_vfunc_callback(GAsyncInitable* self,
+  int io_priority, GCancellable* cancellable, GAsyncReadyCallback callback,
+  gpointer user_data)
+{
+  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.
+        // Get the slot.
+        Gio::SlotAsyncReady* the_slot =
+          static_cast<Gio::SlotAsyncReady*>(user_data);
+
+        obj->init_async_vfunc(*the_slot, Glib::wrap(cancellable), io_priority);
+        return;
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      }
+      catch(...)
+      {
+        Glib::exception_handlers_invoke();
+      }
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+    }
+  }
+  
+  BaseClassType *const base = static_cast<BaseClassType*>(
+      g_type_interface_peek_parent( // Get the parent interface of the interface (The original underlying C interface).
+g_type_interface_peek(G_OBJECT_GET_CLASS(self), CppObjectType::get_type()) // Get the interface.
+)  );
+
+  // Call the original underlying C function:
+  if(base && base->init_async)
+    (*base->init_async)(self, io_priority, cancellable, callback, user_data);
+
+}
+void Gio::AsyncInitable::init_async_vfunc(const SlotAsyncReady& slot,
+  const Glib::RefPtr<Cancellable>& cancellable, int io_priority)
+{
+  BaseClassType *const base = static_cast<BaseClassType*>(
+      g_type_interface_peek_parent( // Get the parent interface of the interface (The original underlying C interface).
+g_type_interface_peek(G_OBJECT_GET_CLASS(gobject_), CppObjectType::get_type()) // Get the interface.
+)  );
+
+  if(base && base->init_async)
+  {
+    // Create a copy of the slot.
+    // A pointer to it will be passed through the callback's data parameter
+    // and deleted in the callback.
+    SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
+
+    (*base->init_async)(gobj(), io_priority,
+      const_cast<GCancellable*>(Glib::unwrap(cancellable)),
+      &SignalProxy_async_callback, slot_copy);
+  }
+}
+gboolean AsyncInitable_Class::init_finish_vfunc_callback(GAsyncInitable* self, GAsyncResult* res, 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.
+        return static_cast<int>(obj->init_finish_vfunc(Glib::wrap(res, true)));
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      }
+      catch(...)
+      {
+        Glib::exception_handlers_invoke();
+      }
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+    }
+  }
+  
+  BaseClassType *const base = static_cast<BaseClassType*>(
+      g_type_interface_peek_parent( // Get the parent interface of the interface (The original underlying C interface).
+g_type_interface_peek(G_OBJECT_GET_CLASS(self), CppObjectType::get_type()) // Get the interface.
+)  );
+
+  // Call the original underlying C function:
+  if(base && base->init_finish)
+    return (*base->init_finish)(self, res, error);
+
+
+  typedef gboolean RType;
+  return RType();
+}
+bool Gio::AsyncInitable::init_finish_vfunc(const Glib::RefPtr<AsyncResult>& res) 
+{
+  BaseClassType *const base = static_cast<BaseClassType*>(
+      g_type_interface_peek_parent( // Get the parent interface of the interface (The original underlying C interface).
+g_type_interface_peek(G_OBJECT_GET_CLASS(gobject_), CppObjectType::get_type()) // Get the interface.
+)  );
+
+  if(base && base->init_finish)
+  {
+    GError* gerror = 0;
+
+    bool const result = (*base->init_finish)(gobj(), Glib::unwrap(res),
+      &gerror);
+
+    if(gerror)
+      ::Glib::Error::throw_exception(gerror);
+
+    return result;
+  }
+
+  typedef bool RType;
+  return RType();
+}
+
 } // namespace Gio
diff --git a/gio/src/asyncinitable.hg b/gio/src/asyncinitable.hg
index 04f1d51..f6d96b9 100644
--- a/gio/src/asyncinitable.hg
+++ b/gio/src/asyncinitable.hg
@@ -22,6 +22,7 @@
 
 _DEFS(giomm,gio)
 _PINCLUDE(glibmm/private/interface_p.h)
+_PINCLUDE(gio/gio.h)
 
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
 typedef struct _GAsyncInitableIface GAsyncInitableIface;
@@ -125,6 +126,28 @@ protected:
     int io_priority = Glib::PRIORITY_DEFAULT);
 
   _WRAP_METHOD(bool init_finish(const Glib::RefPtr<AsyncResult>& result), g_async_initable_init_finish, errthrow)
+
+  virtual void init_async_vfunc(const SlotAsyncReady& slot,
+    const Glib::RefPtr<Cancellable>& cancellable,
+    int io_priority = Glib::PRIORITY_DEFAULT);
+
+  /** @throw Glib::Errror.
+   */
+    virtual bool init_finish_vfunc(const Glib::RefPtr<AsyncResult>& res);
+  
+protected:
+#m4begin
+  _PUSH(SECTION_PCC_CLASS_INIT_VFUNCS)
+  klass->init_async = &init_async_vfunc_callback;
+  klass->init_finish = &init_finish_vfunc_callback;
+  _SECTION(SECTION_PH_VFUNCS)
+  static void init_async_vfunc_callback(GAsyncInitable* self,
+    int io_priority, GCancellable* cancellable, GAsyncReadyCallback callback,
+    gpointer user_data);
+  static gboolean init_finish_vfunc_callback(GAsyncInitable* self,
+    GAsyncResult* res, GError** error);
+  _POP()
+#m4end
 };
 
 } // namespace Gio
diff --git a/gio/src/gio_vfuncs.defs b/gio/src/gio_vfuncs.defs
index a29e2b6..c4547fd 100644
--- a/gio/src/gio_vfuncs.defs
+++ b/gio/src/gio_vfuncs.defs
@@ -3,6 +3,28 @@
 ; define-vfunc is g*mm-specific
 ; These are hand-written.
 
+; GAsyncInitable
+
+(define-vfunc init_async
+  (of-object "GAsyncInitable")
+  (return-type "void")
+  (parameters
+   '("int" "io_priority")
+   '("GCancellable*" "cancellable")
+   '("GAsyncReadyCallback" "callback")
+   '("gpointer" "user_data")
+  )
+)
+
+(define-vfunc init_finish
+  (of-object "GAsyncInitable")
+  (return-type "gboolean")
+  (parameters
+   '("GAsyncResult*" "res")
+   '("GError**" "error")
+  )
+)
+
 ; GAsyncResult
 
 (define-vfunc get_source_object



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