1 /* vi: set et sw=4 ts=4 cino=t0,(0: */
2 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
4 * This file is part of tlm
6 * Copyright (C) 2013 Intel Corporation.
8 * Contact: Imran Zaman <imran.zaman@linux.intel.com>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 #include <gio/gunixinputstream.h>
26 #include <gio/gunixoutputstream.h>
28 #include "tlm-pipe-stream.h"
31 #define TLM_PIPE_STREAM_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj),\
32 TLM_TYPE_PIPE_STREAM, TlmPipeStreamPrivate))
34 struct _TlmPipeStreamPrivate
36 GInputStream *input_stream;
37 GOutputStream *output_stream;
40 G_DEFINE_TYPE (TlmPipeStream, tlm_pipe_stream, G_TYPE_IO_STREAM);
43 _tlm_pipe_stream_get_input_stream (GIOStream *io_stream)
45 return TLM_PIPE_STREAM (io_stream)->priv->input_stream;
48 static GOutputStream *
49 _tlm_pipe_stream_get_output_stream (GIOStream *io_stream)
51 return TLM_PIPE_STREAM (io_stream)->priv->output_stream;
55 _tlm_pipe_stream_dispose (GObject *gobject)
57 g_return_if_fail (TLM_IS_PIPE_STREAM (gobject));
60 /* Chain up to the parent class */
61 G_OBJECT_CLASS (tlm_pipe_stream_parent_class)->dispose (gobject);
66 _tlm_pipe_stream_finalize (GObject *gobject)
68 TlmPipeStream *stream = TLM_PIPE_STREAM (gobject);
70 /* g_io_stream needs streams to be valid in its dispose still
72 if (stream->priv->input_stream) {
73 g_clear_object (&stream->priv->input_stream);
76 if (stream->priv->output_stream) {
77 g_clear_object (&stream->priv->output_stream);
80 G_OBJECT_CLASS (tlm_pipe_stream_parent_class)->finalize (gobject);
84 tlm_pipe_stream_class_init (TlmPipeStreamClass *klass)
86 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
87 GIOStreamClass *stream_class = G_IO_STREAM_CLASS (klass);
89 gobject_class->finalize = _tlm_pipe_stream_finalize;
90 gobject_class->dispose = _tlm_pipe_stream_dispose;
93 stream_class->get_input_stream = _tlm_pipe_stream_get_input_stream;
94 stream_class->get_output_stream = _tlm_pipe_stream_get_output_stream;
96 g_type_class_add_private (klass, sizeof (TlmPipeStreamPrivate));
100 tlm_pipe_stream_init (TlmPipeStream *self)
102 self->priv = TLM_PIPE_STREAM_GET_PRIVATE (self);
103 self->priv->input_stream = NULL;
104 self->priv->output_stream = NULL;
108 tlm_pipe_stream_new (
113 TlmPipeStream *stream = TLM_PIPE_STREAM (g_object_new (
114 TLM_TYPE_PIPE_STREAM, NULL));
116 stream->priv->input_stream = G_INPUT_STREAM (
117 g_unix_input_stream_new (in_fd, close_fds));
118 stream->priv->output_stream = G_OUTPUT_STREAM (
119 g_unix_output_stream_new (out_fd, close_fds));