[glibmm] Wrap SocketClient, SocketConnection, TcpConnection, UnixConnection



commit 869c20eabe798e5c2af6311cf398fbb169a579ed
Author: Jonathon Jongsma <jonathon quotidian org>
Date:   Sat Jan 2 18:32:00 2010 -0600

    Wrap SocketClient, SocketConnection, TcpConnection, UnixConnection

 gio/giomm.h                  |    4 ++
 gio/src/filelist.am          |    4 ++
 gio/src/socketclient.ccg     |   83 +++++++++++++++++++++++++++++++++++++
 gio/src/socketclient.hg      |   93 ++++++++++++++++++++++++++++++++++++++++++
 gio/src/socketconnection.ccg |   24 +++++++++++
 gio/src/socketconnection.hg  |   70 +++++++++++++++++++++++++++++++
 gio/src/tcpconnection.ccg    |   24 +++++++++++
 gio/src/tcpconnection.hg     |   51 +++++++++++++++++++++++
 gio/src/unixconnection.ccg   |   25 +++++++++++
 gio/src/unixconnection.hg    |   52 +++++++++++++++++++++++
 tools/m4/convert_gio.m4      |    6 +++
 11 files changed, 436 insertions(+), 0 deletions(-)
---
diff --git a/gio/giomm.h b/gio/giomm.h
index 75a8f56..99ed546 100644
--- a/gio/giomm.h
+++ b/gio/giomm.h
@@ -69,10 +69,14 @@
 #include <giomm/socket.h>
 #include <giomm/socketaddress.h>
 #include <giomm/socketaddressenumerator.h>
+#include <giomm/socketclient.h>
 #include <giomm/socketconnectable.h>
+#include <giomm/socketconnection.h>
 #include <giomm/srvtarget.h>
+#include <giomm/tcpconnection.h>
 #include <giomm/themedicon.h>
 #ifndef G_OS_WIN32
+# include <giomm/unixconnection.h>
 # include <giomm/unixinputstream.h>
 # include <giomm/unixoutputstream.h>
 #endif
diff --git a/gio/src/filelist.am b/gio/src/filelist.am
index 333351c..4303780 100644
--- a/gio/src/filelist.am
+++ b/gio/src/filelist.am
@@ -55,14 +55,18 @@ giomm_files_any_hg =			\
 	socket.hg			\
 	socketaddress.hg		\
 	socketaddressenumerator.hg	\
+	socketclient.hg		\
 	socketconnectable.hg		\
+	socketconnection.hg		\
 	srvtarget.hg			\
+	tcpconnection.hg			\
 	themedicon.hg			\
 	volume.hg			\
 	volumemonitor.hg
 
 giomm_files_posix_hg =			\
 	desktopappinfo.hg		\
+	unixconnection.hg		\
 	unixinputstream.hg		\
 	unixoutputstream.hg
 
