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.
40 typedef GSeekableIface GSeekableInterface;
41 G_DEFINE_INTERFACE (GSeekable, g_seekable, G_TYPE_OBJECT)
44 g_seekable_default_init (GSeekableInterface *iface)
50 * @seekable: a #GSeekable.
52 * Tells the current position within the stream.
54 * Returns: the offset from the beginning of the buffer.
57 g_seekable_tell (GSeekable *seekable)
59 GSeekableIface *iface;
61 g_return_val_if_fail (G_IS_SEEKABLE (seekable), 0);
63 iface = G_SEEKABLE_GET_IFACE (seekable);
65 return (* iface->tell) (seekable);
69 * g_seekable_can_seek:
70 * @seekable: a #GSeekable.
72 * Tests if the stream supports the #GSeekableIface.
74 * Returns: %TRUE if @seekable can be seeked. %FALSE otherwise.
77 g_seekable_can_seek (GSeekable *seekable)
79 GSeekableIface *iface;
81 g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
83 iface = G_SEEKABLE_GET_IFACE (seekable);
85 return (* iface->can_seek) (seekable);
90 * @seekable: a #GSeekable.
91 * @offset: a #goffset.
92 * @type: a #GSeekType.
93 * @cancellable: optional #GCancellable object, %NULL to ignore.
94 * @error: a #GError location to store the error occuring, or %NULL to
97 * Seeks in the stream by the given @offset, modified by @type.
99 * If @cancellable is not %NULL, then the operation can be cancelled by
100 * triggering the cancellable object from another thread. If the operation
101 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
103 * Returns: %TRUE if successful. If an error
104 * has occurred, this function will return %FALSE and set @error
105 * appropriately if present.
108 g_seekable_seek (GSeekable *seekable,
111 GCancellable *cancellable,
114 GSeekableIface *iface;
116 g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
118 iface = G_SEEKABLE_GET_IFACE (seekable);
120 return (* iface->seek) (seekable, offset, type, cancellable, error);
124 * g_seekable_can_truncate:
125 * @seekable: a #GSeekable.
127 * Tests if the stream can be truncated.
129 * Returns: %TRUE if the stream can be truncated, %FALSE otherwise.
132 g_seekable_can_truncate (GSeekable *seekable)
134 GSeekableIface *iface;
136 g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
138 iface = G_SEEKABLE_GET_IFACE (seekable);
140 return (* iface->can_truncate) (seekable);
144 * g_seekable_truncate:
145 * @seekable: a #GSeekable.
146 * @offset: a #goffset.
147 * @cancellable: optional #GCancellable object, %NULL to ignore.
148 * @error: a #GError location to store the error occuring, or %NULL to
151 * Truncates a stream with a given #offset.
153 * If @cancellable is not %NULL, then the operation can be cancelled by
154 * triggering the cancellable object from another thread. If the operation
155 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an
156 * operation was partially finished when the operation was cancelled the
157 * partial result will be returned, without an error.
159 * Returns: %TRUE if successful. If an error
160 * has occurred, this function will return %FALSE and set @error
161 * appropriately if present.
164 g_seekable_truncate (GSeekable *seekable,
166 GCancellable *cancellable,
169 GSeekableIface *iface;
171 g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
173 iface = G_SEEKABLE_GET_IFACE (seekable);
175 return (* iface->truncate_fn) (seekable, offset, cancellable, error);
178 #define __G_SEEKABLE_C__
179 #include "gioaliasdef.c"