[glibmm] giomm: Add AsyncInitable interface.



commit 6b8ff1bb705a3721fcc16b4e412b22a16d4003ad
Author: José Alburquerque <jaalburqu svn gnome org>
Date:   Fri Aug 27 17:36:16 2010 -0400

    	giomm: Add AsyncInitable interface.
    
    	* gio/src/asyncinitable.ccg:
    	* gio/src/asyncinitable.hg: Add source files for AsyncInitable
    	interface.
    	* gio/src/filelist.am: Mention the asyncinitable.hg file so the
    	sources are built.
    	* gio/src/dbusconnection.hg: Have DBusConnection derive from the
    	AsyncInitable interface also.

 ChangeLog                 |   12 ++++
 gio/src/asyncinitable.ccg |   50 ++++++++++++++
 gio/src/asyncinitable.hg  |  162 +++++++++++++++++++++++++++++++++++++++++++++
 gio/src/dbusconnection.hg |    4 +-
 gio/src/filelist.am       |    1 +
 5 files changed, 228 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6a39949..4efe94c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2010-08-30  José Alburquerque  <jaalburqu svn gnome org>
+
+	giomm: Add AsyncInitable interface.
+
+	* gio/src/asyncinitable.ccg:
+	* gio/src/asyncinitable.hg: Add source files for AsyncInitable
+	interface.
+	* gio/src/filelist.am: Mention the asyncinitable.hg file so the
+	sources are built.
+	* gio/src/dbusconnection.hg: Have DBusConnection derive from the
+	AsyncInitable interface also.
+
 2010-08-27  José Alburquerque  <jaalburqu svn gnome org>
 
 	giomm: DBusConnection: Wrap synchronous new functions.
