[glibmm] Implement Gio::Socket ctors using Gio::Initable



commit a8154e320e5da74564c7f068baeea2c1ab03f949
Author: Daniel Elstner <danielk openismus com>
Date:   Tue Sep 8 18:03:41 2009 +0200

    Implement Gio::Socket ctors using Gio::Initable
    
    * gio/src/gio_vfuncs.defs: Add GInitableClass::init() vfunc.
    * gio/src/initable.{ccg,hg} (Initable::init): Use _WRAP_METHOD().
    (Initable::init_vfunc): Wrap GInitableClass::init() vfunc.
    * gio/src/socket.{ccg,hg} (Socket::Socket): Wrap constructors
    manually.  Call Initable::init() from the constructor body.
    (Socket::create), (Socket::create_from_fd): Forward to constructors.
    * tools/m4/convert_gio.m4: Add conversion from GCancellable* to
    const Glib::RefPtr<Cancellable>&.

 ChangeLog               |   13 +++++++++++++
 gio/src/gio_vfuncs.defs |   11 +++++++++++
 gio/src/initable.ccg    |   25 -------------------------
 gio/src/initable.hg     |   13 ++++---------
 gio/src/socket.ccg      |   29 +++++++++++++++++++++++++++++
 gio/src/socket.hg       |   15 ++++++++++++---
 tools/m4/convert_gio.m4 |    1 +
 7 files changed, 70 insertions(+), 37 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7909138..dd815c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2009-09-08  Daniel Elstner  <danielk openismus com>
+
+	Implement Gio::Socket ctors using Gio::Initable
+
+	* gio/src/gio_vfuncs.defs: Add GInitableClass::init() vfunc.
+	* gio/src/initable.{ccg,hg} (Initable::init): Use _WRAP_METHOD().
+	(Initable::init_vfunc): Wrap GInitableClass::init() vfunc.
+	* gio/src/socket.{ccg,hg} (Socket::Socket): Wrap constructors
+	manually.  Call Initable::init() from the constructor body.
+	(Socket::create), (Socket::create_from_fd): Forward to constructors.
+	* tools/m4/convert_gio.m4: Add conversion from GCancellable* to
+	const Glib::RefPtr<Cancellable>&.
+
 2009-09-07  Daniel Elstner  <danielk openismus com>
 
 	Officially deprecate GLIBMM_CHECK_PERL macro
diff --git a/gio/src/gio_vfuncs.defs b/gio/src/gio_vfuncs.defs
index c7ff5a4..d295c10 100644
--- a/gio/src/gio_vfuncs.defs
+++ b/gio/src/gio_vfuncs.defs
@@ -127,6 +127,17 @@
   (return-type "guint")
 )
 
+; GInitable
+
+(define-vfunc init
+  (of-object "GInitable")
+  (return-type "gboolean")
+  (parameters
+    '("GCancellable*" "cancellable")
+    '("GError**" "error")
+  )
+)
+
 ; GLoadableIcon
 
 (define-vfunc load
diff --git a/gio/src/initable.ccg b/gio/src/initable.ccg
index 2fd0087..7140b0f 100644
--- a/gio/src/initable.ccg
+++ b/gio/src/initable.ccg
@@ -18,28 +18,3 @@
  */
 
 #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
index 0cddf6a..1bcd48d 100644
--- a/gio/src/initable.hg
+++ b/gio/src/initable.hg
@@ -55,16 +55,11 @@ 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();
+protected:
+  _WRAP_METHOD(void init(const Glib::RefPtr<Cancellable>& cancellable),
+               g_initable_init, errthrow)
 
-  // 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
+  _WRAP_VFUNC(bool init(const Glib::RefPtr<Cancellable>& cancellable, GError** error), "init")
 };
 
 } // namespace Gio
