gvfs r2258 - in trunk: . client test
- From: alexl svn gnome org
- To: svn-commits-list gnome org
- Subject: gvfs r2258 - in trunk: . client test
- Date: Fri, 27 Feb 2009 13:20:23 +0000 (UTC)
Author: alexl
Date: Fri Feb 27 13:20:23 2009
New Revision: 2258
URL: http://svn.gnome.org/viewvc/gvfs?rev=2258&view=rev
Log:
2009-02-27 Alexander Larsson <alexl redhat com>
* client/gdaemonfileinputstream.c:
Support async query info
* test/test-query-info-stream.c:
Test async query info
Modified:
trunk/ChangeLog
trunk/client/gdaemonfileinputstream.c
trunk/test/test-query-info-stream.c
Modified: trunk/client/gdaemonfileinputstream.c
==============================================================================
--- trunk/client/gdaemonfileinputstream.c (original)
+++ trunk/client/gdaemonfileinputstream.c Fri Feb 27 13:20:23 2009
@@ -220,56 +220,66 @@
GString *output_buffer;
};
-static gssize g_daemon_file_input_stream_read (GInputStream *stream,
- void *buffer,
- gsize count,
- GCancellable *cancellable,
- GError **error);
-static gssize g_daemon_file_input_stream_skip (GInputStream *stream,
- gsize count,
- GCancellable *cancellable,
- GError **error);
-static gboolean g_daemon_file_input_stream_close (GInputStream *stream,
- GCancellable *cancellable,
- GError **error);
-static GFileInfo *g_daemon_file_input_stream_query_info (GFileInputStream *stream,
- char *attributes,
- GCancellable *cancellable,
- GError **error);
-static goffset g_daemon_file_input_stream_tell (GFileInputStream *stream);
-static gboolean g_daemon_file_input_stream_can_seek (GFileInputStream *stream);
-static gboolean g_daemon_file_input_stream_seek (GFileInputStream *stream,
- goffset offset,
- GSeekType type,
- GCancellable *cancellable,
- GError **error);
-static void g_daemon_file_input_stream_read_async (GInputStream *stream,
- void *buffer,
- gsize count,
- int io_priority,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer data);
-static gssize g_daemon_file_input_stream_read_finish (GInputStream *stream,
- GAsyncResult *result,
- GError **error);
-static void g_daemon_file_input_stream_skip_async (GInputStream *stream,
- gsize count,
- int io_priority,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer data);
-static gssize g_daemon_file_input_stream_skip_finish (GInputStream *stream,
- GAsyncResult *result,
- GError **error);
-static void g_daemon_file_input_stream_close_async (GInputStream *stream,
- int io_priority,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer data);
-static gboolean g_daemon_file_input_stream_close_finish (GInputStream *stream,
- GAsyncResult *result,
- GError **error);
+static gssize g_daemon_file_input_stream_read (GInputStream *stream,
+ void *buffer,
+ gsize count,
+ GCancellable *cancellable,
+ GError **error);
+static gssize g_daemon_file_input_stream_skip (GInputStream *stream,
+ gsize count,
+ GCancellable *cancellable,
+ GError **error);
+static gboolean g_daemon_file_input_stream_close (GInputStream *stream,
+ GCancellable *cancellable,
+ GError **error);
+static GFileInfo *g_daemon_file_input_stream_query_info (GFileInputStream *stream,
+ char *attributes,
+ GCancellable *cancellable,
+ GError **error);
+static goffset g_daemon_file_input_stream_tell (GFileInputStream *stream);
+static gboolean g_daemon_file_input_stream_can_seek (GFileInputStream *stream);
+static gboolean g_daemon_file_input_stream_seek (GFileInputStream *stream,
+ goffset offset,
+ GSeekType type,
+ GCancellable *cancellable,
+ GError **error);
+static void g_daemon_file_input_stream_read_async (GInputStream *stream,
+ void *buffer,
+ gsize count,
+ int io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer data);
+static gssize g_daemon_file_input_stream_read_finish (GInputStream *stream,
+ GAsyncResult *result,
+ GError **error);
+static void g_daemon_file_input_stream_skip_async (GInputStream *stream,
+ gsize count,
+ int io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer data);
+static gssize g_daemon_file_input_stream_skip_finish (GInputStream *stream,
+ GAsyncResult *result,
+ GError **error);
+static void g_daemon_file_input_stream_close_async (GInputStream *stream,
+ int io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer data);
+static gboolean g_daemon_file_input_stream_close_finish (GInputStream *stream,
+ GAsyncResult *result,
+ GError **error);
+static void g_daemon_file_input_stream_query_info_async (GFileInputStream *stream,
+ char *attributes,
+ int io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+static GFileInfo *g_daemon_file_input_stream_query_info_finish (GFileInputStream *stream,
+ GAsyncResult *result,
+ GError **error);
+
G_DEFINE_TYPE (GDaemonFileInputStream, g_daemon_file_input_stream,
@@ -347,6 +357,8 @@
file_stream_class->can_seek = g_daemon_file_input_stream_can_seek;
file_stream_class->seek = g_daemon_file_input_stream_seek;
file_stream_class->query_info = g_daemon_file_input_stream_query_info;
+ file_stream_class->query_info_async = g_daemon_file_input_stream_query_info_async;
+ file_stream_class->query_info_finish = g_daemon_file_input_stream_query_info_finish;
}
@@ -1606,6 +1618,7 @@
return op.info;
}
+
/************************************************************************
* Async I/O Code *
************************************************************************/
@@ -2008,3 +2021,96 @@
/* Failures handled in generic close_finish code */
return TRUE;
}
+
+static void
+async_query_done (GInputStream *stream,
+ gpointer op_data,
+ GAsyncReadyCallback callback,
+ gpointer user_data,
+ GError *io_error)
+{
+ GDaemonFileInputStream *file;
+ GSimpleAsyncResult *simple;
+ QueryOperation *op;
+ GFileInfo *info;
+ GError *error;
+
+ file = G_DAEMON_FILE_INPUT_STREAM (stream);
+
+ op = op_data;
+
+ if (io_error)
+ {
+ info = NULL;
+ error = io_error;
+ }
+ else
+ {
+ info = op->info;
+ error = op->ret_error;
+ }
+
+ simple = g_simple_async_result_new (G_OBJECT (stream),
+ callback, user_data,
+ g_daemon_file_input_stream_query_info_async);
+
+ if (info == NULL)
+ g_simple_async_result_set_from_error (simple, error);
+ else
+ g_simple_async_result_set_op_res_gpointer (simple, info,
+ g_object_unref);
+
+ /* Complete immediately, not in idle, since we're already in a mainloop callout */
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+
+ if (op->ret_error)
+ g_error_free (op->ret_error);
+ g_free (op->attributes);
+ g_free (op);
+}
+
+static void
+g_daemon_file_input_stream_query_info_async (GFileInputStream *stream,
+ char *attributes,
+ int io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GDaemonFileInputStream *file;
+ QueryOperation *op;
+
+ file = G_DAEMON_FILE_INPUT_STREAM (stream);
+
+ op = g_new0 (QueryOperation, 1);
+ op->state = QUERY_STATE_INIT;
+ if (attributes)
+ op->attributes = g_strdup (attributes);
+ else
+ op->attributes = g_strdup ("");
+
+ run_async_state_machine (file,
+ (state_machine_iterator)iterate_query_state_machine,
+ op, io_priority,
+ callback, user_data,
+ cancellable,
+ async_query_done);
+}
+
+static GFileInfo *
+g_daemon_file_input_stream_query_info_finish (GFileInputStream *stream,
+ GAsyncResult *result,
+ GError **error)
+{
+ GSimpleAsyncResult *simple;
+ GFileInfo *info;
+
+ simple = G_SIMPLE_ASYNC_RESULT (result);
+ g_assert (g_simple_async_result_get_source_tag (simple) == g_daemon_file_input_stream_query_info_async);
+
+ info = g_simple_async_result_get_op_res_gpointer (simple);
+
+ return g_object_ref (info);
+
+}
Modified: trunk/test/test-query-info-stream.c
==============================================================================
--- trunk/test/test-query-info-stream.c (original)
+++ trunk/test/test-query-info-stream.c Fri Feb 27 13:20:23 2009
@@ -39,6 +39,8 @@
* hide bugs */
#define DATA_MODULO 200
+static GMainLoop *main_loop;
+
static gboolean
verify_block (guchar *data, guchar *start, gsize size)
{
@@ -105,14 +107,11 @@
}
static void
-check_query_info (GFileInputStream *in)
+check_query_info_res (GFileInfo *info,
+ GError *error)
{
- GFileInfo *info;
- GError *error;
goffset file_size;
- error = NULL;
- info = g_file_input_stream_query_info (in, "*", NULL, &error);
if (info == NULL)
{
g_print ("error querying info: %s\n", error->message);
@@ -126,7 +125,6 @@
}
file_size = g_file_info_get_size (info);
- g_print ("file size: %d\n", (int)file_size);
if (file_size != 100*1000)
{
g_print ("wrong file size\n");
@@ -134,6 +132,37 @@
}
}
+
+static void
+check_query_info (GFileInputStream *in)
+{
+ GFileInfo *info;
+ GError *error;
+
+ error = NULL;
+ info = g_file_input_stream_query_info (in, "*", NULL, &error);
+
+ check_query_info_res (info, error);
+}
+
+static void
+async_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GFileInfo *info;
+ GError *error;
+
+ error = NULL;
+ info =
+ g_file_input_stream_query_info_finish (G_FILE_INPUT_STREAM (source_object),
+ res, &error);
+
+ check_query_info_res (info, error);
+
+ g_main_loop_quit (main_loop);
+}
+
int
main (int argc, char *argv[])
{
@@ -201,8 +230,6 @@
exit (1);
}
- g_print ("res: %d\n", (int)res);
-
if (!verify_block (buffer, &start, res))
{
g_print ("error in block starting at %d\n", (int)read_size);
@@ -220,7 +247,15 @@
g_print ("Didn't read entire file\n");
exit (1);
}
+
+ main_loop = g_main_loop_new (NULL, FALSE);
+ g_file_input_stream_query_info_async (in, "*",
+ 0, NULL,
+ async_cb, NULL);
+ g_main_loop_run (main_loop);
+
+ g_print ("ALL OK\n");
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]