2007-11-26 17:13:05 +01:00
|
|
|
/* GIO - GLib Input, Output and Streaming Library
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006-2007 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General
|
|
|
|
* Public License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* Author: Alexander Larsson <alexl@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2008-06-22 17:10:51 +02:00
|
|
|
#include "config.h"
|
2007-11-26 17:13:05 +01:00
|
|
|
#include "gseekable.h"
|
|
|
|
#include "glibintl.h"
|
|
|
|
|
2007-11-28 13:39:07 +01:00
|
|
|
#include "gioalias.h"
|
|
|
|
|
2007-11-27 15:00:13 +01:00
|
|
|
/**
|
|
|
|
* SECTION:gseekable
|
2007-11-28 07:43:33 +01:00
|
|
|
* @short_description: Stream seeking interface
|
2008-02-21 19:20:17 +01:00
|
|
|
* @include: gio/gio.h
|
2007-11-28 07:43:33 +01:00
|
|
|
* @see_also: #GInputStream, #GOutputStream
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
|
|
|
* #GSeekable is implemented by streams (implementations of
|
|
|
|
* #GInputStream or #GOutputStream) that support seeking.
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
static void g_seekable_base_init (gpointer g_class);
|
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
g_seekable_get_type (void)
|
|
|
|
{
|
|
|
|
static GType seekable_type = 0;
|
|
|
|
|
2007-11-30 06:11:25 +01:00
|
|
|
if (!seekable_type)
|
2007-11-26 17:13:05 +01:00
|
|
|
{
|
|
|
|
static const GTypeInfo seekable_info =
|
|
|
|
{
|
|
|
|
sizeof (GSeekableIface), /* class_size */
|
|
|
|
g_seekable_base_init, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
|
|
|
NULL,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
0,
|
|
|
|
0, /* n_preallocs */
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
seekable_type =
|
|
|
|
g_type_register_static (G_TYPE_INTERFACE, I_("GSeekable"),
|
|
|
|
&seekable_info, 0);
|
|
|
|
|
|
|
|
g_type_interface_add_prerequisite (seekable_type, G_TYPE_OBJECT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return seekable_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_seekable_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_seekable_tell:
|
2007-11-27 15:00:13 +01:00
|
|
|
* @seekable: a #GSeekable.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* Tells the current position within the stream.
|
|
|
|
*
|
|
|
|
* Returns: the offset from the beginning of the buffer.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
goffset
|
|
|
|
g_seekable_tell (GSeekable *seekable)
|
|
|
|
{
|
|
|
|
GSeekableIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_SEEKABLE (seekable), 0);
|
|
|
|
|
|
|
|
iface = G_SEEKABLE_GET_IFACE (seekable);
|
|
|
|
|
|
|
|
return (* iface->tell) (seekable);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_seekable_can_seek:
|
2007-11-27 15:00:13 +01:00
|
|
|
* @seekable: a #GSeekable.
|
|
|
|
*
|
|
|
|
* Tests if the stream supports the #GSeekableIface.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if @seekable can be seeked. %FALSE otherwise.
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
g_seekable_can_seek (GSeekable *seekable)
|
|
|
|
{
|
|
|
|
GSeekableIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
|
|
|
|
|
|
|
|
iface = G_SEEKABLE_GET_IFACE (seekable);
|
|
|
|
|
|
|
|
return (* iface->can_seek) (seekable);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_seekable_seek:
|
2007-11-27 15:00:13 +01:00
|
|
|
* @seekable: a #GSeekable.
|
|
|
|
* @offset: a #goffset.
|
|
|
|
* @type: a #GSeekType.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @error: a #GError location to store the error occuring, or %NULL to
|
|
|
|
* ignore.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
|
|
|
* Seeks in the stream by the given @offset, modified by @type.
|
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if successful. If an error
|
2008-01-16 21:00:23 +01:00
|
|
|
* has occurred, this function will return %FALSE and set @error
|
2007-11-30 06:11:25 +01:00
|
|
|
* appropriately if present.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
g_seekable_seek (GSeekable *seekable,
|
|
|
|
goffset offset,
|
|
|
|
GSeekType type,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GSeekableIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
|
|
|
|
|
|
|
|
iface = G_SEEKABLE_GET_IFACE (seekable);
|
|
|
|
|
|
|
|
return (* iface->seek) (seekable, offset, type, cancellable, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_seekable_can_truncate:
|
2007-11-27 15:00:13 +01:00
|
|
|
* @seekable: a #GSeekable.
|
|
|
|
*
|
|
|
|
* Tests if the stream can be truncated.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* Returns: %TRUE if the stream can be truncated, %FALSE otherwise.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
g_seekable_can_truncate (GSeekable *seekable)
|
|
|
|
{
|
|
|
|
GSeekableIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
|
|
|
|
|
|
|
|
iface = G_SEEKABLE_GET_IFACE (seekable);
|
|
|
|
|
|
|
|
return (* iface->can_truncate) (seekable);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_seekable_truncate:
|
2007-11-27 15:00:13 +01:00
|
|
|
* @seekable: a #GSeekable.
|
|
|
|
* @offset: a #goffset.
|
2007-11-26 17:13:05 +01:00
|
|
|
* @cancellable: optional #GCancellable object, %NULL to ignore.
|
|
|
|
* @error: a #GError location to store the error occuring, or %NULL to
|
|
|
|
* ignore.
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
|
|
|
* Truncates a stream with a given #offset.
|
|
|
|
*
|
|
|
|
* If @cancellable is not %NULL, then the operation can be cancelled by
|
|
|
|
* triggering the cancellable object from another thread. If the operation
|
|
|
|
* was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an
|
|
|
|
* operation was partially finished when the operation was cancelled the
|
|
|
|
* partial result will be returned, without an error.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if successful. If an error
|
2008-01-16 21:00:23 +01:00
|
|
|
* has occurred, this function will return %FALSE and set @error
|
2007-11-30 06:11:25 +01:00
|
|
|
* appropriately if present.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
g_seekable_truncate (GSeekable *seekable,
|
|
|
|
goffset offset,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GSeekableIface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_SEEKABLE (seekable), FALSE);
|
|
|
|
|
|
|
|
iface = G_SEEKABLE_GET_IFACE (seekable);
|
|
|
|
|
2007-12-05 11:38:03 +01:00
|
|
|
return (* iface->truncate_fn) (seekable, offset, cancellable, error);
|
2007-11-26 17:13:05 +01:00
|
|
|
}
|
|
|
|
|
2007-11-28 13:39:07 +01:00
|
|
|
#define __G_SEEKABLE_C__
|
|
|
|
#include "gioaliasdef.c"
|