gtestutils: Fix a typo in a documentation comment
[glib.git] / gio / gsimpleiostream.c
blobaa988c13e1f6c30ed04d778478f1a66556753f2e
1 /*
2 * Copyright © 2014 NICE s.r.l.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation; either version 2 of the licence or (at
7 * your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 * Authors: Ignacio Casal Quinteiro <ignacio.casal@nice-software.com>
21 #include "config.h"
22 #include <glib.h>
23 #include "glibintl.h"
25 #include "gsimpleiostream.h"
26 #include "gtask.h"
28 /**
29 * SECTION:gsimpleiostream
30 * @short_description: A wrapper around an input and an output stream.
31 * @include: gio/gio.h
32 * @see_also: #GIOStream
34 * GSimpleIOStream creates a #GIOStream from an arbitrary #GInputStream and
35 * #GOutputStream. This allows any pair of input and output streams to be used
36 * with #GIOStream methods.
38 * This is useful when you obtained a #GInputStream and a #GOutputStream
39 * by other means, for instance creating them with platform specific methods as
40 * g_unix_input_stream_new() or g_win32_input_stream_new(), and you want
41 * to take advantage of the methods provided by #GIOStream.
43 * Since: 2.44
46 /**
47 * GSimpleIOStream:
49 * A wrapper around a #GInputStream and a #GOutputStream.
51 * Since: 2.44
53 struct _GSimpleIOStream
55 GIOStream parent;
57 GInputStream *input_stream;
58 GOutputStream *output_stream;
61 struct _GSimpleIOStreamClass
63 GIOStreamClass parent;
66 typedef struct _GSimpleIOStreamClass GSimpleIOStreamClass;
68 enum
70 PROP_0,
71 PROP_INPUT_STREAM,
72 PROP_OUTPUT_STREAM
75 G_DEFINE_TYPE (GSimpleIOStream, g_simple_io_stream, G_TYPE_IO_STREAM)
77 static void
78 g_simple_io_stream_finalize (GObject *object)
80 GSimpleIOStream *stream = G_SIMPLE_IO_STREAM (object);
82 if (stream->input_stream)
83 g_object_unref (stream->input_stream);
85 if (stream->output_stream)
86 g_object_unref (stream->output_stream);
88 G_OBJECT_CLASS (g_simple_io_stream_parent_class)->finalize (object);
91 static void
92 g_simple_io_stream_set_property (GObject *object,
93 guint prop_id,
94 const GValue *value,
95 GParamSpec *pspec)
97 GSimpleIOStream *stream = G_SIMPLE_IO_STREAM (object);
99 switch (prop_id)
101 case PROP_INPUT_STREAM:
102 stream->input_stream = g_value_dup_object (value);
103 break;
105 case PROP_OUTPUT_STREAM:
106 stream->output_stream = g_value_dup_object (value);
107 break;
109 default:
110 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
111 break;
115 static void
116 g_simple_io_stream_get_property (GObject *object,
117 guint prop_id,
118 GValue *value,
119 GParamSpec *pspec)
121 GSimpleIOStream *stream = G_SIMPLE_IO_STREAM (object);
123 switch (prop_id)
125 case PROP_INPUT_STREAM:
126 g_value_set_object (value, stream->input_stream);
127 break;
129 case PROP_OUTPUT_STREAM:
130 g_value_set_object (value, stream->output_stream);
131 break;
133 default:
134 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
135 break;
139 static GInputStream *
140 g_simple_io_stream_get_input_stream (GIOStream *stream)
142 GSimpleIOStream *simple_stream = G_SIMPLE_IO_STREAM (stream);
144 return simple_stream->input_stream;
147 static GOutputStream *
148 g_simple_io_stream_get_output_stream (GIOStream *stream)
150 GSimpleIOStream *simple_stream = G_SIMPLE_IO_STREAM (stream);
152 return simple_stream->output_stream;
155 static void
156 g_simple_io_stream_class_init (GSimpleIOStreamClass *class)
158 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
159 GIOStreamClass *io_class = G_IO_STREAM_CLASS (class);
161 gobject_class->finalize = g_simple_io_stream_finalize;
162 gobject_class->get_property = g_simple_io_stream_get_property;
163 gobject_class->set_property = g_simple_io_stream_set_property;
165 io_class->get_input_stream = g_simple_io_stream_get_input_stream;
166 io_class->get_output_stream = g_simple_io_stream_get_output_stream;
169 * GSimpleIOStream:input-stream:
171 * Since: 2.44
173 g_object_class_install_property (gobject_class, PROP_INPUT_STREAM,
174 g_param_spec_object ("input-stream",
175 P_("Input stream"),
176 P_("The GInputStream to read from"),
177 G_TYPE_INPUT_STREAM,
178 G_PARAM_READWRITE |
179 G_PARAM_STATIC_STRINGS |
180 G_PARAM_CONSTRUCT_ONLY));
183 * GSimpleIOStream:output-stream:
185 * Since: 2.44
187 g_object_class_install_property (gobject_class, PROP_OUTPUT_STREAM,
188 g_param_spec_object ("output-stream",
189 P_("Output stream"),
190 P_("The GOutputStream to write to"),
191 G_TYPE_OUTPUT_STREAM,
192 G_PARAM_READWRITE |
193 G_PARAM_STATIC_STRINGS |
194 G_PARAM_CONSTRUCT_ONLY));
197 static void
198 g_simple_io_stream_init (GSimpleIOStream *stream)
203 * g_simple_io_stream_new:
204 * @input_stream: a #GInputStream.
205 * @output_stream: a #GOutputStream.
207 * Creates a new #GSimpleIOStream wrapping @input_stream and @output_stream.
208 * See also #GIOStream.
210 * Returns: a new #GSimpleIOStream instance.
212 * Since: 2.44
214 GIOStream *
215 g_simple_io_stream_new (GInputStream *input_stream,
216 GOutputStream *output_stream)
218 return g_object_new (G_TYPE_SIMPLE_IO_STREAM,
219 "input-stream", input_stream,
220 "output-stream", output_stream,
221 NULL);