diff options
author | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2020-07-31 15:20:49 +0200 |
---|---|---|
committer | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2020-07-31 15:20:49 +0200 |
commit | 477fcd63ab7a836be8916e44f7d3145f650da55c (patch) | |
tree | e1b674c291fbba39b8865a3a0b13693c860e5a25 | |
parent | 79ca4a64dbd7dcc59b2662d5f996f42700b6021a (diff) | |
download | glibmm-477fcd63ab7a836be8916e44f7d3145f650da55c.tar.gz |
Gio::SocketClient::signal_event(): Fix wrapping of 'connection' param
The GIOStream* parameter in the 'event' signal can point to either a
GSocketConnection or to a subclass of GTlsConnection that implements
the GTlsClientConnection interface. If it implements the
GTlsClientConnection interface, wrap it in a Gio::TlsClientConnectionImpl.
Then a signal handler can do:
auto tls_client_connection =
std::dynamic_pointer_cast<Gio::TlsClientConnection>(connection);
Fixes #73
-rw-r--r-- | gio/src/socketclient.ccg | 19 | ||||
-rw-r--r-- | gio/src/socketclient.hg | 5 |
2 files changed, 22 insertions, 2 deletions
diff --git a/gio/src/socketclient.ccg b/gio/src/socketclient.ccg index 8339f12d..52658d62 100644 --- a/gio/src/socketclient.ccg +++ b/gio/src/socketclient.ccg @@ -15,9 +15,28 @@ */ #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 b7ae3e32..b0a5d898 100644 --- a/gio/src/socketclient.hg +++ b/gio/src/socketclient.hg @@ -167,8 +167,9 @@ 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>&',`Glib::wrap($3, true)') - _WRAP_SIGNAL(void event(SocketClientEvent event, const Glib::RefPtr<SocketConnectable>& connectable, const Glib::RefPtr<IOStream>& connection), event) +#m4 _CONVERSION(`GIOStream*',`const Glib::RefPtr<IOStream>&',`SocketClient_signal_event_wrap_connection($3, true)') + _WRAP_SIGNAL(void event(SocketClientEvent event, const Glib::RefPtr<SocketConnectable>& connectable, + const Glib::RefPtr<IOStream>& connection), event) }; } // namespace Gio |