diff --git a/gio/src/socket.ccg b/gio/src/socket.ccg
index 1850a92..2a95002 100644
--- a/gio/src/socket.ccg
+++ b/gio/src/socket.ccg
@@ -24,6 +24,35 @@
 namespace Gio
 {
 
+Socket::Socket(SocketFamily family, SocketType type, SocketProtocol protocol,
+               const Glib::RefPtr<Cancellable>& cancellable)
+:
+  _CONSTRUCT("family", int(family), "type", int(type), "protocol", int(protocol))
+{
+  init(cancellable);
+}
+
+Socket::Socket(int fd, const Glib::RefPtr<Cancellable>& cancellable)
+:
+  _CONSTRUCT("fd", fd)
+{
+  init(cancellable);
+}
+
+// static
+Glib::RefPtr<Socket> Socket::create(SocketFamily family, SocketType type, SocketProtocol protocol,
+                                    const Glib::RefPtr<Cancellable>& cancellable)
+{
+  return Glib::RefPtr<Socket>(new Socket(family, type, protocol, cancellable));
+}
+
+// static
+Glib::RefPtr<Socket> Socket::create_from_fd(int fd, const Glib::RefPtr<Cancellable>& cancellable)
+{
+  return Glib::RefPtr<Socket>(new Socket(fd, cancellable));
+}
+
+
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
 void Socket::connect(const Glib::RefPtr<SocketAddress>& address)
 #else
diff --git a/gio/src/socket.hg b/gio/src/socket.hg
index 0e3b219..63ef000 100644
--- a/gio/src/socket.hg
+++ b/gio/src/socket.hg
@@ -83,15 +83,24 @@ _WRAP_ENUM(SocketMsgFlags, GSocketMsgFlags)
  *
  * @newin{2,22}
  */
-class Socket : public Glib::Object,
-    public Initable
+class Socket : public Glib::Object, public Initable
 {
   _CLASS_GOBJECT(Socket, GSocket, G_SOCKET, Glib::Object, GObject)
   _IMPLEMENTS_INTERFACE(Initable)
 
-  // FIXME: figure out initable constructors
+protected:
+  Socket(SocketFamily family, SocketType type, SocketProtocol protocol,
+         const Glib::RefPtr<Cancellable>& cancellable);
+  Socket(int fd, const Glib::RefPtr<Cancellable>& cancellable);
 
 public:
+  _WRAP_METHOD_DOCS_ONLY(g_socket_new)
+  static Glib::RefPtr<Socket>
+  create(SocketFamily family, SocketType type, SocketProtocol protocol,
+         const Glib::RefPtr<Cancellable>& cancellable = Glib::RefPtr<Cancellable>());
+  _WRAP_METHOD_DOCS_ONLY(g_socket_new_from_fd)
+  static Glib::RefPtr<Socket> create_from_fd(int fd, const Glib::RefPtr<Cancellable>&
+                                             cancellable = Glib::RefPtr<Cancellable>());
 
   _WRAP_METHOD(void bind(const Glib::RefPtr<SocketAddress>& address, bool allow_reuse), g_socket_bind, errthrow)
   _WRAP_METHOD(void listen(), g_socket_listen, errthrow)
diff --git a/tools/m4/convert_gio.m4 b/tools/m4/convert_gio.m4
index 632bef4..a625bb5 100644
--- a/tools/m4/convert_gio.m4
+++ b/tools/m4/convert_gio.m4
@@ -43,6 +43,7 @@ _CONVERSION(`Glib::RefPtr<AsyncResult>&',`GAsyncResult*',__CONVERT_REFPTR_TO_P)
 _CONVERSION(`const Glib::RefPtr<Cancellable>&',`GCancellable*',__CONVERT_CONST_REFPTR_TO_P)
 _CONVERSION(`const Glib::RefPtr<Gio::Cancellable>&',`GCancellable*',__CONVERT_CONST_REFPTR_TO_P)
 _CONVERSION(`GCancellable*', `Glib::RefPtr<Cancellable>', `Glib::wrap($3)')
+_CONVERSION(`GCancellable*', `const Glib::RefPtr<Cancellable>&', `Glib::wrap($3)')
 
 # DesktopAppInfo
 _CONVERSION(`GDesktopAppInfo*', `Glib::RefPtr<DesktopAppInfo>', `Glib::wrap($3)')



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