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
32 * @see_also: #GInputStream, #GOutputStream
34 * #GSeekable is implemented by streams (implementations of
35 * #GInputStream or #GOutputStream) that support seeking.
40 static void g_seekable_base_init (gpointer g_class);
44 g_seekable_get_type (void)
46 static GType seekable_type = 0;
50 static const GTypeInfo seekable_info =
52 sizeof (GSeekableIface), /* class_size */
53 g_seekable_base_init, /* base_init */
54 NULL, /* base_finalize */
56 NULL, /* class_finalize */
57 NULL, /* class_data */
64 g_type_register_static (G_TYPE_INTERFACE, I_("GSeekable"),
67 g_type_interface_add_prerequisite (seekable_type, G_TYPE_OBJECT);
74 g_seekable_base_init (gpointer g_class)
80 * @seekable: a #GSeekable.
82 * Tells the current position within the stream.
84 * Returns: the offset from the beginning of the buffer.
87 g_seekable_tell (GSeekable *seekable)
89 GSeekableIface *iface;
91 g_return_val_if_fail (G_IS_SEEKABLE (seekable), 0);
93 iface = G_SEEKABLE_GET_IFACE (seekable);
95 return (* iface->tell) (seekable);
99 * g_seekable_can_seek:
100 * @seekable: a #GSeekable.
102 * Tests if the stream supports the #GSeekableIface.
104 * Returns: %TRUE if @seekable can be seeked. %FALSE otherwise.
107 g_seekable_can_seek (GSeekable *seekable)
109 GSeekableIface *iface;
111 g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
113 iface = G_SEEKABLE_GET_IFACE (seekable);
115 return (* iface->can_seek) (seekable);
120 * @seekable: a #GSeekable.
121 * @offset: a #goffset.
122 * @type: a #GSeekType.
123 * @cancellable: optional #GCancellable object, %NULL to ignore.
124 * @error: a #GError location to store the error occuring, or %NULL to
127 * Seeks in the stream by the given @offset, modified by @type.
129 * If @cancellable is not %NULL, then the operation can be cancelled by
130 * triggering the cancellable object from another thread. If the operation
131 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
133 * Returns: %TRUE if successful. If an error
134 * has occured, this function will return %FALSE and set @error
135 * appropriately if present.
138 g_seekable_seek (GSeekable *seekable,
141 GCancellable *cancellable,
144 GSeekableIface *iface;
146 g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
148 iface = G_SEEKABLE_GET_IFACE (seekable);
150 return (* iface->seek) (seekable, offset, type, cancellable, error);
154 * g_seekable_can_truncate:
155 * @seekable: a #GSeekable.
157 * Tests if the stream can be truncated.
159 * Returns: %TRUE if the stream can be truncated, %FALSE otherwise.
162 g_seekable_can_truncate (GSeekable *seekable)
164 GSeekableIface *iface;
166 g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
168 iface = G_SEEKABLE_GET_IFACE (seekable);
170 return (* iface->can_truncate) (seekable);
174 * g_seekable_truncate:
175 * @seekable: a #GSeekable.
176 * @offset: a #goffset.
177 * @cancellable: optional #GCancellable object, %NULL to ignore.
178 * @error: a #GError location to store the error occuring, or %NULL to
181 * Truncates a stream with a given #offset.
183 * If @cancellable is not %NULL, then the operation can be cancelled by
184 * triggering the cancellable object from another thread. If the operation
185 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an
186 * operation was partially finished when the operation was cancelled the
187 * partial result will be returned, without an error.
189 * Returns: %TRUE if successful. If an error
190 * has occured, this function will return %FALSE and set @error
191 * appropriately if present.
194 g_seekable_truncate (GSeekable *seekable,
196 GCancellable *cancellable,
199 GSeekableIface *iface;
201 g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
203 iface = G_SEEKABLE_GET_IFACE (seekable);
205 return (* iface->truncate_fn) (seekable, offset, cancellable, error);
208 #define __G_SEEKABLE_C__
209 #include "gioaliasdef.c"