From a8154e320e5da74564c7f068baeea2c1ab03f949 Mon Sep 17 00:00:00 2001 From: Daniel Elstner Date: Tue, 8 Sep 2009 18:03:41 +0200 Subject: 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&. --- 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 79091388..dd815c4e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2009-09-08 Daniel Elstner + + 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&. + 2009-09-07 Daniel Elstner Officially deprecate GLIBMM_CHECK_PERL macro diff --git a/gio/src/gio_vfuncs.defs b/gio/src/gio_vfuncs.defs index c7ff5a4a..d295c10b 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 2fd00874..7140b0f2 100644 --- a/gio/src/initable.ccg +++ b/gio/src/initable.ccg @@ -18,28 +18,3 @@ */ #include - -namespace Gio { - void - Initable::init(const Glib::RefPtr& 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 0cddf6ab..1bcd48d6 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); - /** non-cancellable variant of init() */ - void init(); +protected: + _WRAP_METHOD(void init(const Glib::RefPtr& 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, GError** error), "init") }; } // namespace Gio diff --git a/gio/src/socket.ccg b/gio/src/socket.ccg index 1850a92e..2a950027 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) +: + _CONSTRUCT("family", int(family), "type", int(type), "protocol", int(protocol)) +{ + init(cancellable); +} + +Socket::Socket(int fd, const Glib::RefPtr& cancellable) +: + _CONSTRUCT("fd", fd) +{ + init(cancellable); +} + +// static +Glib::RefPtr Socket::create(SocketFamily family, SocketType type, SocketProtocol protocol, + const Glib::RefPtr& cancellable) +{ + return Glib::RefPtr(new Socket(family, type, protocol, cancellable)); +} + +// static +Glib::RefPtr Socket::create_from_fd(int fd, const Glib::RefPtr& cancellable) +{ + return Glib::RefPtr(new Socket(fd, cancellable)); +} + + #ifdef GLIBMM_EXCEPTIONS_ENABLED void Socket::connect(const Glib::RefPtr& address) #else diff --git a/gio/src/socket.hg b/gio/src/socket.hg index 0e3b2199..63ef0001 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); + Socket(int fd, const Glib::RefPtr& cancellable); public: + _WRAP_METHOD_DOCS_ONLY(g_socket_new) + static Glib::RefPtr + create(SocketFamily family, SocketType type, SocketProtocol protocol, + const Glib::RefPtr& cancellable = Glib::RefPtr()); + _WRAP_METHOD_DOCS_ONLY(g_socket_new_from_fd) + static Glib::RefPtr create_from_fd(int fd, const Glib::RefPtr& + cancellable = Glib::RefPtr()); _WRAP_METHOD(void bind(const Glib::RefPtr& 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 632bef47..a625bb55 100644 --- a/tools/m4/convert_gio.m4 +++ b/tools/m4/convert_gio.m4 @@ -43,6 +43,7 @@ _CONVERSION(`Glib::RefPtr&',`GAsyncResult*',__CONVERT_REFPTR_TO_P) _CONVERSION(`const Glib::RefPtr&',`GCancellable*',__CONVERT_CONST_REFPTR_TO_P) _CONVERSION(`const Glib::RefPtr&',`GCancellable*',__CONVERT_CONST_REFPTR_TO_P) _CONVERSION(`GCancellable*', `Glib::RefPtr', `Glib::wrap($3)') +_CONVERSION(`GCancellable*', `const Glib::RefPtr&', `Glib::wrap($3)') # DesktopAppInfo _CONVERSION(`GDesktopAppInfo*', `Glib::RefPtr', `Glib::wrap($3)') -- cgit v1.2.1