[PATCH] handle test method cancellation
- From: Christian Neumair <chris gnome-de org>
- To: "gnome-vfs-list gnome org" <gnome-vfs-list gnome org>
- Subject: [PATCH] handle test method cancellation
- Date: Fri, 11 Aug 2006 22:03:41 +0200
The attached patch should fix bug 46127 [1]
I don't know any elegant/readable construct preserving the const
modifiers. Any ideas?
[1] http://bugzilla.gnome.org/show_bug.cgi?id=46127
--
Christian Neumair <chris gnome-de org>
Index: modules/test-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/test-method.c,v
retrieving revision 1.20
diff -u -p -r1.20 test-method.c
--- modules/test-method.c 8 May 2005 13:04:05 -0000 1.20
+++ modules/test-method.c 11 Aug 2006 19:57:16 -0000
@@ -55,7 +55,7 @@
typedef struct {
char *operation_name;
- int delay;
+ unsigned int delay;
gboolean skip;
gboolean override_result;
GnomeVFSResult overridden_result_value;
@@ -154,7 +154,7 @@ translate_uri (GnomeVFSURI *uri)
and perform_operation will be TRUE if the operation should execute the underlying
operation anyway
*/
-static const OperationSettings *
+static OperationSettings *
get_operation_settings (const char *function_identifier)
{
static OperationSettings empty_settings;
@@ -171,22 +171,41 @@ get_operation_settings (const char *func
return &empty_settings;
}
-static const OperationSettings *
+static GnomeVFSResult
start_operation (const char *name,
+ OperationSettings **settings,
GnomeVFSURI **uri,
- GnomeVFSURI **saved_uri)
+ GnomeVFSURI **saved_uri,
+ GnomeVFSContext *context)
{
- const OperationSettings *settings;
+ GTimer *timer;
- settings = get_operation_settings (name);
+ *settings = get_operation_settings (name);
+
+ timer = g_timer_new ();
+ g_timer_start (timer);
+
+ /* sleep for 0.1 secs, and check cancellation each time
+ * . The overall sleep time might increase but this shouldn't
+ * be a problem, since this is a stress-testing method anyway.
+ */
+ while (g_timer_elapsed (timer, NULL) < (*settings)->delay / 1000) {
+ g_usleep (MIN ((*settings)->delay, 10) * 1000);
+
+ if (gnome_vfs_context_check_cancellation (context)) {
+ g_timer_destroy (timer);
+ return GNOME_VFS_ERROR_CANCELLED;
+ }
+ }
+
+ g_timer_destroy (timer);
- g_usleep (settings->delay * 1000);
-
if (uri != NULL) {
*saved_uri = *uri;
*uri = translate_uri (*uri);
}
- return settings;
+
+ return GNOME_VFS_OK;
}
static GnomeVFSResult
@@ -206,9 +225,9 @@ finish_operation (const OperationSetting
return result;
}
-#define PERFORM_OPERATION(name, operation) \
-do { \
- const OperationSettings *settings; \
+#define PERFORM_OPERATION(name, operation, context) \
+{ \
+ OperationSettings *settings; \
GnomeVFSURI *saved_uri; \
GnomeVFSResult result; \
\
@@ -216,35 +235,35 @@ do { \
return GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE; \
} \
\
- settings = start_operation (#name, &uri, &saved_uri); \
- if (settings->skip) { \
- result = GNOME_VFS_OK; \
- } else { \
+ result = start_operation (#name, &settings, &uri, &saved_uri, context); \
+ if (!settings->skip && result == GNOME_VFS_OK) { \
result = operation; \
+ result = finish_operation (settings, result, \
+ &uri, &saved_uri); \
} \
- return finish_operation (settings, result, \
- &uri, &saved_uri); \
-} while (0)
+ \
+ return result; \
+}
-#define PERFORM_OPERATION_NO_URI(name, operation) \
-do { \
- const OperationSettings *settings; \
+#define PERFORM_OPERATION_NO_URI(name, operation, context) \
+{ \
+ OperationSettings *settings; \
GnomeVFSResult result; \
\
if (!properly_initialized) { \
return GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE; \
} \
\
- settings = start_operation (#name, NULL, NULL); \
- if (settings->skip) { \
- result = GNOME_VFS_OK; \
- } else { \
+ result = start_operation (#name, &settings, NULL, NULL, context); \
+ if (!settings->skip && result == GNOME_VFS_OK) { \
result = operation; \
+ result = finish_operation (settings, result, \
+ NULL, NULL); \
} \
- return finish_operation (settings, result, \
- NULL, NULL); \
-} while (0)
+ \
+ return result; \
+}
static gboolean
parse_result_text (const char *result_text,
@@ -323,7 +342,7 @@ do_open (GnomeVFSMethod *method,
GnomeVFSOpenMode mode,
GnomeVFSContext *context)
{
- PERFORM_OPERATION (open, gnome_vfs_open_uri_cancellable ((GnomeVFSHandle **) method_handle, uri, mode, context));
+ PERFORM_OPERATION (open, gnome_vfs_open_uri_cancellable ((GnomeVFSHandle **) method_handle, uri, mode, context), context);
}
static GnomeVFSResult
@@ -344,7 +363,7 @@ do_close (GnomeVFSMethod *method,
GnomeVFSMethodHandle *method_handle,
GnomeVFSContext *context)
{
- PERFORM_OPERATION_NO_URI (close, gnome_vfs_close_cancellable ((GnomeVFSHandle *) method_handle, context));
+ PERFORM_OPERATION_NO_URI (close, gnome_vfs_close_cancellable ((GnomeVFSHandle *) method_handle, context), context);
}
static GnomeVFSResult
@@ -355,7 +374,7 @@ do_read (GnomeVFSMethod *method,
GnomeVFSFileSize *bytes_read,
GnomeVFSContext *context)
{
- PERFORM_OPERATION_NO_URI (read, gnome_vfs_read_cancellable ((GnomeVFSHandle *) method_handle, buffer, num_bytes, bytes_read, context));
+ PERFORM_OPERATION_NO_URI (read, gnome_vfs_read_cancellable ((GnomeVFSHandle *) method_handle, buffer, num_bytes, bytes_read, context), context);
}
static GnomeVFSResult
@@ -366,7 +385,7 @@ do_write (GnomeVFSMethod *method,
GnomeVFSFileSize *bytes_written,
GnomeVFSContext *context)
{
- PERFORM_OPERATION_NO_URI (write, gnome_vfs_write_cancellable((GnomeVFSHandle *) method_handle, buffer, num_bytes, bytes_written, context));
+ PERFORM_OPERATION_NO_URI (write, gnome_vfs_write_cancellable((GnomeVFSHandle *) method_handle, buffer, num_bytes, bytes_written, context), context);
}
static GnomeVFSResult
@@ -376,7 +395,7 @@ do_seek (GnomeVFSMethod *method,
GnomeVFSFileOffset offset,
GnomeVFSContext *context)
{
- PERFORM_OPERATION_NO_URI (seek, gnome_vfs_seek_cancellable ((GnomeVFSHandle *) method_handle, whence, offset, context));
+ PERFORM_OPERATION_NO_URI (seek, gnome_vfs_seek_cancellable ((GnomeVFSHandle *) method_handle, whence, offset, context), context);
}
static GnomeVFSResult
@@ -384,7 +403,7 @@ do_tell (GnomeVFSMethod *method,
GnomeVFSMethodHandle *method_handle,
GnomeVFSFileSize *offset_return)
{
- PERFORM_OPERATION_NO_URI (tell, gnome_vfs_tell ((GnomeVFSHandle *) method_handle, offset_return));
+ PERFORM_OPERATION_NO_URI (tell, gnome_vfs_tell ((GnomeVFSHandle *) method_handle, offset_return), NULL);
}
@@ -395,7 +414,7 @@ do_open_directory (GnomeVFSMethod *metho
GnomeVFSFileInfoOptions options,
GnomeVFSContext *context)
{
- PERFORM_OPERATION (open_directory, gnome_vfs_directory_open_from_uri ((GnomeVFSDirectoryHandle **) method_handle, uri, options));
+ PERFORM_OPERATION (open_directory, gnome_vfs_directory_open_from_uri ((GnomeVFSDirectoryHandle **) method_handle, uri, options), context);
}
static GnomeVFSResult
@@ -403,7 +422,7 @@ do_close_directory (GnomeVFSMethod *meth
GnomeVFSMethodHandle *method_handle,
GnomeVFSContext *context)
{
- PERFORM_OPERATION_NO_URI (close_directory, gnome_vfs_directory_close ((GnomeVFSDirectoryHandle *) method_handle));
+ PERFORM_OPERATION_NO_URI (close_directory, gnome_vfs_directory_close ((GnomeVFSDirectoryHandle *) method_handle), context);
}
static GnomeVFSResult
@@ -412,7 +431,7 @@ do_read_directory (GnomeVFSMethod *metho
GnomeVFSFileInfo *file_info,
GnomeVFSContext *context)
{
- PERFORM_OPERATION_NO_URI (read_directory, gnome_vfs_directory_read_next ((GnomeVFSDirectoryHandle *) method_handle, file_info));
+ PERFORM_OPERATION_NO_URI (read_directory, gnome_vfs_directory_read_next ((GnomeVFSDirectoryHandle *) method_handle, file_info), context);
}
static GnomeVFSResult
@@ -422,7 +441,7 @@ do_get_file_info (GnomeVFSMethod *method
GnomeVFSFileInfoOptions options,
GnomeVFSContext *context)
{
- PERFORM_OPERATION (get_file_info, gnome_vfs_get_file_info_uri_cancellable (uri, file_info, options, context));
+ PERFORM_OPERATION (get_file_info, gnome_vfs_get_file_info_uri_cancellable (uri, file_info, options, context), context);
}
static GnomeVFSResult
@@ -432,7 +451,7 @@ do_get_file_info_from_handle (GnomeVFSMe
GnomeVFSFileInfoOptions options,
GnomeVFSContext *context)
{
- PERFORM_OPERATION_NO_URI (get_file_info_from_handle, gnome_vfs_get_file_info_from_handle_cancellable ((GnomeVFSHandle *) method_handle, file_info, options, context));
+ PERFORM_OPERATION_NO_URI (get_file_info_from_handle, gnome_vfs_get_file_info_from_handle_cancellable ((GnomeVFSHandle *) method_handle, file_info, options, context), context);
}
static gboolean
@@ -449,7 +468,7 @@ do_make_directory (GnomeVFSMethod *metho
guint perm,
GnomeVFSContext *context)
{
- PERFORM_OPERATION (make_directory, gnome_vfs_make_directory_for_uri_cancellable (uri, perm, context));
+ PERFORM_OPERATION (make_directory, gnome_vfs_make_directory_for_uri_cancellable (uri, perm, context), context);
}
static GnomeVFSResult
@@ -457,7 +476,7 @@ do_remove_directory (GnomeVFSMethod *met
GnomeVFSURI *uri,
GnomeVFSContext *context)
{
- PERFORM_OPERATION (remove_directory, gnome_vfs_remove_directory_from_uri_cancellable (uri, context));
+ PERFORM_OPERATION (remove_directory, gnome_vfs_remove_directory_from_uri_cancellable (uri, context), context);
}
static GnomeVFSResult
@@ -476,7 +495,7 @@ do_unlink (GnomeVFSMethod *method,
GnomeVFSURI *uri,
GnomeVFSContext *context)
{
- PERFORM_OPERATION (unlink, gnome_vfs_unlink_from_uri_cancellable (uri, context));
+ PERFORM_OPERATION (unlink, gnome_vfs_unlink_from_uri_cancellable (uri, context), context);
}
static GnomeVFSResult
@@ -497,7 +516,7 @@ do_set_file_info (GnomeVFSMethod *method
GnomeVFSSetFileInfoMask mask,
GnomeVFSContext *context)
{
- PERFORM_OPERATION (set_file_info, gnome_vfs_set_file_info_cancellable (uri, info, mask, context));
+ PERFORM_OPERATION (set_file_info, gnome_vfs_set_file_info_cancellable (uri, info, mask, context), context);
}
static GnomeVFSResult
@@ -506,7 +525,7 @@ do_truncate (GnomeVFSMethod *method,
GnomeVFSFileSize where,
GnomeVFSContext *context)
{
- PERFORM_OPERATION (truncate, gnome_vfs_truncate_uri_cancellable (uri, where, context));
+ PERFORM_OPERATION (truncate, gnome_vfs_truncate_uri_cancellable (uri, where, context), context);
}
static GnomeVFSResult
@@ -515,7 +534,7 @@ do_truncate_handle (GnomeVFSMethod *meth
GnomeVFSFileSize where,
GnomeVFSContext *context)
{
- PERFORM_OPERATION_NO_URI (truncate_handle, gnome_vfs_truncate_handle_cancellable ((GnomeVFSHandle *) method_handle, where, context));
+ PERFORM_OPERATION_NO_URI (truncate_handle, gnome_vfs_truncate_handle_cancellable ((GnomeVFSHandle *) method_handle, where, context), context);
}
static GnomeVFSResult
@@ -528,7 +547,7 @@ do_find_directory (GnomeVFSMethod *metho
guint permissions,
GnomeVFSContext *context)
{
- PERFORM_OPERATION (find_directory, gnome_vfs_find_directory_cancellable (uri, kind, result_uri, create_if_needed, find_if_needed, permissions, context));
+ PERFORM_OPERATION (find_directory, gnome_vfs_find_directory_cancellable (uri, kind, result_uri, create_if_needed, find_if_needed, permissions, context), context);
}
static GnomeVFSResult
@@ -537,7 +556,7 @@ do_create_symbolic_link (GnomeVFSMethod
const char *target_reference,
GnomeVFSContext *context)
{
- PERFORM_OPERATION (create_symbolic_link, gnome_vfs_create_symbolic_link_cancellable (uri, target_reference, context));
+ PERFORM_OPERATION (create_symbolic_link, gnome_vfs_create_symbolic_link_cancellable (uri, target_reference, context), context);
}
static GnomeVFSMethod method = {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]