Improvde #include order consistency
[glib.git] / gio / gtcpwrapperconnection.c
blobdeab98f2d3db94c9571e07192afc02fdf9584e86
1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright © 2010 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Authors: Nicolas Dufresne <nicolas.dufresne@colllabora.co.uk>
23 /**
24 * SECTION:gtcpwrapperconnection
25 * @title: GTcpWrapperConnection
26 * @short_description: wrapper for non-GSocketConnection-based, GSocket-based GIOStreams
27 * @see_also: #GSocketConnection.
29 * A #GTcpWrapperConnection can be used to wrap a #GIOStream that is
30 * based on a #GSocket, but which is not actually a
31 * #GSocketConnection. This is used by #GSocketClient so that it can
32 * always return a #GSocketConnection, even when the connection it has
33 * actually created is not directly a #GSocketConnection.
35 * Since: 2.28
38 #include "config.h"
40 #include "gtcpwrapperconnection.h"
42 #include "gtcpconnection.h"
43 #include "glibintl.h"
45 G_DEFINE_TYPE (GTcpWrapperConnection,
46 g_tcp_wrapper_connection, G_TYPE_TCP_CONNECTION);
48 enum
50 PROP_NONE,
51 PROP_BASE_IO_STREAM
54 struct _GTcpWrapperConnectionPrivate
56 GIOStream *base_io_stream;
59 static GInputStream *
60 g_tcp_wrapper_connection_get_input_stream (GIOStream *io_stream)
62 GTcpWrapperConnection *connection = G_TCP_WRAPPER_CONNECTION (io_stream);
64 return g_io_stream_get_input_stream (connection->priv->base_io_stream);
67 static GOutputStream *
68 g_tcp_wrapper_connection_get_output_stream (GIOStream *io_stream)
70 GTcpWrapperConnection *connection = G_TCP_WRAPPER_CONNECTION (io_stream);
72 return g_io_stream_get_output_stream (connection->priv->base_io_stream);
75 static void
76 g_tcp_wrapper_connection_get_property (GObject *object,
77 guint prop_id,
78 GValue *value,
79 GParamSpec *pspec)
81 GTcpWrapperConnection *connection = G_TCP_WRAPPER_CONNECTION (object);
83 switch (prop_id)
85 case PROP_BASE_IO_STREAM:
86 g_value_set_object (value, connection->priv->base_io_stream);
87 break;
89 default:
90 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
94 static void
95 g_tcp_wrapper_connection_set_property (GObject *object,
96 guint prop_id,
97 const GValue *value,
98 GParamSpec *pspec)
100 GTcpWrapperConnection *connection = G_TCP_WRAPPER_CONNECTION (object);
102 switch (prop_id)
104 case PROP_BASE_IO_STREAM:
105 connection->priv->base_io_stream = g_value_dup_object (value);
106 break;
108 default:
109 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
113 static void
114 g_tcp_wrapper_connection_finalize (GObject *object)
116 GTcpWrapperConnection *connection = G_TCP_WRAPPER_CONNECTION (object);
118 if (connection->priv->base_io_stream)
119 g_object_unref (connection->priv->base_io_stream);
121 G_OBJECT_CLASS (g_tcp_wrapper_connection_parent_class)->finalize (object);
124 static void
125 g_tcp_wrapper_connection_class_init (GTcpWrapperConnectionClass *klass)
127 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
128 GIOStreamClass *stream_class = G_IO_STREAM_CLASS (klass);
130 g_type_class_add_private (klass, sizeof (GTcpWrapperConnectionPrivate));
132 gobject_class->set_property = g_tcp_wrapper_connection_set_property;
133 gobject_class->get_property = g_tcp_wrapper_connection_get_property;
134 gobject_class->finalize = g_tcp_wrapper_connection_finalize;
136 stream_class->get_input_stream = g_tcp_wrapper_connection_get_input_stream;
137 stream_class->get_output_stream = g_tcp_wrapper_connection_get_output_stream;
139 g_object_class_install_property (gobject_class,
140 PROP_BASE_IO_STREAM,
141 g_param_spec_object ("base-io-stream",
142 P_("Base IO Stream"),
143 P_("The wrapped GIOStream"),
144 G_TYPE_IO_STREAM,
145 G_PARAM_CONSTRUCT_ONLY |
146 G_PARAM_READWRITE |
147 G_PARAM_STATIC_STRINGS));
150 static void
151 g_tcp_wrapper_connection_init (GTcpWrapperConnection *connection)
153 connection->priv = G_TYPE_INSTANCE_GET_PRIVATE (connection,
154 G_TYPE_TCP_WRAPPER_CONNECTION,
155 GTcpWrapperConnectionPrivate);
159 * g_tcp_wrapper_connection_new:
160 * @base_io_stream: the #GIOStream to wrap
161 * @socket: the #GSocket associated with @base_io_stream
163 * Wraps @base_io_stream and @socket together as a #GSocketConnection.
165 * Return value: the new #GSocketConnection.
167 * Since: 2.28
169 GSocketConnection *
170 g_tcp_wrapper_connection_new (GIOStream *base_io_stream,
171 GSocket *socket)
173 g_return_val_if_fail (G_IS_IO_STREAM (base_io_stream), NULL);
174 g_return_val_if_fail (G_IS_SOCKET (socket), NULL);
175 g_return_val_if_fail (g_socket_get_family (socket) == G_SOCKET_FAMILY_IPV4 ||
176 g_socket_get_family (socket) == G_SOCKET_FAMILY_IPV6, NULL);
177 g_return_val_if_fail (g_socket_get_socket_type (socket) == G_SOCKET_TYPE_STREAM, NULL);
179 return g_object_new (G_TYPE_TCP_WRAPPER_CONNECTION,
180 "base-io-stream", base_io_stream,
181 "socket", socket,
182 NULL);
186 * g_tcp_wrapper_connection_get_base_io_stream:
187 * @conn: a #GTcpWrapperConnection
189 * Get's @conn's base #GIOStream
191 * Return value: (transfer none): @conn's base #GIOStream
193 GIOStream *
194 g_tcp_wrapper_connection_get_base_io_stream (GTcpWrapperConnection *conn)
196 g_return_val_if_fail (G_IS_TCP_WRAPPER_CONNECTION (conn), NULL);
198 return conn->priv->base_io_stream;