本文整理汇总了C++中G_SEEKABLE函数的典型用法代码示例。如果您正苦于以下问题:C++ G_SEEKABLE函数的具体用法?C++ G_SEEKABLE怎么用?C++ G_SEEKABLE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了G_SEEKABLE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: xmms_gvfs_seek
static gint64
xmms_gvfs_seek (xmms_xform_t *xform, gint64 offset,
xmms_xform_seek_mode_t whence, xmms_error_t *error)
{
GSeekType type;
GError *err = NULL;
xmms_gvfs_data_t *data = xmms_xform_private_data_get (xform);
g_return_val_if_fail (data, -1);
g_return_val_if_fail (!g_input_stream_is_closed (data->handle), -1);
switch (whence) {
case XMMS_XFORM_SEEK_CUR:
type = G_SEEK_CUR;
break;
case XMMS_XFORM_SEEK_SET:
type = G_SEEK_SET;
break;
case XMMS_XFORM_SEEK_END:
type = G_SEEK_END;
break;
}
if (g_seekable_seek (G_SEEKABLE (data->handle), offset, type, NULL, &err)) {
return g_seekable_tell (G_SEEKABLE (data->handle));
}
xmms_error_set (error, XMMS_ERROR_GENERIC, err->message);
return -1;
}
示例2: try_seek_on_read
static gboolean
try_seek_on_read (GVfsBackend *backend,
GVfsJobSeekRead *job,
GVfsBackendHandle handle,
goffset offset,
GSeekType type)
{
GInputStream *stream;
GError *error = NULL;
stream = G_INPUT_STREAM (handle);
if (!g_seekable_seek (G_SEEKABLE (stream), offset, type,
G_VFS_JOB (job)->cancellable, &error))
{
g_vfs_job_failed_literal (G_VFS_JOB (job),
error->domain,
error->code,
error->message);
g_error_free (error);
return FALSE;
}
else
{
g_vfs_job_seek_read_set_offset (job, g_seekable_tell (G_SEEKABLE (stream)));
g_vfs_job_succeeded (G_VFS_JOB (job));
}
return TRUE;
}
示例3: extract_gibest_hash
static void
extract_gibest_hash (GTask *task,
gpointer source_object,
gpointer task_data,
GCancellable *cancellable)
{
GFile *file = source_object;
guint64 buffer[2][CHUNK_N_BYTES/8];
GInputStream *stream = NULL;
gssize n_bytes, file_size;
GError *error = NULL;
guint64 hash = 0;
gint i;
char *str;
ResolveData *resolve_data = task_data;
GrlLocalMetadataSourcePriv *priv;
priv = GRL_LOCAL_METADATA_SOURCE_GET_PRIVATE (resolve_data->source);
stream = G_INPUT_STREAM (g_file_read (file, cancellable, &error));
if (stream == NULL)
goto fail;
/* Extract start/end chunks of the file */
n_bytes = g_input_stream_read (stream, buffer[0], CHUNK_N_BYTES, cancellable, &error);
if (n_bytes == -1)
goto fail;
if (!g_seekable_seek (G_SEEKABLE (stream), -CHUNK_N_BYTES, G_SEEK_END, cancellable, &error))
goto fail;
n_bytes = g_input_stream_read (stream, buffer[1], CHUNK_N_BYTES, cancellable, &error);
if (n_bytes == -1)
goto fail;
for (i = 0; i < G_N_ELEMENTS (buffer[0]); i++)
hash += buffer[0][i] + buffer[1][i];
file_size = g_seekable_tell (G_SEEKABLE (stream));
if (file_size < CHUNK_N_BYTES)
goto fail;
/* Include file size */
hash += file_size;
g_object_unref (stream);
str = g_strdup_printf ("%" G_GINT64_FORMAT, hash);
grl_data_set_string (GRL_DATA (resolve_data->rs->media), priv->hash_keyid, str);
g_free (str);
g_task_return_boolean (task, TRUE);
return;
fail:
GRL_DEBUG ("Could not get file hash: %s\n", error ? error->message : "Unknown error");
g_task_return_error (task, error);
g_clear_object (&stream);
}
示例4: ddb_gvfs_rewind
static void
ddb_gvfs_rewind (DB_FILE *stream)
{
vfs_gvfs_data_t *data = (vfs_gvfs_data_t *) stream;
g_return_if_fail (data != NULL);
if (g_seekable_can_seek (G_SEEKABLE (data->handle)))
g_seekable_seek (G_SEEKABLE (data->handle), 0, G_SEEK_SET, NULL, NULL);
}
示例5: test_message_compare
gint
test_message_compare (CamelMimeMessage *msg)
{
CamelMimeMessage *msg2;
CamelStream *stream1;
CamelStream *stream2;
GByteArray *byte_array1;
GByteArray *byte_array2;
byte_array1 = g_byte_array_new ();
stream1 = camel_stream_mem_new_with_byte_array (byte_array1);
check_msg (camel_data_wrapper_write_to_stream_sync (
CAMEL_DATA_WRAPPER (msg), stream1, NULL, NULL) != -1,
"write_to_stream 1 failed", NULL);
g_seekable_seek (G_SEEKABLE (stream1), 0, G_SEEK_SET, NULL, NULL);
msg2 = camel_mime_message_new ();
check_msg (camel_data_wrapper_construct_from_stream_sync (
CAMEL_DATA_WRAPPER (msg2), stream1, NULL, NULL) != -1,
"construct_from_stream 1 failed");
g_seekable_seek (G_SEEKABLE (stream1), 0, G_SEEK_SET, NULL, NULL);
byte_array2 = g_byte_array_new ();
stream2 = camel_stream_mem_new_with_byte_array (byte_array2);
check_msg (camel_data_wrapper_write_to_stream_sync (
CAMEL_DATA_WRAPPER (msg2), stream2, NULL, NULL) != -1,
"write_to_stream 2 failed");
g_seekable_seek (G_SEEKABLE (stream2), 0, G_SEEK_SET, NULL, NULL);
if (byte_array1->len != byte_array2->len) {
CamelDataWrapper *content;
printf ("stream1 stream:\n%.*s\n", byte_array1->len, byte_array1->data);
printf ("stream2 stream:\n%.*s\n\n", byte_array2->len, byte_array2->data);
printf ("msg1:\n");
test_message_dump_structure (msg);
printf ("msg2:\n");
test_message_dump_structure (msg2);
content = camel_medium_get_content ((CamelMedium *) msg);
}
check_unref (msg2, 1);
check_msg (
byte_array1->len == byte_array2->len,
"byte_array1->len = %d, byte_array2->len = %d",
byte_array1->len, byte_array2->len);
check_msg (memcmp (byte_array1->data, byte_array2->data, byte_array1->len) == 0, "msg/stream compare");
g_object_unref (stream1);
g_object_unref (stream2);
return 0;
}
示例6: vfs_data_seek
/* Called from gpgme to seek a file */
static off_t
vfs_data_seek (void *handle, off_t offset, int whence)
{
VfsAsyncHandle* ah = (VfsAsyncHandle*)handle;
GSeekable *seekable = NULL;
GSeekType wh;
/* If the file isn't open yet, then do that now */
if (!ah->ostream && !ah->istream && ah->state == VFS_ASYNC_READY)
vfs_data_open_helper (ah);
/* Just in case we have an operation, like open */
if (!vfs_data_wait_results(ah, TRUE))
return (off_t)-1;
g_assert (ah->state == VFS_ASYNC_READY);
if (ah->writer && G_IS_SEEKABLE (ah->ostream))
seekable = G_SEEKABLE (ah->ostream);
else
seekable = G_SEEKABLE (ah->istream);
if (!seekable || !g_seekable_can_seek (seekable)) {
errno = ENOTSUP;
return -1;
}
switch(whence)
{
case SEEK_SET:
wh = G_SEEK_SET;
break;
case SEEK_CUR:
wh = G_SEEK_CUR;
break;
case SEEK_END:
wh = G_SEEK_END;
break;
default:
g_assert_not_reached();
break;
}
/* All seek operations are not async */
g_clear_error (&ah->error);
g_seekable_seek (seekable, (goffset)offset, wh, ah->cancellable, &ah->error);
/* Start async operation */
ah->state = VFS_ASYNC_READY;
if (!vfs_data_wait_results (ah, TRUE))
return -1;
/* Return results */
ah->state = VFS_ASYNC_READY;
return offset;
}
示例7: seek_in_stream
static toff_t
seek_in_stream(thandle_t handle,
toff_t offset,
int whence)
{
Priv *p = (Priv*) handle;
GError *error = NULL;
gboolean sought = FALSE;
goffset position = -1;
g_assert(p->stream);
if (p->can_seek)
{
sought = g_seekable_seek(G_SEEKABLE(p->stream),
(goffset) offset, lseek_to_seek_type(whence),
NULL, &error);
if (sought)
position = g_seekable_tell(G_SEEKABLE(p->stream));
else
{
g_warning("%s", error->message);
g_error_free(error);
}
}
else
{
switch (whence)
{
default:
case SEEK_SET:
if (offset <= p->allocated)
position = p->position = offset;
break;
case SEEK_CUR:
if (p->position + offset <= p->allocated)
position = p->position += offset;
break;
case G_SEEK_END:
position = p->position = p->allocated + offset;
break;
}
}
return (toff_t) position;
}
示例8: seahorse_util_read_to_memory
/**
* seahorse_util_read_to_memory:
* @input: Data to read. The #GInputStream is read till the end.
* @len: Length of the data read (out)
*
* Reads data from the input stream and returns them as #guchar
*
* Returns: The string read from data. The returned string should be freed
* with #g_free when no longer needed.
**/
guchar*
seahorse_util_read_to_memory (GInputStream *input, guint *len)
{
gsize size = 128;
gchar *buffer, *text;
gsize nread = 0;
GString *string;
GSeekable *seek;
if (G_IS_SEEKABLE (input)) {
seek = G_SEEKABLE (input);
g_seekable_seek (seek, 0, SEEK_SET, NULL, NULL);
}
string = g_string_new ("");
buffer = g_new (gchar, size);
while (g_input_stream_read_all (input, buffer, size, &nread, NULL, NULL)) {
string = g_string_append_len (string, buffer, nread);
if (nread != size)
break;
}
if (len)
*len = string->len;
text = g_string_free (string, FALSE);
g_free (buffer);
return (guchar*)text;
}
示例9: cache_replace_ready_cb
static void
cache_replace_ready_cb (GObject *source,
GAsyncResult *res,
gpointer user_data)
{
GFileOutputStream *cache_stream;
GError *error = NULL;
NemoPreviewCoverArtFetcher *self = user_data;
cache_stream = g_file_replace_finish (G_FILE (source),
res, &error);
if (error != NULL) {
g_warning ("Can't save the cover art image in the cache: %s\n", error->message);
g_error_free (error);
return;
}
g_seekable_seek (G_SEEKABLE (self->priv->input_stream), 0, G_SEEK_SET,
NULL, NULL);
g_output_stream_splice_async (G_OUTPUT_STREAM (cache_stream),
self->priv->input_stream,
G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE |
G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
G_PRIORITY_DEFAULT,
NULL,
cache_splice_ready_cb, self);
g_object_unref (cache_stream);
}
示例10: gegl_tile_backend_file_write_header
static gboolean
gegl_tile_backend_file_write_header (GeglTileBackendFile *self)
{
gboolean success;
gegl_tile_backend_file_ensure_exist (self);
#if HAVE_GIO
success = g_seekable_seek (G_SEEKABLE (self->o), 0, G_SEEK_SET,
NULL, NULL);
#else
success = (lseek (self->o, 0, SEEK_SET) != -1);
#endif
if (success == FALSE)
{
g_warning ("unable to seek in buffer");
return FALSE;
}
#if HAVE_GIO
g_output_stream_write (self->o, &(self->header), 256, NULL, NULL);
#else
write (self->o, &(self->header), 256);
#endif
GEGL_NOTE (GEGL_DEBUG_TILE_BACKEND, "Wrote header, next=%i", (gint)self->header.next);
return TRUE;
}
示例11: gimp_curves_tool_settings_import
static gboolean
gimp_curves_tool_settings_import (GimpImageMapTool *image_map_tool,
GInputStream *input,
GError **error)
{
GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
gchar header[64];
gsize bytes_read;
if (! g_input_stream_read_all (input, header, sizeof (header),
&bytes_read, NULL, error) ||
bytes_read != sizeof (header))
{
g_prefix_error (error, _("Could not read header: "));
return FALSE;
}
g_seekable_seek (G_SEEKABLE (input), 0, G_SEEK_SET, NULL, NULL);
if (g_str_has_prefix (header, "# GIMP Curves File\n"))
return gimp_curves_config_load_cruft (tool->config, input, error);
return GIMP_IMAGE_MAP_TOOL_CLASS (parent_class)->settings_import (image_map_tool,
input,
error);
}
示例12: et_ogg_tell_func
/*
* et_ogg_tell_func:
* @datasource: the Ogg parser state
*
* Tell the current position of the stream from the beginning of the Ogg file.
*
* Returns: the current position in the Ogg file
*/
static long
et_ogg_tell_func (void *datasource)
{
EtOggState *state = (EtOggState *)datasource;
return g_seekable_tell (G_SEEKABLE (state->istream));
}
示例13: gst_gio_base_sink_event
static gboolean
gst_gio_base_sink_event (GstBaseSink * base_sink, GstEvent * event)
{
GstGioBaseSink *sink = GST_GIO_BASE_SINK (base_sink);
GstFlowReturn ret = GST_FLOW_OK;
if (sink->stream == NULL)
return TRUE;
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_SEGMENT:
if (G_IS_OUTPUT_STREAM (sink->stream)) {
const GstSegment *segment;
gst_event_parse_segment (event, &segment);
if (segment->format != GST_FORMAT_BYTES) {
GST_WARNING_OBJECT (sink, "ignored SEGMENT event in %s format",
gst_format_get_name (segment->format));
break;
}
if (GST_GIO_STREAM_IS_SEEKABLE (sink->stream)) {
ret = gst_gio_seek (sink, G_SEEKABLE (sink->stream), segment->start,
sink->cancel);
if (ret == GST_FLOW_OK)
sink->position = segment->start;
} else {
ret = GST_FLOW_NOT_SUPPORTED;
}
}
break;
case GST_EVENT_EOS:
case GST_EVENT_FLUSH_START:
if (G_IS_OUTPUT_STREAM (sink->stream)) {
gboolean success;
GError *err = NULL;
success = g_output_stream_flush (sink->stream, sink->cancel, &err);
if (!success && !gst_gio_error (sink, "g_output_stream_flush", &err,
&ret)) {
GST_ELEMENT_ERROR (sink, RESOURCE, WRITE, (NULL),
("flush failed: %s", err->message));
g_clear_error (&err);
}
}
break;
default:
break;
}
if (ret == GST_FLOW_OK)
return GST_BASE_SINK_CLASS (parent_class)->event (base_sink, event);
else {
gst_event_unref (event);
return FALSE;
}
}
示例14: on_file_read_ready
static void on_file_read_ready (GObject * object, GAsyncResult * res, gpointer data)
{
GError *error = NULL;
GDownloadable *download = G_DOWNLOADABLE (data);
GioDownload *gio_download = GIO_DOWNLOAD (data);
g_assert (download != NULL);
gio_download->priv->input = g_file_read_finish (G_FILE(object), res, &error);
handle_critical_error (error);
if (gio_download->priv->input == NULL) {
// TODO: Error details
g_downloadable_set_status (download, G_DOWNLOADABLE_NETWORK_ERROR);
} else {
if (g_seekable_can_seek(G_SEEKABLE(gio_download->priv->input))
&& g_file_query_exists (download->priv->local_file, NULL)) {
//g_message ("appeding file ...\n");
g_file_append_to_async (download->priv->local_file, 0,G_PRIORITY_DEFAULT,
NULL, on_file_append_to_ready, download);
} else {
//g_message ("replacing file ...\n");
g_file_replace_async (download->priv->local_file, NULL, FALSE, 0, G_PRIORITY_DEFAULT,
NULL, on_file_replace_ready, download);
}
g_downloadable_set_status (download, G_DOWNLOADABLE_DOWNLOADING);
}
}
示例15: gst_gio_base_src_start
static gboolean
gst_gio_base_src_start (GstBaseSrc * base_src)
{
GstGioBaseSrc *src = GST_GIO_BASE_SRC (base_src);
GstGioBaseSrcClass *gbsrc_class = GST_GIO_BASE_SRC_GET_CLASS (src);
src->position = 0;
/* FIXME: This will likely block */
src->stream = gbsrc_class->get_stream (src);
if (G_UNLIKELY (!G_IS_INPUT_STREAM (src->stream))) {
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
("No input stream provided by subclass"));
return FALSE;
} else if (G_UNLIKELY (g_input_stream_is_closed (src->stream))) {
GST_ELEMENT_ERROR (src, LIBRARY, FAILED, (NULL),
("Input stream is already closed"));
return FALSE;
}
if (G_IS_SEEKABLE (src->stream))
src->position = g_seekable_tell (G_SEEKABLE (src->stream));
GST_DEBUG_OBJECT (src, "started source");
return TRUE;
}