1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
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 * Author: Alexander Larsson <alexl@redhat.com>
24 #include "gseekable.h"
31 * @short_description: Stream seeking interface
33 * @see_also: #GInputStream, #GOutputStream
35 * #GSeekable is implemented by streams (implementations of
36 * #GInputStream or #GOutputStream) that support seeking.
41 static void g_seekable_base_init (gpointer g_class);
45 g_seekable_get_type (void)
47 static GType seekable_type = 0;
51 static const GTypeInfo seekable_info =
53 sizeof (GSeekableIface), /* class_size */
54 g_seekable_base_init, /* base_init */
55 NULL, /* base_finalize */
57 NULL, /* class_finalize */
58 NULL, /* class_data */
65 g_type_register_static (G_TYPE_INTERFACE, I_("GSeekable"),
68 g_type_interface_add_prerequisite (seekable_type, G_TYPE_OBJECT);
75 g_seekable_base_init (gpointer g_class)
81 * @seekable: a #GSeekable.
83 * Tells the current position within the stream.
85 * Returns: the offset from the beginning of the buffer.
88 g_seekable_tell (GSeekable *seekable)
90 GSeekableIface *iface;
92 g_return_val_if_fail (G_IS_SEEKABLE (seekable), 0);
94 iface = G_SEEKABLE_GET_IFACE (seekable);
96 return (* iface->tell) (seekable);
100 * g_seekable_can_seek:
101 * @seekable: a #GSeekable.
103 * Tests if the stream supports the #GSeekableIface.
105 * Returns: %TRUE if @seekable can be seeked. %FALSE otherwise.
108 g_seekable_can_seek (GSeekable *seekable)
110 GSeekableIface *iface;
112 g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
114 iface = G_SEEKABLE_GET_IFACE (seekable);
116 return (* iface->can_seek) (seekable);
121 * @seekable: a #GSeekable.
122 * @offset: a #goffset.
123 * @type: a #GSeekType.
124 * @cancellable: optional #GCancellable object, %NULL to ignore.
125 * @error: a #GError location to store the error occuring, or %NULL to
128 * Seeks in the stream by the given @offset, modified by @type.
130 * If @cancellable is not %NULL, then the operation can be cancelled by
131 * triggering the cancellable object from another thread. If the operation
132 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
134 * Returns: %TRUE if successful. If an error
135 * has occurred, this function will return %FALSE and set @error
136 * appropriately if present.
139 g_seekable_seek (GSeekable *seekable,
142 GCancellable *cancellable,
145 GSeekableIface *iface;
147 g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
149 iface = G_SEEKABLE_GET_IFACE (seekable);
151 return (* iface->seek) (seekable, offset, type, cancellable, error);
155 * g_seekable_can_truncate:
156 * @seekable: a #GSeekable.
158 * Tests if the stream can be truncated.
160 * Returns: %TRUE if the stream can be truncated, %FALSE otherwise.
163 g_seekable_can_truncate (GSeekable *seekable)
165 GSeekableIface *iface;
167 g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
169 iface = G_SEEKABLE_GET_IFACE (seekable);
171 return (* iface->can_truncate) (seekable);
175 * g_seekable_truncate:
176 * @seekable: a #GSeekable.
177 * @offset: a #goffset.
178 * @cancellable: optional #GCancellable object, %NULL to ignore.
179 * @error: a #GError location to store the error occuring, or %NULL to
182 * Truncates a stream with a given #offset.
184 * If @cancellable is not %NULL, then the operation can be cancelled by
185 * triggering the cancellable object from another thread. If the operation
186 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an
187 * operation was partially finished when the operation was cancelled the
188 * partial result will be returned, without an error.
190 * Returns: %TRUE if successful. If an error
191 * has occurred, this function will return %FALSE and set @error
192 * appropriately if present.
195 g_seekable_truncate (GSeekable *seekable,
197 GCancellable *cancellable,
200 GSeekableIface *iface;
202 g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
204 iface = G_SEEKABLE_GET_IFACE (seekable);
206 return (* iface->truncate_fn) (seekable, offset, cancellable, error);
209 #define __G_SEEKABLE_C__
210 #include "gioaliasdef.c"