[glibmm] AsyncResult: Add get_source_object_base(), deprecating get_source_object().



commit 1af070ad51f63ebe34dec81b3d19b26b6464ebfd
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Jan 28 10:08:51 2010 +0100

    AsyncResult: Add get_source_object_base(), deprecating get_source_object().
    
    * gio/asyncresult.[hg|ccg]: Deprecate get_source_object(), replacing it
    with get_source_object_base(), because in giomm, the C++ wrapper object
    might be a Glib::Interface, but not a Glib::Object (though the underlying
    C instance must be a GObject). This happens if giomm does not know about
    the GType of the underlying C Object, which is a legitimate situation.
    * tests/giomm_asyncresult_sourceobject/main.cc: Added this test case
    from Michael Hasselmann, from bug #608269.

 ChangeLog                                    |   12 ++++++++++
 gio/src/asyncresult.ccg                      |   23 +++++++++++++++++++
 gio/src/asyncresult.hg                       |   15 ++++++++++--
 tests/Makefile.am                            |    7 +++++-
 tests/giomm_asyncresult_sourceobject/main.cc |   30 ++++++++++++++++++++++++++
 tools/m4/convert_gio.m4                      |    1 +
 tools/m4/convert_glib.m4                     |    3 ++
 7 files changed, 87 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a1069ca..b3fa32d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2010-01-28  Murray Cumming  <murrayc murrayc com>
+
+	AsyncResult: Add get_source_object_base(), deprecating get_source_object().
+
+	* gio/asyncresult.[hg|ccg]: Deprecate get_source_object(), replacing it
+	with get_source_object_base(), because in giomm, the C++ wrapper object
+	might be a Glib::Interface, but not a Glib::Object (though the underlying
+	C instance must be a GObject). This happens if giomm does not know about
+	the GType of the underlying C Object, which is a legitimate situation.
+	* tests/giomm_asyncresult_sourceobject/main.cc: Added this test case
+	from Michael Hasselmann, from bug #608269.
+
 2010-03-08  Murray Cumming  <murrayc murrayc com>
 
     Regenerated more .defs.
diff --git a/gio/src/asyncresult.ccg b/gio/src/asyncresult.ccg
index 9f547c9..0094868 100644
--- a/gio/src/asyncresult.ccg
+++ b/gio/src/asyncresult.ccg
@@ -19,3 +19,26 @@
 
 //#include <gio/gasyncresult.h> //We are not allowed to include individual headers.
 #include <gio/gio.h>
+
+namespace Gio
+{
+
+static GObject* unwrap_objectbase_custom(const Glib::RefPtr<Glib::ObjectBase>& cpp_instance)
+{
+  return (cpp_instance ? cpp_instance->gobj() : 0);
+}
+
+Glib::RefPtr<Glib::ObjectBase> AsyncResult::get_source_object_base()
+{
+  GObject* cobj = g_async_result_get_source_object(gobj());
+  ObjectBase* cppobj = Glib::wrap_auto(cobj); //ObjectBase::_get_current_wrapper(cobj);
+  return Glib::RefPtr<Glib::ObjectBase>(cppobj); //g_async_result_get_source_object() gives us a ref, unusually.
+  //TODO: For some reason this fails: Glib::wrap(cobj);
+}
+
+Glib::RefPtr<const Glib::ObjectBase> AsyncResult::get_source_object_base() const
+{
+  return const_cast<AsyncResult*>(this)->get_source_object_base();
+}
+
+} //namespace Gio
diff --git a/gio/src/asyncresult.hg b/gio/src/asyncresult.hg
index efc882e..fa1a809 100644
--- a/gio/src/asyncresult.hg
+++ b/gio/src/asyncresult.hg
@@ -110,11 +110,20 @@ public:
   //Note that this returns a reference, unlike most GTK+ get_*() functions,
   //so we don't need to use refreturn.
   _WRAP_METHOD(Glib::RefPtr<Glib::Object> get_source_object(),
-               g_async_result_get_source_object)
+               g_async_result_get_source_object, deprecated "Use get_source_object_base()")
   _WRAP_METHOD(Glib::RefPtr<const Glib::Object> get_source_object() const,
-               g_async_result_get_source_object, constversion)
+               g_async_result_get_source_object, constversion, deprecated "Use get_source_object_base()")
 
-  _WRAP_VFUNC(Glib::RefPtr<Glib::Object> get_source_object(),
+  //Note that this returns a reference, unlike most GTK+ get_*() functions,
+  //so we don't need to use refreturn.
+  Glib::RefPtr<Glib::ObjectBase> get_source_object_base();
+  Glib::RefPtr<const Glib::ObjectBase> get_source_object_base() const;
+
+
+  // TODO: For some reason, the compiler cannot find an unwrap() for ObjectBase.
+  //#m4 _CONVERSION(`Glib::RefPtr<Glib::ObjectBase>',`GObject*',__CONVERT_REFPTR_TO_P)
+#m4 _CONVERSION(`Glib::RefPtr<Glib::ObjectBase>',`GObject*',`unwrap_objectbase_custom($3)')
+  _WRAP_VFUNC(Glib::RefPtr<Glib::ObjectBase> get_source_object(),
               "get_source_object")
 };
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index af6ccb2..fb090d3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -20,12 +20,13 @@ AUTOMAKE_OPTIONS = subdir-objects
 check_PROGRAMS =			\
 	giomm_ioerror/test		\
 	giomm_simple/test		\
