[maemo-commits] [maemo-commits] r15159 - projects/haf/trunk/osso-gnomevfs-extra/obex-module/src

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Fri Feb 8 18:50:03 EET 2008
Author: marivoll
Date: 2008-02-08 18:50:00 +0200 (Fri, 08 Feb 2008)
New Revision: 15159

Modified:
   projects/haf/trunk/osso-gnomevfs-extra/obex-module/src/obex-method.c
   projects/haf/trunk/osso-gnomevfs-extra/obex-module/src/om-utils.c
Log:
2008-01-23  Richard Hult  <richard at imendio.com>

	* obex-module/src/obex-method.c: (do_close): Send abort through
	gwobex API, if cancelled.
	(do_read), (do_write):
	(do_open_directory), (om_get_file_info_helper), (do_get_file_info),
	(do_get_file_info_from_handle): Try to return early if cancelled.

	* obex-module/src/om-utils.c: (om_utils_obex_error_to_vfs_result):
	Add human readable errors for the rest of the GW_* error codes.


Modified: projects/haf/trunk/osso-gnomevfs-extra/obex-module/src/obex-method.c
===================================================================
--- projects/haf/trunk/osso-gnomevfs-extra/obex-module/src/obex-method.c	2008-02-08 16:10:47 UTC (rev 15158)
+++ projects/haf/trunk/osso-gnomevfs-extra/obex-module/src/obex-method.c	2008-02-08 16:50:00 UTC (rev 15159)
@@ -900,19 +900,56 @@
 	result = GNOME_VFS_OK;
 	handle = (FileHandle *) method_handle;
 
-	/* Cancellation context is not used in this function */
-
 	conn = om_get_connection (handle->uri, &result);
 	if (conn == NULL) {
 		return result;
 	}
 
