[glibmm] Add start of Initable



commit ea4e560cc94d53f3a129a333bcbafd9d5cd2cc6d
Author: Jonathon Jongsma <jonathon quotidian org>
Date:   Fri Jun 19 23:03:25 2009 -0500

    Add start of Initable

 .gitignore                              |    2 +
 ChangeLog                               |   14 ++++++
 gio/src/Makefile_list_of_hg.am_fragment |    1 +
 gio/src/initable.ccg                    |   45 ++++++++++++++++++++
 gio/src/initable.hg                     |   70 +++++++++++++++++++++++++++++++
 5 files changed, 132 insertions(+), 0 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 1c052cc..8be81df 100644
--- a/.gitignore
+++ b/.gitignore
@@ -114,6 +114,8 @@ gio/giomm/inetaddress.cc
 gio/giomm/inetaddress.h
 gio/giomm/inetsocketaddress.cc
 gio/giomm/inetsocketaddress.h
+gio/giomm/initable.cc
+gio/giomm/initable.h
 gio/giomm/inputstream.cc
 gio/giomm/inputstream.h
 gio/giomm/iostream.cc
diff --git a/ChangeLog b/ChangeLog
index 76adb18..0edc420 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2009-06-19  Jonathon Jongsma  <jonathon quotidian org>
 
+	Add start of Initable
+	This class may require a bit of additional thought since it implies
+	that we will need to call a special g_initable_new() constructor
+	that can fail with a GError rather than calling g_object_new()
+	directly.  Alternately, all classes that derive from Initable may
+	need to manually call init() in their constructors
+
+	* .gitignore:
+	* gio/src/Makefile_list_of_hg.am_fragment:
+	* gio/src/initable.ccg: Added
+	* gio/src/initable.hg: Added.
+
+2009-06-19  Jonathon Jongsma  <jonathon quotidian org>
+
 	Add NetworkService class
 
 	* .gitignore:
diff --git a/gio/src/Makefile_list_of_hg.am_fragment b/gio/src/Makefile_list_of_hg.am_fragment
index 9077783..a55792c 100644
--- a/gio/src/Makefile_list_of_hg.am_fragment
+++ b/gio/src/Makefile_list_of_hg.am_fragment
@@ -34,6 +34,7 @@ files_general_hg = \
                    icon.hg \
                    inetaddress.hg \
                    inetsocketaddress.hg \
+                   initable.hg \
                    inputstream.hg \
                    iostream.hg \
                    loadableicon.hg \
diff --git a/gio/src/initable.ccg b/gio/src/initable.ccg
new file mode 100644
index 0000000..2fd0087
--- /dev/null
+++ b/gio/src/initable.ccg
@@ -0,0 +1,45 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* Copyright (C) 2009 Jonathon Jongsma
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gio/gio.h>
+
+namespace Gio {
+  void
+  Initable::init(const Glib::RefPtr<Cancellable>& cancellable)
+  {
+      GError *error = 0;
+
+      g_initable_init (gobj (), cancellable->gobj (), &error);
+
+      if (error)
+          ::Glib::Error::throw_exception (error);
+  }
+
+  void
+  Initable::init()
+  {
+      GError *error = 0;
+
+      g_initable_init (gobj (), 0, &error);
+
+      if (error)
+          ::Glib::Error::throw_exception (error);
+  }
+
+} // namespace Gio
diff --git a/gio/src/initable.hg b/gio/src/initable.hg
new file mode 100644
index 0000000..0ac78d8
--- /dev/null
+++ b/gio/src/initable.hg
@@ -0,0 +1,70 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* Copyright (C) 2007 The giomm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <glibmm/interface.h>
+#include <giomm/cancellable.h>
+
+_DEFS(giomm,gio)
+_PINCLUDE(glibmm/private/interface_p.h)
+
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+typedef struct _GInitableIface GInitableIface;
+#endif /* DOXYGEN_SHOULD_SKIP_THIS */
+
+namespace Gio
+{
+
+/** Failable object initialization interface
+ *
+ * Initable is implemented by objects that can fail during initialization. If
+ * an object implements this interface the init() function must be called as the
+ * first thing after construction. If init() is not called, or if it returns an
+ * error, all further operations on the object should fail, generally with a
+ * G_IO_ERROR_NOT_INITIALIZED error.
+ *
+ * Users of objects implementing this are not intended to use the interface
+ * method directly, instead it will be used automatically in various ways. For C
+ * applications you generally just call g_initable_new() directly, or indirectly
+ * via a foo_thing_new() wrapper. This will call g_initable_init() under the
+ * cover, returning NULL and setting a GError on failure.
+ *
+ * For bindings in languages where the native constructor supports exceptions
+ * the binding could check for objects implemention GInitable during normal
+ * construction and automatically initialize them, throwing an exception on
+ * failure.
+ *
+ * @newin2p22
+ */
+class Initable : public Glib::Interface
+{
+  _CLASS_INTERFACE(Initable, GInitable, G_INITABLE, GInitableIface)
+
+public:
+  _WRAP_METHOD_DOCS_ONLY(g_initable_init)
+  void init(const Glib::RefPtr<Cancellable>& cancellable);
+  /** non-cancellable variant of init() */
+  void init();
+
+  // FIXME: this interface (and classes derived from it) really needs some
+  // additional thought for the binding since it seems to imply that we need to
+  // call g_initable_new() or g_derived_new() (which can fail with a GError)
+  // rather than calling g_object_new() like we usually do in gtkmm
+};
+
+} // namespace Gio



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