diff options
author | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2020-08-12 12:52:31 +0200 |
---|---|---|
committer | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2020-08-12 12:52:31 +0200 |
commit | 2da4503d039da6a12cbd61cbbfea0af4ba572229 (patch) | |
tree | 1b5b9b34418ae73b1efcb0eb1a6ead58c956f582 /gio/src | |
parent | bb806ba91b7c8ae08b721826996d877b748200b2 (diff) | |
download | glibmm-2da4503d039da6a12cbd61cbbfea0af4ba572229.tar.gz |
Rewrite Gio::Tls[Client,Server]ConnectionImpl
TlsConnection_Class::wrap_new() can wrap a C object in a TlsConnection,
TlsClientConnectionImpl or TlsServerConnectionImpl depending on which
interface, if any, the C object implements.
No need for special wrap*() functions in Tls[Client,Server]Connection
or SocketClient::signal_event().
This is similar to Gdk::DeviceWithPad.
Diffstat (limited to 'gio/src')
-rw-r--r-- | gio/src/socketclient.ccg | 19 | ||||
-rw-r--r-- | gio/src/socketclient.hg | 2 | ||||
-rw-r--r-- | gio/src/tlsclientconnection.hg | 2 | ||||
-rw-r--r-- | gio/src/tlsconnection.ccg | 19 | ||||
-rw-r--r-- | gio/src/tlsconnection.hg | 1 | ||||
-rw-r--r-- | gio/src/tlsserverconnection.hg | 2 |
6 files changed, 23 insertions, 22 deletions
diff --git a/gio/src/socketclient.ccg b/gio/src/socketclient.ccg index 52658d62..8339f12d 100644 --- a/gio/src/socketclient.ccg +++ b/gio/src/socketclient.ccg @@ -15,28 +15,9 @@ */ #include <gio/gio.h> -#include <giomm/tlsclientconnectionimpl.h> #include <giomm/asyncresult.h> #include "slot_async.h" -namespace -{ -// Wrap the GIOStream* connection in the 'event' signal. -// The GIOStream pointer, if not a nullptr, can point to either a GSocketConnection -// or to a subclass of GTlsConnection that implements the GTlsClientConnection interface. -Glib::RefPtr<Gio::IOStream> SocketClient_signal_event_wrap_connection(GIOStream* object, bool take_copy) -{ - if (!Glib::ObjectBase::_get_current_wrapper((GObject*)object) && - G_IS_TLS_CLIENT_CONNECTION(object)) - // An instance of a class that implements GTlsClientConnection. - // It doesn't have a wrapper. Wrap it in a Gio::TlsClientConnectionImpl. - return Glib::wrap_tls_client_connection_impl(G_TLS_CONNECTION(object), take_copy); - - return Glib::wrap(object, take_copy); -} - -} // anonymous namespace - namespace Gio { diff --git a/gio/src/socketclient.hg b/gio/src/socketclient.hg index b0a5d898..ab1ba680 100644 --- a/gio/src/socketclient.hg +++ b/gio/src/socketclient.hg @@ -167,7 +167,7 @@ public: _WRAP_PROPERTY("proxy-resolver", Glib::RefPtr<ProxyResolver>) #m4 _CONVERSION(`GSocketConnectable*',`const Glib::RefPtr<SocketConnectable>&',`Glib::wrap($3, true)') -#m4 _CONVERSION(`GIOStream*',`const Glib::RefPtr<IOStream>&',`SocketClient_signal_event_wrap_connection($3, true)') +#m4 _CONVERSION(`GIOStream*',`const Glib::RefPtr<IOStream>&',`Glib::wrap($3, true)') _WRAP_SIGNAL(void event(SocketClientEvent event, const Glib::RefPtr<SocketConnectable>& connectable, const Glib::RefPtr<IOStream>& connection), event) }; diff --git a/gio/src/tlsclientconnection.hg b/gio/src/tlsclientconnection.hg index 94465477..d413f346 100644 --- a/gio/src/tlsclientconnection.hg +++ b/gio/src/tlsclientconnection.hg @@ -52,7 +52,7 @@ class GIOMM_API TlsClientConnection : public Glib::Interface public: // It's not possible to use _WRAP_CTOR/_WRAP_CREATE to wrap the new // function because this is an interface. -#m4 _CONVERSION(`GIOStream*',`Glib::RefPtr<TlsClientConnectionImpl>',`Glib::wrap_tls_client_connection_impl(G_TLS_CONNECTION($3))') +#m4 _CONVERSION(`GIOStream*',`Glib::RefPtr<TlsClientConnectionImpl>',`std::dynamic_pointer_cast<TlsClientConnectionImpl>(Glib::wrap(G_TLS_CONNECTION($3)))') _WRAP_METHOD(static Glib::RefPtr<TlsClientConnectionImpl> create(const Glib::RefPtr<IOStream>& base_io_stream, const Glib::RefPtr<const SocketConnectable>& server_identity{?}), g_tls_client_connection_new, errthrow) diff --git a/gio/src/tlsconnection.ccg b/gio/src/tlsconnection.ccg index 4ec8d7e4..7697ed9f 100644 --- a/gio/src/tlsconnection.ccg +++ b/gio/src/tlsconnection.ccg @@ -18,4 +18,23 @@ #include <giomm/cancellable.h> #include <giomm/tlsdatabase.h> #include <giomm/tlsinteraction.h> +#include <giomm/tlsclientconnectionimpl.h> +#include <giomm/tlsserverconnectionimpl.h> #include "slot_async.h" + +namespace Gio +{ + +// Custom wrap_new() because we want to create +// a TlsClientConnectionImpl if the underlying C class implements the GTlsClientConnection interface, +// a TlsServerConnectionImpl if the underlying C class implements the GTlsServerConnection interface. +Glib::ObjectBase* TlsConnection_Class::wrap_new(GObject* object) +{ + if (G_IS_TLS_CLIENT_CONNECTION(object)) + return new TlsClientConnectionImpl((GTlsConnection*)object); + if (G_IS_TLS_SERVER_CONNECTION(object)) + return new TlsServerConnectionImpl((GTlsConnection*)object); + return new TlsConnection((GTlsConnection*)object); +} + +} // namespace Gio diff --git a/gio/src/tlsconnection.hg b/gio/src/tlsconnection.hg index 12132a80..c7bcc832 100644 --- a/gio/src/tlsconnection.hg +++ b/gio/src/tlsconnection.hg @@ -40,6 +40,7 @@ class GIOMM_API TlsInteraction; class GIOMM_API TlsConnection : public IOStream { _CLASS_GOBJECT(TlsConnection, GTlsConnection, G_TLS_CONNECTION, IOStream, GIOStream, , , GIOMM_API) + _CUSTOM_WRAP_NEW protected: _CTOR_DEFAULT diff --git a/gio/src/tlsserverconnection.hg b/gio/src/tlsserverconnection.hg index 94a729a5..e3193b00 100644 --- a/gio/src/tlsserverconnection.hg +++ b/gio/src/tlsserverconnection.hg @@ -47,7 +47,7 @@ class GIOMM_API TlsServerConnection : public Glib::Interface public: // It's not possible to use _WRAP_CTOR/_WRAP_CREATE to wrap the new // function because this is an interface. -#m4 _CONVERSION(`GIOStream*',`Glib::RefPtr<TlsServerConnectionImpl>',`Glib::wrap_tls_server_connection_impl(G_TLS_CONNECTION($3))') +#m4 _CONVERSION(`GIOStream*',`Glib::RefPtr<TlsServerConnectionImpl>',`std::dynamic_pointer_cast<TlsServerConnectionImpl>(Glib::wrap(G_TLS_CONNECTION($3)))') _WRAP_METHOD(static Glib::RefPtr<TlsServerConnectionImpl> create(const Glib::RefPtr<IOStream>& base_io_stream, const Glib::RefPtr<TlsCertificate>& certificate), g_tls_server_connection_new, errthrow) |