diff --git a/gio/src/socketclient.ccg b/gio/src/socketclient.ccg
new file mode 100644
index 0000000..b947e76
--- /dev/null
+++ b/gio/src/socketclient.ccg
@@ -0,0 +1,83 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* Copyright (C) 2010 Jonathon Jongsma
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gio/gio.h>
+#include <giomm/asyncresult.h>
+#include "slot_async.h"
+
+namespace Gio
+{
+
+void
+SocketClient::connect_async(const Glib::RefPtr<SocketConnectable>& connectable,
+                            const Glib::RefPtr<Cancellable>& cancellable,
+                            const SlotAsyncReady& slot)
+{
+  // Create a copy of the slot.
+  // A pointer to it will be passed through the callback's data parameter
+  // and deleted in the callback.
+  SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
+
+  g_socket_client_connect_async (gobj(),
+                                 connectable->gobj (),
+                                 cancellable->gobj(),
+                                 &SignalProxy_async_callback,
+                                 slot_copy);
+}
+
+void
+SocketClient::connect_to_host_async(const Glib::ustring& host_and_port,
+                                    guint16 default_port,
+                                    const Glib::RefPtr<Cancellable>& cancellable,
+                                    const SlotAsyncReady& slot)
+{
+  // Create a copy of the slot.
+  // A pointer to it will be passed through the callback's data parameter
+  // and deleted in the callback.
+  SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
+
+  g_socket_client_connect_to_host_async (gobj(),
+                                         host_and_port.c_str (),
+                                         default_port,
+                                         cancellable->gobj(),
+                                         &SignalProxy_async_callback,
+                                         slot_copy);
+}
+
+void
+SocketClient::connect_to_service_async(const Glib::ustring& domain,
+                                       const Glib::ustring& service,
+                                       const Glib::RefPtr<Cancellable>& cancellable,
+                                       const SlotAsyncReady& slot)
+{
+  // Create a copy of the slot.
+  // A pointer to it will be passed through the callback's data parameter
+  // and deleted in the callback.
+  SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
+
+  g_socket_client_connect_to_service_async (gobj(),
+                                            domain.c_str (),
+                                            service.c_str (),
+                                            cancellable->gobj(),
+                                            &SignalProxy_async_callback,
+                                            slot_copy);
+}
+
+
+} // namespace Gio
diff --git a/gio/src/socketclient.hg b/gio/src/socketclient.hg
new file mode 100644
index 0000000..6890e38
--- /dev/null
+++ b/gio/src/socketclient.hg
@@ -0,0 +1,93 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* Copyright (C) 2010 Jonathon Jongsma
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <glibmm/object.h>
+#include <giomm/asyncresult.h>
+#include <giomm/cancellable.h>
+#include <giomm/socketconnectable.h>
+#include <giomm/enums.h>
+#include <giomm/socket.h>
+#include <giomm/socketconnection.h>
+
+_DEFS(giomm,gio)
+_PINCLUDE(glibmm/private/object_p.h)
+
+namespace Gio
+{
+
+/** @defgroup NetworkIO Portable Network I/O Functionality
+ */
+
+/**
+ * Helper for connecting to a network service
+ * @see_also SocketConnection, SocketListener
+ *
+ * SocketClient is a high-level utility class for connecting to a
+ * network host using a connection oriented socket type.
+ *
+ * You create a SocketClient object, set any options you want, then
+ * call a sync or async connect operation, which returns a #GSocketConnection
+ * subclass on success.
+ *
+ * The type of the SocketConnection object returned depends on the type of
+ * the underlying socket that is in use. For instance, for a TCP/IP connection
+ * it will be a TcpConnection.
+ *
+ * @newin{2,24}
+ * @ingroup NetworkIO
+ */
+class SocketClient : public Glib::Object
+{
+    _CLASS_GOBJECT(SocketClient, GSocketClient, G_SOCKET_CLIENT, Glib::Object, GObject)
+
+protected:
+    _CTOR_DEFAULT
+
+public:
+_WRAP_CREATE()
+_WRAP_METHOD(SocketFamily get_family() const, g_socket_client_get_family)
+_WRAP_METHOD(void set_family(SocketFamily family), g_socket_client_set_family)
+_WRAP_METHOD(SocketType get_socket_type() const, g_socket_client_get_socket_type)
+_WRAP_METHOD(void set_socket_type(SocketType type), g_socket_client_set_socket_type)
+_WRAP_METHOD(SocketProtocol get_protocol() const, g_socket_client_get_protocol)
+_WRAP_METHOD(void set_protocol(SocketProtocol protocol), g_socket_client_set_protocol)
+_WRAP_METHOD(Glib::RefPtr<SocketAddress> get_local_address(), g_socket_client_get_local_address)
+_WRAP_METHOD(Glib::RefPtr<const SocketAddress> get_local_address() const, g_socket_client_get_local_address, constversion)
+_WRAP_METHOD(void set_local_address(const Glib::RefPtr<SocketAddress>& address), g_socket_client_set_local_address)
+
+// TODO: non-cancellable version
+_WRAP_METHOD(Glib::RefPtr<SocketConnection> connect(const Glib::RefPtr<SocketConnectable>& connectable, const Glib::RefPtr<Cancellable>& cancellable), g_socket_client_connect, errthrow)
+// TODO: non-cancellable version
+_WRAP_METHOD(Glib::RefPtr<SocketConnection> connect_to_host(const Glib::ustring& host_and_port, guint16 default_port, const Glib::RefPtr<Cancellable>& cancellable), g_socket_client_connect_to_host, errthrow)
+// TODO: non-cancellable version
+_WRAP_METHOD(Glib::RefPtr<SocketConnection> connect_to_service(const Glib::ustring& domain, const Glib::ustring& service, const Glib::RefPtr<Cancellable>& cancellable), g_socket_client_connect_to_service, errthrow)
+// TODO: non-cancellable version
+void connect_async(const Glib::RefPtr<SocketConnectable>& connectable, const Glib::RefPtr<Cancellable>& cancellable, const SlotAsyncReady& slot);
+_WRAP_METHOD(Glib::RefPtr<SocketConnection> connect_finish(const Glib::RefPtr<AsyncResult>& result), g_socket_client_connect_finish, errthrow)
+// TODO: non-cancellable version
+void connect_to_host_async(const Glib::ustring& host_and_port, guint16 default_port, const Glib::RefPtr<Cancellable>& cancellable, const SlotAsyncReady& slot);
+_WRAP_METHOD(Glib::RefPtr<SocketConnection> connect_to_host_finish(const Glib::RefPtr<AsyncResult>& result), g_socket_client_connect_to_host_finish, errthrow)
+
+// TODO: non-cancellable version
+void connect_to_service_async(const Glib::ustring& domain, const Glib::ustring& service, const Glib::RefPtr<Cancellable>& cancellable, const SlotAsyncReady& slot);
+_WRAP_METHOD(Glib::RefPtr<SocketConnection> connect_to_service_finish(const Glib::RefPtr<AsyncResult>& result), g_socket_client_connect_to_service_finish, errthrow)
+
+};
+
+} // namespace Gio
diff --git a/gio/src/socketconnection.ccg b/gio/src/socketconnection.ccg
new file mode 100644
index 0000000..6e07769
--- /dev/null
+++ b/gio/src/socketconnection.ccg
@@ -0,0 +1,24 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* Copyright (C) 2010 Jonathon Jongsma
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gio/gio.h>
+
+namespace Gio
+{
+} // namespace Gio
diff --git a/gio/src/socketconnection.hg b/gio/src/socketconnection.hg
new file mode 100644
index 0000000..8545eb0
--- /dev/null
+++ b/gio/src/socketconnection.hg
@@ -0,0 +1,70 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* Copyright (C) 2010 Jonathon Jongsma
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <glibmm/object.h>
+#include <giomm/iostream.h>
+#include <giomm/enums.h>
+#include <giomm/socket.h>
+
+_DEFS(giomm,gio)
+_PINCLUDE(giomm/private/iostream_p.h)
+
+namespace Gio
+{
+
+/** @defgroup NetworkIO Portable Network I/O Functionality
+ */
+
+/**
+ * A socket connection
+ * @see_also: IOStream, SocketClient, SocketListener
+ *
+ * SocketConnection is a IOStream for a connected socket. They
+ * can be created either by SocketClient when connecting to a host,
+ * or by SocketListener when accepting a new client.
+ *
+ * The type of the SocketConnection object returned from these calls
+ * depends on the type of the underlying socket that is in use. For
+ * instance, for a TCP/IP connection it will be a TcpConnection.
+ *
+ * Chosing what type of object to construct is done with the socket
+ * connection factory, and it is possible for 3rd parties to register
+ * custom socket connection types for specific combination of socket
+ * family/type/protocol using g_socket_connection_factory_register_type().
+ *
+ * @newin{2,24}
+ * @ingroup NetworkIO
+ */
+class SocketConnection : public Gio::IOStream
+{
+    _CLASS_GOBJECT(SocketConnection, GSocketConnection, G_SOCKET_CONNECTION, Gio::IOStream, GIOStream)
+
+public:
+_WRAP_METHOD(Glib::RefPtr<Socket> get_socket(), g_socket_connection_get_socket)
+_WRAP_METHOD(Glib::RefPtr<const Socket> get_socket() const, g_socket_connection_get_socket, constversion)
+_WRAP_METHOD(Glib::RefPtr<SocketAddress> get_local_address(), g_socket_connection_get_local_address, errthrow)
+_WRAP_METHOD(Glib::RefPtr<const SocketAddress> get_local_address() const, g_socket_connection_get_local_address, constversion, errthrow)
+_WRAP_METHOD(Glib::RefPtr<SocketAddress> get_remote_address(), g_socket_connection_get_remote_address, errthrow)
+_WRAP_METHOD(Glib::RefPtr<const SocketAddress> get_remote_address() const, g_socket_connection_get_remote_address, constversion, errthrow)
+//_WRAP_METHOD(void factory_register_type(GType g_type, GSocketFamily family, GSocketType type, gint protocol);
+//_WRAP_METHOD(GType factory_lookup_type(GSocketFamily family, GSocketType type, gint protocol_id);
+//_WRAP_METHOD(Glib::RefPtr<SocketConnection> factory_create_connection(GSocket *socket);
+};
+
+} // namespace Gio
diff --git a/gio/src/tcpconnection.ccg b/gio/src/tcpconnection.ccg
new file mode 100644
index 0000000..6e07769
--- /dev/null
+++ b/gio/src/tcpconnection.ccg
@@ -0,0 +1,24 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* Copyright (C) 2010 Jonathon Jongsma
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gio/gio.h>
+
+namespace Gio
+{
+} // namespace Gio
diff --git a/gio/src/tcpconnection.hg b/gio/src/tcpconnection.hg
new file mode 100644
index 0000000..d995dfe
--- /dev/null
+++ b/gio/src/tcpconnection.hg
@@ -0,0 +1,51 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* Copyright (C) 2010 Jonathon Jongsma
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <glibmm/object.h>
+#include <giomm/socketconnection.h>
+
+_DEFS(giomm,gio)
+_PINCLUDE(giomm/private/socketconnection_p.h)
+
+namespace Gio
+{
+
+/** @defgroup NetworkIO Portable Network I/O Functionality
+ */
+
+/**
+ * A TCP SocketConnection
+ *
+ * This is the subclass of SocketConnection that is created
+ * for TCP/IP sockets.
+ *
+ * @newin{2,24}
+ * @ingroup NetworkIO
+ */
+class TcpConnection : public Gio::SocketConnection
+{
+    _CLASS_GOBJECT(TcpConnection, GTcpConnection, G_TCP_CONNECTION, Gio::SocketConnection, GSocketConnection)
+    _GTKMMPROC_WIN32_NO_WRAP
+
+public:
+    _WRAP_METHOD(void set_graceful_disconnect (bool graceful_disconnect), g_tcp_connection_set_graceful_disconnect)
+    _WRAP_METHOD(bool get_graceful_disconnect () const, g_tcp_connection_get_graceful_disconnect)
+};
+
+} // namespace Gio
diff --git a/gio/src/unixconnection.ccg b/gio/src/unixconnection.ccg
new file mode 100644
index 0000000..e4433e4
--- /dev/null
+++ b/gio/src/unixconnection.ccg
@@ -0,0 +1,25 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* Copyright (C) 2010 Jonathon Jongsma
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gio/gio.h>
+#include <gio/gunixconnection.h>
+
+namespace Gio
+{
+} // namespace Gio
diff --git a/gio/src/unixconnection.hg b/gio/src/unixconnection.hg
new file mode 100644
index 0000000..3c6bdb3
--- /dev/null
+++ b/gio/src/unixconnection.hg
@@ -0,0 +1,52 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* Copyright (C) 2010 Jonathon Jongsma
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <glibmm/object.h>
+#include <giomm/socketconnection.h>
+
+_DEFS(giomm,gio)
+_PINCLUDE(giomm/private/socketconnection_p.h)
+
+namespace Gio
+{
+
+/** @defgroup NetworkIO Portable Network I/O Functionality
+ */
+
+/**
+ * A Unix domain SocketConnection
+ *
+ * This is the subclass of #GSocketConnection that is created
+ * for UNIX domain sockets.
+ *
+ * It contains functions to do some of the unix socket specific
+ * functionallity like passing file descriptors.
+ *
+ * @newin{2,24}
+ * @ingroup NetworkIO
+ */
+class UnixConnection : public Gio::SocketConnection
+{
+    _CLASS_GOBJECT(UnixConnection, GUnixConnection, G_UNIX_CONNECTION, Gio::SocketConnection, GSocketConnection)
+public:
+    _WRAP_METHOD(bool send_fd(int fd, const Glib::RefPtr<Cancellable>& cancellable), g_unix_connection_send_fd, errthrow)
+    _WRAP_METHOD(int receive_fd(const Glib::RefPtr<Cancellable>& cancellable), g_unix_connection_receive_fd, errthrow)
+};
+
+} // namespace Gio
diff --git a/tools/m4/convert_gio.m4 b/tools/m4/convert_gio.m4
index a625bb5..f5f3eb2 100644
--- a/tools/m4/convert_gio.m4
+++ b/tools/m4/convert_gio.m4
@@ -132,6 +132,12 @@ _CONVERSION(`const Glib::RefPtr<SocketAddress>&',`GSocketAddress*',__CONVERT_CON
 _CONVERSION(`Glib::RefPtr<SocketAddress>&',`GSocketAddress*',__CONVERT_CONST_REFPTR_TO_P)
 _CONVERSION(`GSocketAddressEnumerator*',`Glib::RefPtr<SocketAddressEnumerator>',`Glib::wrap($3)')
 
+#SocketConnectable
+_CONVERSION(`const Glib::RefPtr<SocketConnectable>&',`GSocketConnectable*',__CONVERT_CONST_REFPTR_TO_P)
+
+#SocketConnection
+_CONVERSION(`GSocketConnection*',`Glib::RefPtr<SocketConnection>',`Glib::wrap($3)')
+
 #Volume
 _CONVERSION(`GVolume*',`Glib::RefPtr<Volume>',`Glib::wrap($3)')
 



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