diff options
author | Daniel Elstner <danielk@openismus.com> | 2009-09-08 18:03:41 +0200 |
---|---|---|
committer | Daniel Elstner <danielk@openismus.com> | 2009-09-08 18:12:07 +0200 |
commit | a8154e320e5da74564c7f068baeea2c1ab03f949 (patch) | |
tree | 974eaf90fe16635d70dc4d144f2a656115bd8ce8 | |
parent | 9fb2a37f8989cdc965164052aecb095f66ddbebe (diff) | |
download | glibmm-a8154e320e5da74564c7f068baeea2c1ab03f949.tar.gz |
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>&.
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | gio/src/gio_vfuncs.defs | 11 | ||||
-rw-r--r-- | gio/src/initable.ccg | 25 | ||||
-rw-r--r-- | gio/src/initable.hg | 13 | ||||
-rw-r--r-- | gio/src/socket.ccg | 29 | ||||
-rw-r--r-- | gio/src/socket.hg | 15 | ||||
-rw-r--r-- | tools/m4/convert_gio.m4 | 1 |
7 files changed, 70 insertions, 37 deletions
@@ -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 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 <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 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>& 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 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>& 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 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>& 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 632bef47..a625bb55 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)') |