+	giomm_asyncresult_sourceobject/test \
 	glibmm_btree/test		\
 	glibmm_date/test		\
 	glibmm_nodetree/test		\
 	glibmm_ustring_compose/test	\
 	glibmm_value/test		\
-	glibmm_valuearray/test
+	glibmm_valuearray/test		
 
 glibmm_includes = -I$(top_builddir)/glib $(if $(srcdir:.=),-I$(top_srcdir)/glib)
 giomm_includes  = -I$(top_builddir)/gio $(if $(srcdir:.=),-I$(top_srcdir)/gio)
@@ -42,9 +43,13 @@ giomm_ldadd = $(GIOMM_LIBS) $(local_libglibmm) $(local_libgiomm)
 
 giomm_ioerror_test_SOURCES = giomm_ioerror/main.cc
 giomm_ioerror_test_LDADD   = $(giomm_ldadd)
+
 giomm_simple_test_SOURCES  = giomm_simple/main.cc
 giomm_simple_test_LDADD    = $(giomm_ldadd)
 
+giomm_asyncresult_sourceobject_test_SOURCES  = giomm_asyncresult_sourceobject/main.cc
+giomm_asyncresult_sourceobject_test_LDADD    = $(giomm_ldadd)
+
 glibmm_btree_test_SOURCES           = glibmm_btree/main.cc
 glibmm_date_test_SOURCES            = glibmm_date/main.cc
 glibmm_nodetree_test_SOURCES        = glibmm_nodetree/main.cc
diff --git a/tests/giomm_asyncresult_sourceobject/main.cc b/tests/giomm_asyncresult_sourceobject/main.cc
new file mode 100644
index 0000000..1c9f1a1
--- /dev/null
+++ b/tests/giomm_asyncresult_sourceobject/main.cc
@@ -0,0 +1,30 @@
+#include <giomm.h>
+#include <iostream>
+
+void on_read_async(const Glib::RefPtr<Gio::AsyncResult>& result)
+{
+  std::cout << "Testing result ... "
+            << (result ? "OK!" : "FAILED!") << std::endl;
+
+  std::cout << "Testing get_source_object from gobj() ... "
+            << (g_async_result_get_source_object(result->gobj()) ? "OK!" : "FAILED!") << std::endl;
+
+  std::cout << "Testing Gio::AsyncResult's get_source_object ... "
+            << (result->get_source_object_base() ? "OK!" : "FAILED!") << std::endl;
+
+  exit(EXIT_SUCCESS);
+}
+
+int main(int, char**)
+{
+  Glib::init();
+  Gio::init();
+
+  Glib::RefPtr<Glib::MainLoop> mainloop = Glib::MainLoop::create();
+
+  Glib::RefPtr<Gio::File> file = Gio::File::create_for_path("/etc/passwd");
+  file->read_async(&on_read_async);
+
+  mainloop->run();
+  return 0;
+}
diff --git a/tools/m4/convert_gio.m4 b/tools/m4/convert_gio.m4
index 39547c1..d2f1f9a 100644
--- a/tools/m4/convert_gio.m4
+++ b/tools/m4/convert_gio.m4
@@ -36,6 +36,7 @@ _CONVERSION(`const Glib::ListHandle< Glib::RefPtr<Gio::File> >&',`GList*',`$3.da
 
 # AsyncResult
 _CONVERSION(`Glib::RefPtr<Glib::Object>',`GObject*',__CONVERT_REFPTR_TO_P)
+
 _CONVERSION(`const Glib::RefPtr<AsyncResult>&',`GAsyncResult*',__CONVERT_REFPTR_TO_P)
 _CONVERSION(`Glib::RefPtr<AsyncResult>&',`GAsyncResult*',__CONVERT_REFPTR_TO_P)
 
diff --git a/tools/m4/convert_glib.m4 b/tools/m4/convert_glib.m4
index 80cb2cc..5bde0bb 100644
--- a/tools/m4/convert_glib.m4
+++ b/tools/m4/convert_glib.m4
@@ -63,6 +63,9 @@ _CONVERSION(`const Glib::RefPtr<const Glib::Object>&',`GObject*',__CONVERT_CONST
 _CONVERSION(`GObject*',`Glib::RefPtr<Glib::Object>',`Glib::wrap($3)')
 _CONVERSION(`GObject*',`Glib::RefPtr<const Glib::Object>',`Glib::wrap($3)')
 
+_CONVERSION(`GObject*',`Glib::RefPtr<Glib::ObjectBase>',`Glib::wrap($3)')
+_CONVERSION(`GObject*',`Glib::RefPtr<const Glib::ObjectBase>',`Glib::wrap($3)')
+
 _CONVERSION(`GRegex*',`Glib::RefPtr<Regex>',`Glib::wrap($3)')
 _CONVERSION(`GRegex*',`Glib::RefPtr<const Regex>',`Glib::wrap($3)')
 



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