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 volatile gsize g_define_type_id__volatile = 0;
49 if (g_once_init_enter (&g_define_type_id__volatile))
51 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 */
63 GType g_define_type_id =
64 g_type_register_static (G_TYPE_INTERFACE, I_("GSeekable"),
67 g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_OBJECT);
69 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
72 return g_define_type_id__volatile;
76 g_seekable_base_init (gpointer g_class)
82 * @seekable: a #GSeekable.
84 * Tells the current position within the stream.
86 * Returns: the offset from the beginning of the buffer.
89 g_seekable_tell (GSeekable *seekable)
91 GSeekableIface *iface;
93 g_return_val_if_fail (G_IS_SEEKABLE (seekable), 0);
95 iface = G_SEEKABLE_GET_IFACE (seekable);
97 return (* iface->tell) (seekable);
101 * g_seekable_can_seek:
102 * @seekable: a #GSeekable.
104 * Tests if the stream supports the #GSeekableIface.
106 * Returns: %TRUE if @seekable can be seeked. %FALSE otherwise.
109 g_seekable_can_seek (GSeekable *seekable)
111 GSeekableIface *iface;
113 g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
115 iface = G_SEEKABLE_GET_IFACE (seekable);
117 return (* iface->can_seek) (seekable);
122 * @seekable: a #GSeekable.
123 * @offset: a #goffset.
124 * @type: a #GSeekType.
125 * @cancellable: optional #GCancellable object, %NULL to ignore.
126 * @error: a #GError location to store the error occuring, or %NULL to
129 * Seeks in the stream by the given @offset, modified by @type.
131 * If @cancellable is not %NULL, then the operation can be cancelled by
132 * triggering the cancellable object from another thread. If the operation
133 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
135 * Returns: %TRUE if successful. If an error
136 * has occurred, this function will return %FALSE and set @error
137 * appropriately if present.
140 g_seekable_seek (GSeekable *seekable,
143 GCancellable *cancellable,
146 GSeekableIface *iface;
148 g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
150 iface = G_SEEKABLE_GET_IFACE (seekable);
152 return (* iface->seek) (seekable, offset, type, cancellable, error);
156 * g_seekable_can_truncate:
157 * @seekable: a #GSeekable.
159 * Tests if the stream can be truncated.
161 * Returns: %TRUE if the stream can be truncated, %FALSE otherwise.
164 g_seekable_can_truncate (GSeekable *seekable)
166 GSeekableIface *iface;
168 g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
170 iface = G_SEEKABLE_GET_IFACE (seekable);
172 return (* iface->can_truncate) (seekable);
176 * g_seekable_truncate:
177 * @seekable: a #GSeekable.
178 * @offset: a #goffset.
179 * @cancellable: optional #GCancellable object, %NULL to ignore.
180 * @error: a #GError location to store the error occuring, or %NULL to
183 * Truncates a stream with a given #offset.
185 * If @cancellable is not %NULL, then the operation can be cancelled by
186 * triggering the cancellable object from another thread. If the operation
187 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an
188 * operation was partially finished when the operation was cancelled the
189 * partial result will be returned, without an error.
191 * Returns: %TRUE if successful. If an error
192 * has occurred, this function will return %FALSE and set @error
193 * appropriately if present.
196 g_seekable_truncate (GSeekable *seekable,
198 GCancellable *cancellable,
201 GSeekableIface *iface;
203 g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
205 iface = G_SEEKABLE_GET_IFACE (seekable);
207 return (* iface->truncate_fn) (seekable, offset, cancellable, error);
210 #define __G_SEEKABLE_C__
211 #include "gioaliasdef.c"