-	dv(g_printerr ("do_close: calling gw_obex_xfer_close()\n"));
+	if (handle->xfer) {
+		d(g_printerr ("obex, do_close: checking cancellation\n"));
 
-	if (handle->xfer) {
-		success = gw_obex_xfer_close (handle->xfer, &error);
+		if (gnome_vfs_context_check_cancellation (context)) {
+			/* We need this because gw_obex_xfer_abort triggers
+			 * gw_obex_xfer_close, which in turns does some
+			 * communication with the phone, where we need the
+			 * cancellation to get picked up again. NOTE: This
+			 * probably doesn't help since gwobex is used in
+			 * blocking mode.
+			 */
+			if (handle->mode & GNOME_VFS_OPEN_WRITE) {
+				om_set_cancel_context (conn, context);
+
+				/* For some reason that we haven't been able to find (a
+				 * race in gwobex?) we must sleep a bit before trying to
+				 * abort, otherwise the abort call has no effect.
+				 */
+				g_usleep (0.5*G_USEC_PER_SEC);
+
+				d(g_printerr ("obex, do_close: try sending abort\n"));
+				gw_obex_xfer_abort (handle->xfer, &error);
+				d(g_printerr ("obex, do_close: after sending abort: %d\n", error));
+
+				om_set_cancel_context (conn, NULL);
+			} else {
+				/* Just closing is enough to abort nicely when
+				 * in read mode.
+				 */
+				d(g_printerr ("do_close: read mode, just closing\n"));
+				om_set_cancel_context (conn, context);
+				gw_obex_xfer_close (handle->xfer, &error);
+				om_set_cancel_context (conn, NULL);
+			}
+
+			/* Ignore any error, we always want "abort", which
+			 * translates to GNOME_VFS_ERROR_CANCELLED.
+			 */
+			success = FALSE;
+			error = GW_OBEX_ERROR_ABORT;
+		} else {
+			success = gw_obex_xfer_close (handle->xfer, &error);
+		}
+
 		gw_obex_xfer_free (handle->xfer);
-
 		handle->xfer = NULL;
 	} else {
 		success = TRUE;
@@ -959,8 +996,16 @@
 
 	handle = (FileHandle *) method_handle;
 
-	/* Cancellation context is not used in this function */
+	*bytes_read = 0;
 
+	/* If cancelled, we return directly. The obex aborting is done in
+	 * close(), which must be called anyway. This simplifies the code a lot.
+	 */
+	if (gnome_vfs_context_check_cancellation (context)) {
+		d(g_printerr ("do_read: returning directly, cancelled\n"));
+		return GNOME_VFS_ERROR_CANCELLED;
+	}
+
 	if (!handle->xfer) {
 		if (handle->has_eof) {
 			return GNOME_VFS_ERROR_EOF;
@@ -1029,7 +1074,7 @@
 
 	handle = (FileHandle *) method_handle;
 
-	/* Cancellation context is not used here */
+	*bytes_written = 0;
 
 	if (!handle->xfer) {
 		return GNOME_VFS_ERROR_NOT_OPEN;
@@ -1039,6 +1084,14 @@
 		return GNOME_VFS_ERROR_READ_ONLY;
 	}
 
+	/* If cancelled, we return directly. The obex aborting is done in
+	 * close(), which must be called anyway. This simplifies the code a lot.
+	 */
+	if (gnome_vfs_context_check_cancellation (context)) {
+		d(g_printerr ("do_write: returning directly, cancelled\n"));
+		return GNOME_VFS_ERROR_CANCELLED;
+	}
+
 	conn = om_get_connection (handle->uri, &result);
 	if (conn == NULL) {
 		return result;
@@ -1058,7 +1111,7 @@
 
 		return om_utils_obex_error_to_vfs_result (error);
 	}
-	
+
 	dv(g_printerr ("%d bytes written\n", b_written));
 	*bytes_written = b_written;
 
@@ -1084,6 +1137,10 @@
 	GList           *elements = NULL;
 	DirectoryHandle *handle;
 
+	if (gnome_vfs_context_check_cancellation (context)) {
+		return GNOME_VFS_ERROR_CANCELLED;
+	}
+
 	if (om_uri_is_virtual_obex_root (uri)) {
 		/* We can't support following symlinks in open_directory since
 		 * the URI is different, just not the path.
@@ -1249,6 +1306,10 @@
 		  GnomeVFSFileInfoOptions  options,
 		  GnomeVFSContext         *context)
 {
+	if (gnome_vfs_context_check_cancellation (context)) {
+		return GNOME_VFS_ERROR_CANCELLED;
+	}
+
 	/* Special-case the obex:/// root, which is a virtual root containin
 	 * symlinks to the paired devices.
 	 */
@@ -1358,7 +1419,7 @@
 	FileHandle *handle;
 	
 	handle = (FileHandle *) method_handle;
-	
+
 	return do_get_file_info (method, handle->uri, file_info, 
 				 options, context);
 }

Modified: projects/haf/trunk/osso-gnomevfs-extra/obex-module/src/om-utils.c
===================================================================
--- projects/haf/trunk/osso-gnomevfs-extra/obex-module/src/om-utils.c	2008-02-08 16:10:47 UTC (rev 15158)
+++ projects/haf/trunk/osso-gnomevfs-extra/obex-module/src/om-utils.c	2008-02-08 16:50:00 UTC (rev 15159)
@@ -28,7 +28,7 @@
 
 #include "om-utils.h"
 
-#define d(x) 
+#define d(x) x
 
 
 /* Note: Uses URIs on the form:
@@ -285,30 +285,39 @@
 		/* We get this when trying to move a file on Nokia 6230 and
 		 * HP iPaq, does it mean that it's not a supported action?
 		 */
+		d(g_printerr ("Error: RSP_BAD_REQUEST\n"));
 		return GNOME_VFS_ERROR_NOT_SUPPORTED;
 
 	case OBEX_RSP_FORBIDDEN: /* 0x43 */
+		d(g_printerr ("Error: RSP_FORBIDDEN\n"));
 		return GNOME_VFS_ERROR_NOT_PERMITTED;
 
 	case OBEX_RSP_NOT_FOUND: /* 0x44 */
+		d(g_printerr ("Error: RSP_NOT_FOUND\n"));
 		return GNOME_VFS_ERROR_NOT_FOUND;
 
 	case OBEX_RSP_REQUEST_TIME_OUT: /* 0x48 */
+		d(g_printerr ("Error: RSP_REQUEST_TIME_OUT\n"));
 		return GNOME_VFS_ERROR_IO;
 
 	case OBEX_RSP_NOT_ACCEPTABLE: /* 0x46 */
+		d(g_printerr ("Error: RSP_NOT_ACCEPTABLE\n"));
 		return GNOME_VFS_ERROR_NOT_PERMITTED;
 		
 	case OBEX_RSP_REQ_ENTITY_TOO_LARGE: /* 0x4d */
+		d(g_printerr ("Error: RSP_REQ_ENTITY_TOO_LARGE\n"));
 		return GNOME_VFS_ERROR_TOO_BIG;
 		
 	case OBEX_RSP_NOT_IMPLEMENTED:	/* 0x51 */
+		d(g_printerr ("Error: RSP_NOT_IMPLEMENTED\n"));
 		return GNOME_VFS_ERROR_NOT_SUPPORTED;
 
 	case OBEX_RSP_DATABASE_FULL: /* 0x60 */
+		d(g_printerr ("Error: RSP_DATABASE_FULL\n"));
 		return GNOME_VFS_ERROR_NO_SPACE;
 		
 	case OBEX_RSP_DATABASE_LOCKED: /* 0x61 */
+		d(g_printerr ("Error: RSP_DATABASE_LOCKED\n"));
 		return GNOME_VFS_ERROR_NOT_PERMITTED;
 
 		


More information about the maemo-commits mailing list