diff --git a/gio/src/asyncinitable.ccg b/gio/src/asyncinitable.ccg
new file mode 100644
index 0000000..608868b
--- /dev/null
+++ b/gio/src/asyncinitable.ccg
@@ -0,0 +1,50 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* Copyright (C) 2010 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 <gio/gio.h>
+#include <giomm/cancellable.h>
+#include "slot_async.h"
+
+namespace Gio
+{
+
+void AsyncInitable::init_async(const SlotAsyncReady& slot,
+  const Glib::RefPtr<Cancellable>& cancellable, int io_priority)
+{
+  // 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);
+
+  g_async_initable_init_async(gobj(), io_priority, Glib::unwrap(cancellable),
+    &SignalProxy_async_callback, slot_copy);
+}
+
+void AsyncInitable::init_async(const SlotAsyncReady& slot, int io_priority)
+{
+  // 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);
+
+  g_async_initable_init_async(gobj(), io_priority, 0,
+    &SignalProxy_async_callback, slot_copy);
+}
+
+} // namespace Gio
diff --git a/gio/src/asyncinitable.hg b/gio/src/asyncinitable.hg
new file mode 100644
index 0000000..6bc35c3
--- /dev/null
+++ b/gio/src/asyncinitable.hg
@@ -0,0 +1,162 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* Copyright (C) 2010 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.
+ */
+/* Copyright (C) 2010 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.
+ */
+/* Copyright (C) 2010 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/asyncresult.h>
+
+_DEFS(giomm,gio)
+_PINCLUDE(glibmm/private/interface_p.h)
+
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+typedef struct _GAsyncInitableIface GAsyncInitableIface;
+#endif /* DOXYGEN_SHOULD_SKIP_THIS */
+
+namespace Gio
+{
+
+class Cancellable;
+
+/** AsyncInitable - Asynchronously failable object initialization interface.
+ * This is the asynchronous version of Initable; it behaves the same in all
+ * ways except that initialization is asynchronous. For more details see the
+ * descriptions on Initable.
+ *
+ * A class may implement both the Initable and AsyncInitable interfaces.
+ *
+ * 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_async_initable_new_async()
+ * directly, or indirectly via a foo_thing_new_async() wrapper. This will call
+ * g_async_initable_init_async() under the cover, calling back with NULL and a
+ * set GError on failure. 
+ */
+class AsyncInitable : public Glib::Interface
+{
+  _CLASS_INTERFACE(AsyncInitable, GAsyncInitable, G_ASYNC_INITABLE, GAsyncInitableIface)
+
+protected:
+  /** Starts asynchronous initialization of the object implementing the
+   * interface. This must be done before any real use of the object after
+   * initial construction. If the object also implements Initable you can
+   * optionally call Gio::Initable::init() instead.
+   *
+   * When the initialization is finished, @a slot will be called. You can
+   * then call init_finish() to get the result of the initialization.
+   *
+   * Implementations may also support cancellation. Initialization can be
+   * cancelled by triggering the @a cancellable object from another thread. If
+   * the operation was cancelled, the error Gio::IO_ERROR_CANCELLED will be
+   * returned. If the object doesn't support cancellable initialization, the
+   * error Gio::IO_ERROR_NOT_SUPPORTED will be returned.
+   *
+   * If this function is not called, or returns with an error, then all
+   * operations on the object should fail, generally returning the error
+   * Gio::IO_ERROR_NOT_INITIALIZED.
+   *
+   * Implementations of this method must be idempotent: i.e. multiple calls to
+   * this function with the same argument should return the same results. Only
+   * the first call initializes the object; further calls return the result of
+   * the first call. This is so that it's safe to implement the singleton
+   * pattern in the GObject constructor function.
+   *
+   * For classes that also support the Initable interface, the default
+   * implementation of this method will run the Gio::Initable::init() method
+   * in a thread, so if you want to support asynchronous initialization via
+   * threads, just implement the AsyncInitable interface without overriding
+   * any interface methods.
+   *
+   * @param io_priority The I/O priority of the operation.
+   * @param cancellable Cancellable object to make cancellation possible.
+   * @param slot a SlotAsyncReady to call when the request is satisfied.
+   *
+   * @newin{2,22}
+   */
+  void init_async(const SlotAsyncReady& slot,
+    const Glib::RefPtr<Cancellable>& cancellable,
+    int io_priority = Glib::PRIORITY_DEFAULT);
+  _IGNORE(g_async_initable_init_async)
+
+  /** Starts asynchronous initialization of the object implementing the
+   * interface. This must be done before any real use of the object after
+   * initial construction. If the object also implements Initable you can
+   * optionally call Gio::Initable::init() instead.
+   *
+   * When the initialization is finished, @a slot will be called. You can
+   * then call init_finish() to get the result of the initialization.
+   *
+   * If this function is not called, or returns with an error, then all
+   * operations on the object should fail, generally returning the error
+   * Gio::IO_ERROR_NOT_INITIALIZED.
+   *
+   * Implementations of this method must be idempotent: i.e. multiple calls to
+   * this function with the same argument should return the same results. Only
+   * the first call initializes the object; further calls return the result of
+   * the first call. This is so that it's safe to implement the singleton
+   * pattern in the GObject constructor function.
+   *
+   * For classes that also support the Initable interface, the default
+   * implementation of this method will run the Gio::Initable::init() method
+   * in a thread, so if you want to support asynchronous initialization via
+   * threads, just implement the AsyncInitable interface without overriding
+   * any interface methods.
+   *
+   * @param io_priority The I/O priority of the operation.
+   * @param slot a SlotAsyncReady to call when the request is satisfied.
+   *
+   * @newin{2,22}
+   */
+  void init_async(const SlotAsyncReady& slot,
+    int io_priority = Glib::PRIORITY_DEFAULT);
+
+  _WRAP_METHOD(bool init_finish(const Glib::RefPtr<AsyncResult>& result), g_async_initable_init_finish, errthrow)
+};
+
+} // namespace Gio
diff --git a/gio/src/dbusconnection.hg b/gio/src/dbusconnection.hg
index 3202163..f08b6d0 100644
--- a/gio/src/dbusconnection.hg
+++ b/gio/src/dbusconnection.hg
@@ -19,6 +19,7 @@
 
 #include <glibmm/object.h>
 #include <giomm/initable.h>
+#include <giomm/asyncinitable.h>
 #include <giomm/iostream.h>
 #include <giomm/asyncresult.h>
 #include <giomm/credentials.h>
@@ -51,7 +52,8 @@ class DBusAuthObserver;
  *
  * @newin{2,26}
  */
-class DBusConnection : public Glib::Object, public Initable
+class DBusConnection
+: public Glib::Object, public Initable, public AsyncInitable
 {
 protected:
   _CLASS_GOBJECT(DBusConnection, GDBusConnection, G_DBUS_CONNECTION, Glib::Object, GObject)
diff --git a/gio/src/filelist.am b/gio/src/filelist.am
index d385e9a..74819ef 100644
--- a/gio/src/filelist.am
+++ b/gio/src/filelist.am
@@ -14,6 +14,7 @@ giomm_files_defs =			\
 giomm_files_any_hg =			\
 	appinfo.hg			\
 	application.hg			\
+	asyncinitable.hg		\
 	asyncresult.hg			\
 	bufferedinputstream.hg		\
 	bufferedoutputstream.hg		\



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