[gvfs] afp: convert g_vfs_afp_connection_queue_command to the standard GIO async pattern
- From: Christian Kellner <gicmo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvfs] afp: convert g_vfs_afp_connection_queue_command to the standard GIO async pattern
- Date: Thu, 25 Aug 2011 19:25:59 +0000 (UTC)
commit a39ab511180917bcab2ef21e125adaafaa654e91
Author: Carl-Anton Ingmarsson <ca ingmarsson gmail com>
Date: Sun Jul 17 23:39:08 2011 +0200
afp: convert g_vfs_afp_connection_queue_command to the standard GIO async pattern
also rename it to g_vfs_afp_connection_send_command
daemon/gvfsafpconnection.c | 240 +++++++++++++++++++++-------------
daemon/gvfsafpconnection.h | 19 ++--
daemon/gvfsafpserver.c | 22 +++-
daemon/gvfsbackendafp.c | 289 +++++++++++++++++++++++------------------
daemon/gvfsbackendafpbrowse.c | 29 +++--
5 files changed, 355 insertions(+), 244 deletions(-)
---
diff --git a/daemon/gvfsafpconnection.c b/daemon/gvfsafpconnection.c
index 207c145..4189e4e 100644
--- a/daemon/gvfsafpconnection.c
+++ b/daemon/gvfsafpconnection.c
@@ -583,25 +583,32 @@ get_request_id (GVfsAfpConnection *afp_connection)
return priv->request_id++;
}
+typedef enum
+{
+ REQUEST_TYPE_COMMAND,
+ REQUEST_TYPE_TICKLE
+} RequestType;
+
typedef struct
{
- gboolean tickle;
+ RequestType type;
+
GVfsAfpCommand *command;
- GVfsAfpConnectionReplyCallback reply_cb;
+ GSimpleAsyncResult *simple;
GCancellable *cancellable;
- gpointer user_data;
- GVfsAfpConnection *conn;
} RequestData;
static void
-free_request_data (RequestData *request_data)
+free_request_data (RequestData *req_data)
{
- if (request_data->command)
- g_object_unref (request_data->command);
- if (request_data->cancellable)
- g_object_unref (request_data->cancellable);
+ if (req_data->command)
+ g_object_unref (req_data->command);
+ if (req_data->simple)
+ g_object_unref (req_data->simple);
+ if (req_data->cancellable)
+ g_object_unref (req_data->cancellable);
- g_slice_free (RequestData, request_data);
+ g_slice_free (RequestData, req_data);
}
static void
@@ -635,8 +642,7 @@ dispatch_reply (GVfsAfpConnection *afp_connection)
/* Send back a tickle message */
req_data = g_slice_new0 (RequestData);
- req_data->tickle = TRUE;
- req_data->conn = afp_connection;
+ req_data->type = REQUEST_TYPE_TICKLE;
g_queue_push_head (priv->request_queue, req_data);
run_loop (afp_connection);
@@ -658,14 +664,15 @@ dispatch_reply (GVfsAfpConnection *afp_connection)
GUINT_TO_POINTER (priv->read_dsi_header.requestID));
if (req_data)
{
- if (req_data->reply_cb)
- {
- GVfsAfpReply *reply;
+ GVfsAfpReply *reply;
- reply = g_vfs_afp_reply_new (priv->read_dsi_header.errorCode, priv->data,
- priv->read_dsi_header.totalDataLength);
- req_data->reply_cb (afp_connection, reply, NULL, req_data->user_data);
- }
+ reply = g_vfs_afp_reply_new (priv->read_dsi_header.errorCode, priv->data,
+ priv->read_dsi_header.totalDataLength);
+
+ g_simple_async_result_set_op_res_gpointer (req_data->simple, reply,
+ g_object_unref);
+ g_simple_async_result_complete (req_data->simple);
+
g_hash_table_remove (priv->request_hash, GUINT_TO_POINTER (priv->read_dsi_header.requestID));
}
}
@@ -762,68 +769,91 @@ read_reply (GVfsAfpConnection *afp_connection)
}
static void
+remove_first (GQueue *request_queue)
+{
+ RequestData *req_data;
+
+ req_data = g_queue_pop_head (request_queue);
+ free_request_data (req_data);
+}
+
+static void
write_command_cb (GObject *object, GAsyncResult *res, gpointer user_data)
{
GOutputStream *output = G_OUTPUT_STREAM (object);
- RequestData *request_data = (RequestData *)user_data;
- GVfsAfpConnectionPrivate *priv = request_data->conn->priv;
-
+ GVfsAfpConnection *afp_conn = G_VFS_AFP_CONNECTION (user_data);
+ GVfsAfpConnectionPrivate *priv = afp_conn->priv;
+
+ RequestData *req_data;
gssize bytes_written;
GError *err = NULL;
gsize size;
+
+ req_data = g_queue_pop_head (priv->request_queue);
bytes_written = g_output_stream_write_finish (output, res, &err);
if (bytes_written == -1)
{
- request_data->reply_cb (request_data->conn, NULL, err, request_data->user_data);
- free_request_data (request_data);
+ g_simple_async_result_set_from_error (req_data->simple, err);
+ g_simple_async_result_complete (req_data->simple);
+
+ free_request_data (req_data);
g_error_free (err);
+
+ send_request (afp_conn);
+ return;
}
- size = g_vfs_afp_command_get_size (request_data->command);
+ size = g_vfs_afp_command_get_size (req_data->command);
priv->bytes_written += bytes_written;
if (priv->bytes_written < size)
{
char *data;
- data = g_vfs_afp_command_get_data (request_data->command);
+ data = g_vfs_afp_command_get_data (req_data->command);
g_output_stream_write_async (output, data + priv->bytes_written,
size - priv->bytes_written, 0, NULL,
- write_command_cb, request_data);
+ write_command_cb, afp_conn);
return;
}
+ g_queue_pop_head (priv->request_queue);
g_hash_table_insert (priv->request_hash,
GUINT_TO_POINTER (GUINT16_FROM_BE (priv->write_dsi_header.requestID)),
- request_data);
+ req_data);
- send_request (request_data->conn);
+ send_request (afp_conn);
}
static void
write_dsi_header_cb (GObject *object, GAsyncResult *res, gpointer user_data)
{
GOutputStream *output = G_OUTPUT_STREAM (object);
- RequestData *request_data = (RequestData *)user_data;
- GVfsAfpConnectionPrivate *priv = request_data->conn->priv;
+ GVfsAfpConnection *afp_conn = G_VFS_AFP_CONNECTION (user_data);
+ GVfsAfpConnectionPrivate *priv = afp_conn->priv;
+ RequestData *req_data;
gssize bytes_written;
GError *err = NULL;
char *data;
gsize size;
+
+ req_data = g_queue_peek_head (priv->request_queue);
bytes_written = g_output_stream_write_finish (output, res, &err);
if (bytes_written == -1)
{
- if (request_data->reply_cb)
- request_data->reply_cb (request_data->conn, NULL, err, request_data->user_data);
-
- free_request_data (request_data);
+ g_simple_async_result_set_from_error (req_data->simple, err);
+ g_simple_async_result_complete (req_data->simple);
+
+ remove_first (priv->request_queue);
g_error_free (err);
+
+ send_request (afp_conn);
return;
}
@@ -832,22 +862,22 @@ write_dsi_header_cb (GObject *object, GAsyncResult *res, gpointer user_data)
{
g_output_stream_write_async (output, &priv->write_dsi_header + priv->bytes_written,
sizeof (DSIHeader) - priv->bytes_written, 0,
- NULL, write_dsi_header_cb, request_data);
+ NULL, write_dsi_header_cb, afp_conn);
return;
}
- if (!request_data->command)
+ if (!req_data->command)
{
- free_request_data (request_data);
+ remove_first (priv->request_queue);
return;
}
- data = g_vfs_afp_command_get_data (request_data->command);
- size = g_vfs_afp_command_get_size (request_data->command);
+ data = g_vfs_afp_command_get_data (req_data->command);
+ size = g_vfs_afp_command_get_size (req_data->command);
priv->bytes_written = 0;
g_output_stream_write_async (output, data, size, 0,
- NULL, write_command_cb, request_data);
+ NULL, write_command_cb, afp_conn);
}
static void
@@ -855,85 +885,111 @@ send_request (GVfsAfpConnection *afp_connection)
{
GVfsAfpConnectionPrivate *priv = afp_connection->priv;
- RequestData *request_data;
+ RequestData *req_data;
guint32 writeOffset;
guint8 dsi_command;
- request_data = g_queue_pop_head (priv->request_queue);
+ req_data = g_queue_peek_head (priv->request_queue);
- if (!request_data) {
+ if (!req_data) {
priv->send_loop_running = FALSE;
return;
}
- if (request_data->tickle)
+ switch (req_data->type)
{
- priv->write_dsi_header.flags = 0x00;
- priv->write_dsi_header.command = DSI_TICKLE;
- priv->write_dsi_header.requestID = GUINT16_TO_BE (get_request_id (afp_connection));
- priv->write_dsi_header.writeOffset = 0;
- priv->write_dsi_header.totalDataLength = 0;
- priv->write_dsi_header.reserved = 0;
- }
+ case REQUEST_TYPE_TICKLE:
+ priv->write_dsi_header.flags = 0x00;
+ priv->write_dsi_header.command = DSI_TICKLE;
+ priv->write_dsi_header.requestID = GUINT16_TO_BE (get_request_id (afp_connection));
+ priv->write_dsi_header.writeOffset = 0;
+ priv->write_dsi_header.totalDataLength = 0;
+ priv->write_dsi_header.reserved = 0;
+ break;
- else
- {
- switch (request_data->command->type)
- {
- case AFP_COMMAND_WRITE:
- writeOffset = 8;
- dsi_command = DSI_WRITE;
- break;
- case AFP_COMMAND_WRITE_EXT:
- writeOffset = 20;
- dsi_command = DSI_WRITE;
- break;
+ case REQUEST_TYPE_COMMAND:
+ switch (req_data->command->type)
+ {
+ case AFP_COMMAND_WRITE:
+ writeOffset = 8;
+ dsi_command = DSI_WRITE;
+ break;
+ case AFP_COMMAND_WRITE_EXT:
+ writeOffset = 20;
+ dsi_command = DSI_WRITE;
+ break;
+
+ default:
+ writeOffset = 0;
+ dsi_command = DSI_COMMAND;
+ break;
+ }
- default:
- writeOffset = 0;
- dsi_command = DSI_COMMAND;
- break;
- }
+ priv->write_dsi_header.flags = 0x00;
+ priv->write_dsi_header.command = dsi_command;
+ priv->write_dsi_header.requestID = GUINT16_TO_BE (get_request_id (afp_connection));
+ priv->write_dsi_header.writeOffset = GUINT32_TO_BE (writeOffset);
+ priv->write_dsi_header.totalDataLength = GUINT32_TO_BE (g_vfs_afp_command_get_size (req_data->command));
+ priv->write_dsi_header.reserved = 0;
+ break;
- priv->write_dsi_header.flags = 0x00;
- priv->write_dsi_header.command = dsi_command;
- priv->write_dsi_header.requestID = GUINT16_TO_BE (get_request_id (afp_connection));
- priv->write_dsi_header.writeOffset = GUINT32_TO_BE (writeOffset);
- priv->write_dsi_header.totalDataLength = GUINT32_TO_BE (g_vfs_afp_command_get_size (request_data->command));
- priv->write_dsi_header.reserved = 0;
+ default:
+ g_assert_not_reached ();
}
-
+
+
priv->bytes_written = 0;
g_output_stream_write_async (g_io_stream_get_output_stream (priv->conn),
&priv->write_dsi_header, sizeof (DSIHeader), 0,
- NULL, write_dsi_header_cb, request_data);
+ NULL, write_dsi_header_cb, afp_connection);
}
void
-g_vfs_afp_connection_queue_command (GVfsAfpConnection *afp_connection,
- GVfsAfpCommand *command,
- GVfsAfpConnectionReplyCallback reply_cb,
- GCancellable *cancellable,
- gpointer user_data)
+g_vfs_afp_connection_send_command (GVfsAfpConnection *afp_connection,
+ GVfsAfpCommand *command,
+ GAsyncReadyCallback callback,
+ GCancellable *cancellable,
+ gpointer user_data)
{
GVfsAfpConnectionPrivate *priv = afp_connection->priv;
- RequestData *request_data;
+ RequestData *req_data;
- request_data = g_slice_new0 (RequestData);
- request_data->tickle = FALSE;
- request_data->command = g_object_ref (command);
- request_data->reply_cb = reply_cb;
+ req_data = g_slice_new0 (RequestData);
+ req_data->type = REQUEST_TYPE_COMMAND;
+ req_data->command = g_object_ref (command);
+
+ req_data->simple = g_simple_async_result_new (G_OBJECT (afp_connection), callback,
+ user_data,
+ g_vfs_afp_connection_send_command);
if (cancellable)
- request_data->cancellable = g_object_ref (cancellable);
- request_data->user_data = user_data;
- request_data->conn = afp_connection;
+ req_data->cancellable = g_object_ref (cancellable);
- g_queue_push_tail (priv->request_queue, request_data);
+ g_queue_push_tail (priv->request_queue, req_data);
run_loop (afp_connection);
}
+GVfsAfpReply *
+g_vfs_afp_connection_send_command_finish (GVfsAfpConnection *afp_connection,
+ GAsyncResult *res,
+ GError **error)
+{
+ GSimpleAsyncResult *simple;
+
+ g_return_val_if_fail (g_simple_async_result_is_valid (res,
+ G_OBJECT (afp_connection),
+ g_vfs_afp_connection_send_command),
+ NULL);
+
+ simple = (GSimpleAsyncResult *)res;
+
+ if (g_simple_async_result_propagate_error (simple, error))
+ return NULL;
+
+ return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
+}
+
static gboolean
read_reply_sync (GInputStream *input,
DSIHeader *dsi_header,
diff --git a/daemon/gvfsafpconnection.h b/daemon/gvfsafpconnection.h
index 3eed6a5..364dc3d 100644
--- a/daemon/gvfsafpconnection.h
+++ b/daemon/gvfsafpconnection.h
@@ -337,11 +337,6 @@ struct _GVfsAfpConnection
GVfsAfpConnectionPrivate *priv;
};
-typedef void (*GVfsAfpConnectionReplyCallback) (GVfsAfpConnection *afp_connection,
- GVfsAfpReply *reply,
- GError *error,
- gpointer user_data);
-
GType g_vfs_afp_connection_get_type (void) G_GNUC_CONST;
@@ -368,11 +363,15 @@ GVfsAfpReply* g_vfs_afp_connection_read_reply_sync (GVfsAfpConnection *af
GCancellable *cancellable,
GError **error);
-void g_vfs_afp_connection_queue_command (GVfsAfpConnection *afp_connection,
- GVfsAfpCommand *command,
- GVfsAfpConnectionReplyCallback reply_cb,
- GCancellable *cancellable,
- gpointer user_data);
+GVfsAfpReply* g_vfs_afp_connection_send_command_finish (GVfsAfpConnection *afp_connnection,
+ GAsyncResult *res,
+ GError **error);
+
+void g_vfs_afp_connection_send_command (GVfsAfpConnection *afp_connection,
+ GVfsAfpCommand *command,
+ GAsyncReadyCallback callback,
+ GCancellable *cancellable,
+ gpointer user_data);
G_END_DECLS
#endif /* _GVFSAFPCONNECTION_H_ */
diff --git a/daemon/gvfsafpserver.c b/daemon/gvfsafpserver.c
index 0b96b06..4e03023 100644
--- a/daemon/gvfsafpserver.c
+++ b/daemon/gvfsafpserver.c
@@ -41,14 +41,26 @@ G_DEFINE_TYPE (GVfsAfpServer, g_vfs_afp_server, G_TYPE_OBJECT);
#define AFP_UAM_DHX2 "DHX2"
static void
-get_srvr_msg_cb (GVfsAfpConnection *conn, GVfsAfpReply *reply, GError *error,
- gpointer user_data)
+get_srvr_msg_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
- gint16 message_bitmap;
+ GVfsAfpConnection *afp_conn = G_VFS_AFP_CONNECTION (source_object);
+
+ GVfsAfpReply *reply;
+ AfpResultCode res_code;
+ gint16 message_bitmap;
+
+ reply = g_vfs_afp_connection_send_command_finish (afp_conn, res, NULL);
if (!reply)
return;
+ res_code = g_vfs_afp_reply_get_result_code (reply);
+ if (res_code != AFP_RESULT_NO_ERROR)
+ {
+ g_object_unref (reply);
+ return;
+ }
+
/* MessageType */
g_vfs_afp_reply_read_int16 (reply, NULL);
/* MessageBitmap */
@@ -96,8 +108,8 @@ attention_cb (GVfsAfpConnection *conn, guint attention_code, gpointer user_data)
/* MessageBitmap */
g_vfs_afp_command_put_int16 (comm, 1);
- g_vfs_afp_connection_queue_command (afp_serv->conn, comm, get_srvr_msg_cb,
- NULL, afp_serv);
+ g_vfs_afp_connection_send_command (afp_serv->conn, comm, get_srvr_msg_cb,
+ NULL, afp_serv);
g_object_unref (comm);
}
}
diff --git a/daemon/gvfsbackendafp.c b/daemon/gvfsbackendafp.c
index d77ef48..c650ca1 100644
--- a/daemon/gvfsbackendafp.c
+++ b/daemon/gvfsbackendafp.c
@@ -314,20 +314,22 @@ static void fill_info (GVfsBackendAfp *afp_backend,
}
static void
-open_fork_cb (GVfsAfpConnection *afp_connection,
- GVfsAfpReply *reply,
- GError *error,
- gpointer user_data)
+open_fork_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
+ GVfsAfpConnection *afp_conn = G_VFS_AFP_CONNECTION (source_object);
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
+ GVfsAfpReply *reply;
+ GError *err = NULL;
AfpResultCode res_code;
+
guint16 file_bitmap;
gint16 fork_refnum;
-
+
+ reply = g_vfs_afp_connection_send_command_finish (afp_conn, res, &err);
if (!reply)
{
- g_simple_async_result_set_from_error (simple, error);
+ g_simple_async_result_take_error (simple, err);
g_simple_async_result_complete (simple);
return;
}
@@ -414,8 +416,8 @@ open_fork (GVfsBackendAfp *afp_backend,
simple = g_simple_async_result_new (G_OBJECT (afp_backend), callback,
user_data, open_fork);
- g_vfs_afp_connection_queue_command (afp_backend->server->conn, comm,
- open_fork_cb, cancellable, simple);
+ g_vfs_afp_connection_send_command (afp_backend->server->conn, comm,
+ open_fork_cb, cancellable, simple);
g_object_unref (comm);
}
@@ -442,23 +444,26 @@ open_fork_finish (GVfsBackendAfp *afp_backend,
}
static void
-close_fork_cb (GVfsAfpConnection *afp_connection,
- GVfsAfpReply *reply,
- GError *error,
- gpointer user_data)
+close_fork_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
+ GVfsAfpConnection *afp_conn = G_VFS_AFP_CONNECTION (source_object);
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
+ GVfsAfpReply *reply;
+ GError *err = NULL;
AfpResultCode res_code;
-
+
+ reply = g_vfs_afp_connection_send_command_finish (afp_conn, res, &err);
if (!reply)
{
- g_simple_async_result_set_from_error (simple, error);
+ g_simple_async_result_take_error (simple, err);
g_simple_async_result_complete (simple);
return;
}
res_code = g_vfs_afp_reply_get_result_code (reply);
+ g_object_unref (reply);
+
if (res_code != AFP_RESULT_NO_ERROR)
{
g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_FAILED,
@@ -488,7 +493,7 @@ close_fork (GVfsBackendAfp *afp_backend,
simple = g_simple_async_result_new (G_OBJECT (afp_backend), callback, user_data,
close_fork);
- g_vfs_afp_connection_queue_command (afp_backend->server->conn, comm,
+ g_vfs_afp_connection_send_command (afp_backend->server->conn, comm,
close_fork_cb, cancellable,
simple);
g_object_unref (comm);
@@ -515,21 +520,23 @@ close_fork_finish (GVfsBackendAfp *afp_backend,
}
static void
-get_fork_parms_cb (GVfsAfpConnection *afp_connection,
- GVfsAfpReply *reply,
- GError *error,
- gpointer user_data)
+get_fork_parms_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
+ GVfsAfpConnection *afp_conn = G_VFS_AFP_CONNECTION (source_object);
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
GVfsBackendAfp *afp_backend = G_VFS_BACKEND_AFP (g_async_result_get_source_object (G_ASYNC_RESULT (simple)));
+ GVfsAfpReply *reply;
+ GError *err = NULL;
AfpResultCode res_code;
+
guint16 file_bitmap;
GFileInfo *info;
-
+
+ reply = g_vfs_afp_connection_send_command_finish (afp_conn, res, &err);
if (!reply)
{
- g_simple_async_result_set_from_error (simple, error);
+ g_simple_async_result_take_error (simple, err);
g_simple_async_result_complete (simple);
return;
}
@@ -550,6 +557,8 @@ get_fork_parms_cb (GVfsAfpConnection *afp_connection,
info = g_file_info_new ();
fill_info (afp_backend, info, reply, FALSE, file_bitmap);
+ g_object_unref (reply);
+
g_simple_async_result_set_op_res_gpointer (simple, info, g_object_unref);
g_simple_async_result_complete (simple);
}
@@ -577,7 +586,7 @@ get_fork_parms (GVfsBackendAfp *afp_backend,
get_fork_parms);
- g_vfs_afp_connection_queue_command (afp_backend->server->conn, comm,
+ g_vfs_afp_connection_send_command (afp_backend->server->conn, comm,
get_fork_parms_cb, cancellable,
simple);
g_object_unref (comm);
@@ -603,23 +612,24 @@ get_fork_parms_finish (GVfsBackendAfp *afp_backend,
return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
}
-
static void
-get_vol_parms_cb (GVfsAfpConnection *afp_connection,
- GVfsAfpReply *reply,
- GError *error,
- gpointer user_data)
+get_vol_parms_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
+ GVfsAfpConnection *afp_conn = G_VFS_AFP_CONNECTION (source_object);
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
GVfsBackendAfp *afp_backend = G_VFS_BACKEND_AFP (g_async_result_get_source_object (G_ASYNC_RESULT (simple)));
+ GVfsAfpReply *reply;
+ GError *err = NULL;
AfpResultCode res_code;
+
guint16 vol_bitmap;
GFileInfo *info;
-
+
+ reply = g_vfs_afp_connection_send_command_finish (afp_conn, res, &err);
if (!reply)
{
- g_simple_async_result_set_from_error (simple, error);
+ g_simple_async_result_take_error (simple, err);
g_simple_async_result_complete (simple);
return;
}
@@ -684,6 +694,8 @@ get_vol_parms_cb (GVfsAfpConnection *afp_connection,
g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE,
bytes_total);
}
+
+ g_object_unref (reply);
g_simple_async_result_set_op_res_gpointer (simple, info, g_object_unref);
g_simple_async_result_complete (simple);
@@ -711,7 +723,7 @@ get_vol_parms (GVfsBackendAfp *afp_backend,
get_vol_parms);
- g_vfs_afp_connection_queue_command (afp_backend->server->conn, comm,
+ g_vfs_afp_connection_send_command (afp_backend->server->conn, comm,
get_vol_parms_cb, cancellable,
simple);
g_object_unref (comm);
@@ -741,27 +753,27 @@ get_vol_parms_finish (GVfsBackendAfp *afp_backend,
* Backend code
*/
static void
-create_file_cb (GVfsAfpConnection *afp_connection,
- GVfsAfpReply *reply,
- GError *error,
- gpointer user_data)
+create_file_cb (GObject *object, GAsyncResult *res, gpointer user_data)
{
+ GVfsAfpConnection *afp_conn = G_VFS_AFP_CONNECTION (object);
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
+ GVfsAfpReply *reply;
+ GError *err = NULL;
AfpResultCode res_code;
-
+
+ reply = g_vfs_afp_connection_send_command_finish (afp_conn, res, &err);
if (!reply)
{
- g_simple_async_result_set_from_error (simple, error);
+ g_simple_async_result_take_error (simple, err);
g_simple_async_result_complete (simple);
return;
}
res_code = g_vfs_afp_reply_get_result_code (reply);
+ g_object_unref (reply);
if (res_code != AFP_RESULT_NO_ERROR)
{
- g_object_unref (reply);
-
switch (res_code)
{
case AFP_RESULT_ACCESS_DENIED:
@@ -796,6 +808,7 @@ create_file_cb (GVfsAfpConnection *afp_connection,
}
g_simple_async_result_complete (simple);
+ g_object_unref (simple);
}
static void
@@ -823,8 +836,8 @@ create_file (GVfsBackendAfp *afp_backend,
simple = g_simple_async_result_new (G_OBJECT (afp_backend), callback, user_data,
create_file);
- g_vfs_afp_connection_queue_command (afp_backend->server->conn, comm, create_file_cb,
- cancellable, simple);
+ g_vfs_afp_connection_send_command (afp_backend->server->conn, comm, create_file_cb,
+ cancellable, simple);
g_object_unref (comm);
}
@@ -849,19 +862,21 @@ create_file_finish (GVfsBackendAfp *afp_backend,
}
static void
-rename_cb (GVfsAfpConnection *afp_connection,
- GVfsAfpReply *reply,
- GError *error,
- gpointer user_data)
+rename_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
+ GVfsAfpConnection *afp_conn = G_VFS_AFP_CONNECTION (source_object);
GVfsJobSetDisplayName *job = G_VFS_JOB_SET_DISPLAY_NAME (user_data);
+ GVfsAfpReply *reply;
+ GError *err = NULL;
AfpResultCode res_code;
char *dirname, *newpath;
-
+
+ reply = g_vfs_afp_connection_send_command_finish (afp_conn, res, &err);
if (!reply)
{
- g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
+ g_vfs_job_failed_from_error (G_VFS_JOB (job), err);
+ g_error_free (err);
return;
}
@@ -951,7 +966,7 @@ try_set_display_name (GVfsBackend *backend,
g_free (dirname);
g_free (newname);
- g_vfs_afp_connection_queue_command (afp_backend->server->conn, comm, rename_cb,
+ g_vfs_afp_connection_send_command (afp_backend->server->conn, comm, rename_cb,
G_VFS_JOB (job)->cancellable, job);
g_object_unref (comm);
@@ -959,26 +974,28 @@ try_set_display_name (GVfsBackend *backend,
}
static void
-make_directory_cb (GVfsAfpConnection *afp_connection,
- GVfsAfpReply *reply,
- GError *error,
- gpointer user_data)
+make_directory_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
+ GVfsAfpConnection *afp_conn = G_VFS_AFP_CONNECTION (source_object);
GVfsJobMakeDirectory *job = G_VFS_JOB_MAKE_DIRECTORY (user_data);
+ GVfsAfpReply *reply;
+ GError *err = NULL;
AfpResultCode res_code;
-
+
+ reply = g_vfs_afp_connection_send_command_finish (afp_conn, res, &err);
if (!reply)
{
- g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
+ g_vfs_job_failed_from_error (G_VFS_JOB (job), err);
+ g_error_free (err);
return;
}
res_code = g_vfs_afp_reply_get_result_code (reply);
+ g_object_unref (reply);
+
if (res_code != AFP_RESULT_NO_ERROR)
{
- g_object_unref (reply);
-
switch (res_code)
{
case AFP_RESULT_ACCESS_DENIED:
@@ -1035,34 +1052,36 @@ try_make_directory (GVfsBackend *backend,
/* Pathname */
put_pathname (comm, filename);
- g_vfs_afp_connection_queue_command (afp_backend->server->conn, comm, make_directory_cb,
- G_VFS_JOB (job)->cancellable, job);
+ g_vfs_afp_connection_send_command (afp_backend->server->conn, comm, make_directory_cb,
+ G_VFS_JOB (job)->cancellable, job);
g_object_unref (comm);
return TRUE;
}
static void
-delete_cb (GVfsAfpConnection *afp_connection,
- GVfsAfpReply *reply,
- GError *error,
- gpointer user_data)
+delete_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
+ GVfsAfpConnection *afp_conn = G_VFS_AFP_CONNECTION (source_object);
GVfsJobDelete *job = G_VFS_JOB_DELETE (user_data);
+ GVfsAfpReply *reply;
+ GError *err = NULL;
AfpResultCode res_code;
-
+
+ reply = g_vfs_afp_connection_send_command_finish (afp_conn, res, &err);
if (!reply)
{
- g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
+ g_vfs_job_failed_from_error (G_VFS_JOB (job), err);
+ g_error_free (err);
return;
}
res_code = g_vfs_afp_reply_get_result_code (reply);
+ g_object_unref (reply);
+
if (res_code != AFP_RESULT_NO_ERROR)
{
- g_object_unref (reply);
-
switch (res_code)
{
case AFP_RESULT_ACCESS_DENIED:
@@ -1116,7 +1135,7 @@ try_delete (GVfsBackend *backend,
/* Pathname */
put_pathname (comm, filename);
- g_vfs_afp_connection_queue_command (afp_backend->server->conn, comm, delete_cb,
+ g_vfs_afp_connection_send_command (afp_backend->server->conn, comm, delete_cb,
G_VFS_JOB (job)->cancellable, job);
g_object_unref (comm);
@@ -1124,21 +1143,23 @@ try_delete (GVfsBackend *backend,
}
static void
-write_ext_cb (GVfsAfpConnection *afp_connection,
- GVfsAfpReply *reply,
- GError *error,
- gpointer user_data)
+write_ext_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
+ GVfsAfpConnection *afp_conn = G_VFS_AFP_CONNECTION (source_object);
GVfsJobWrite *job = G_VFS_JOB_WRITE (user_data);
AfpHandle *afp_handle = (AfpHandle *)job->handle;
+ GVfsAfpReply *reply;
+ GError *err = NULL;
AfpResultCode res_code;
gint64 last_written;
gsize written_size;
+ reply = g_vfs_afp_connection_send_command_finish (afp_conn, res, &err);
if (!reply)
{
- g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
+ g_vfs_job_failed_from_error (G_VFS_JOB (job), err);
+ g_error_free (err);
return;
}
@@ -1204,9 +1225,9 @@ try_write (GVfsBackend *backend,
g_output_stream_write_all (G_OUTPUT_STREAM (comm), buffer, req_count, NULL,
NULL, NULL);
- g_vfs_afp_connection_queue_command (afp_backend->server->conn, comm,
- write_ext_cb, G_VFS_JOB (job)->cancellable,
- job);
+ g_vfs_afp_connection_send_command (afp_backend->server->conn, comm,
+ write_ext_cb, G_VFS_JOB (job)->cancellable,
+ job);
g_object_unref (comm);
return TRUE;
@@ -1335,21 +1356,23 @@ try_seek_on_read (GVfsBackend *backend,
}
static void
-read_ext_cb (GVfsAfpConnection *afp_connection,
- GVfsAfpReply *reply,
- GError *error,
- gpointer user_data)
+read_ext_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
+ GVfsAfpConnection *afp_conn = G_VFS_AFP_CONNECTION (source_object);
GVfsJobRead *job = G_VFS_JOB_READ (user_data);
AfpHandle *afp_handle = (AfpHandle *)job->handle;
+ GVfsAfpReply *reply;
+ GError *err = NULL;
AfpResultCode res_code;
gsize size;
char *data;
+ reply = g_vfs_afp_connection_send_command_finish (afp_conn, res, &err);
if (!reply)
{
- g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
+ g_vfs_job_failed_from_error (G_VFS_JOB (job), err);
+ g_error_free (err);
return;
}
@@ -1413,7 +1436,7 @@ try_read (GVfsBackend *backend,
req_count = MIN (bytes_requested, G_MAXUINT32);
g_vfs_afp_command_put_int64 (comm, req_count);
- g_vfs_afp_connection_queue_command (afp_backend->server->conn, comm,
+ g_vfs_afp_connection_send_command (afp_backend->server->conn, comm,
read_ext_cb, G_VFS_JOB (job)->cancellable,
job);
g_object_unref (comm);
@@ -1441,7 +1464,7 @@ close_replace_close_fork_cb (GObject *source_object, GAsyncResult *res, gpointer
/* Pathname */
put_pathname (comm, afp_handle->tmp_filename);
- g_vfs_afp_connection_queue_command (afp_backend->server->conn, comm, NULL,
+ g_vfs_afp_connection_send_command (afp_backend->server->conn, comm, NULL,
NULL, NULL);
g_object_unref (comm);
@@ -1450,19 +1473,21 @@ close_replace_close_fork_cb (GObject *source_object, GAsyncResult *res, gpointer
}
static void
-close_replace_exchange_files_cb (GVfsAfpConnection *afp_connection,
- GVfsAfpReply *reply,
- GError *error,
- gpointer user_data)
+close_replace_exchange_files_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
+ GVfsAfpConnection *afp_conn = G_VFS_AFP_CONNECTION (source_object);
GVfsJobCloseWrite *job = G_VFS_JOB_CLOSE_WRITE (user_data);
GVfsBackendAfp *afp_backend = G_VFS_BACKEND_AFP (job->backend);
+ GVfsAfpReply *reply;
+ GError *err = NULL;
AfpResultCode res_code;
+ reply = g_vfs_afp_connection_send_command_finish (afp_conn, res, &err);
if (!reply)
{
- g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
+ g_vfs_job_failed_from_error (G_VFS_JOB (job), err);
+ g_error_free (err);
return;
}
@@ -1471,10 +1496,10 @@ close_replace_exchange_files_cb (GVfsAfpConnection *afp_connection,
close_replace_close_fork_cb, job->handle);
res_code = g_vfs_afp_reply_get_result_code (reply);
+ g_object_unref (reply);
+
if (res_code != AFP_RESULT_NO_ERROR)
{
- g_object_unref (reply);
-
switch (res_code)
{
case AFP_RESULT_ACCESS_DENIED:
@@ -1539,9 +1564,9 @@ try_close_write (GVfsBackend *backend,
/* DestPath */
put_pathname (comm, afp_handle->tmp_filename);
- g_vfs_afp_connection_queue_command (afp_backend->server->conn, comm,
- close_replace_exchange_files_cb,
- G_VFS_JOB (job)->cancellable, job);
+ g_vfs_afp_connection_send_command (afp_backend->server->conn, comm,
+ close_replace_exchange_files_cb,
+ G_VFS_JOB (job)->cancellable, job);
g_object_unref (comm);
}
else
@@ -1914,38 +1939,46 @@ enumerate_ext2 (GVfsJobEnumerate *job,
gint32 start_index);
static void
-enumerate_ext2_cb (GVfsAfpConnection *afp_connection,
- GVfsAfpReply *reply,
- GError *error,
- gpointer user_data)
+enumerate_ext2_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
+ GVfsAfpConnection *afp_conn = G_VFS_AFP_CONNECTION (source_object);
GVfsJobEnumerate *job = G_VFS_JOB_ENUMERATE (user_data);
GVfsBackendAfp *afp_backend = G_VFS_BACKEND_AFP (job->backend);
+ GVfsAfpReply *reply;
+ GError *err = NULL;
AfpResultCode res_code;
+
guint16 file_bitmap;
guint16 dir_bitmap;
gint16 count, i;
gint start_index;
-
+
+ reply = g_vfs_afp_connection_send_command_finish (afp_conn, res, &err);
if (!reply)
{
- g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
+ g_vfs_job_failed_from_error (G_VFS_JOB (job), err);
+ g_error_free (err);
return;
}
res_code = g_vfs_afp_reply_get_result_code (reply);
- if (res_code == AFP_RESULT_OBJECT_NOT_FOUND)
- {
- g_vfs_job_succeeded (G_VFS_JOB (job));
- g_vfs_job_enumerate_done (job);
- return;
- }
- else if (res_code != AFP_RESULT_NO_ERROR)
+ if (res_code != AFP_RESULT_NO_ERROR)
{
- g_vfs_job_failed_literal (G_VFS_JOB (job), G_IO_ERROR,
- G_IO_ERROR_FAILED, _("Enumeration of files failed"));
+ g_object_unref (reply);
+
+ switch (res_code)
+ {
+ case AFP_RESULT_OBJECT_NOT_FOUND:
+ g_vfs_job_succeeded (G_VFS_JOB (job));
+ g_vfs_job_enumerate_done (job);
+ break;
+ default:
+ g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_FAILED,
+ _("Got error code: %d from server"), res_code);
+ break;
+ }
return;
}
@@ -1980,6 +2013,7 @@ enumerate_ext2_cb (GVfsAfpConnection *afp_connection,
g_vfs_afp_reply_seek (reply, start_pos + struct_length, G_SEEK_SET);
}
+ g_object_unref (reply);
start_index = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (job),
"start-index"));
@@ -2031,7 +2065,7 @@ enumerate_ext2 (GVfsJobEnumerate *job,
/* Pathname */
put_pathname (comm, filename);
- g_vfs_afp_connection_queue_command (conn, comm, enumerate_ext2_cb,
+ g_vfs_afp_connection_send_command (conn, comm, enumerate_ext2_cb,
G_VFS_JOB (job)->cancellable, job);
g_object_unref (comm);
}
@@ -2119,39 +2153,44 @@ try_query_fs_info (GVfsBackend *backend,
}
static void
-get_filedir_parms_cb (GVfsAfpConnection *afp_connection,
- GVfsAfpReply *reply,
- GError *error,
- gpointer user_data)
+get_filedir_parms_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
+ GVfsAfpConnection *afp_conn = G_VFS_AFP_CONNECTION (source_object);
GVfsJobQueryInfo *job = G_VFS_JOB_QUERY_INFO (user_data);
GVfsBackendAfp *afp_backend = G_VFS_BACKEND_AFP (job->backend);
+ GVfsAfpReply *reply;
+ GError *err = NULL;
AfpResultCode res_code;
+
guint16 file_bitmap, dir_bitmap, bitmap;
guint8 FileDir;
gboolean directory;
-
+
+ reply = g_vfs_afp_connection_send_command_finish (afp_conn, res, &err);
if (!reply)
{
- g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
+ g_vfs_job_failed_from_error (G_VFS_JOB (job), err);
+ g_error_free (err);
return;
}
res_code = g_vfs_afp_reply_get_result_code (reply);
- if (res_code == AFP_RESULT_OBJECT_NOT_FOUND)
- {
- g_object_unref (reply);
- g_vfs_job_failed_literal (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
- _("File doesn't exist"));
- return;
- }
-
- else if (res_code != AFP_RESULT_NO_ERROR)
+ if (res_code != AFP_RESULT_NO_ERROR)
{
g_object_unref (reply);
- g_vfs_job_failed_literal (G_VFS_JOB (job), G_IO_ERROR,
- G_IO_ERROR_FAILED, _("Retrieval of file/directory parameters failed"));
+
+ switch (res_code)
+ {
+ case AFP_RESULT_OBJECT_NOT_FOUND:
+ g_vfs_job_failed_literal (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
+ _("File doesn't exist"));
+ break;
+ default:
+ g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR, G_IO_ERROR_FAILED,
+ _("Got error code: %d from server"), res_code);
+ break;
+ }
return;
}
@@ -2254,7 +2293,7 @@ try_query_info (GVfsBackend *backend,
/* Pathname */
put_pathname (comm, filename);
- g_vfs_afp_connection_queue_command (afp_backend->server->conn, comm,
+ g_vfs_afp_connection_send_command (afp_backend->server->conn, comm,
get_filedir_parms_cb,
G_VFS_JOB (job)->cancellable, job);
}
diff --git a/daemon/gvfsbackendafpbrowse.c b/daemon/gvfsbackendafpbrowse.c
index b802a48..37e6236 100644
--- a/daemon/gvfsbackendafpbrowse.c
+++ b/daemon/gvfsbackendafpbrowse.c
@@ -100,19 +100,23 @@ typedef struct
} UpdateCacheData;
static void
-get_srvr_parms_cb (GVfsAfpConnection *afp_connection,
- GVfsAfpReply *reply,
- GError *error,
- gpointer user_data)
+get_srvr_parms_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
+ GVfsAfpConnection *afp_conn = G_VFS_AFP_CONNECTION (source_object);
UpdateCacheData *data = (UpdateCacheData *)user_data;
+ GVfsAfpReply *reply;
+ GError *err = NULL;
AfpResultCode res_code;
+
guint8 num_volumes, i;
+ reply = g_vfs_afp_connection_send_command_finish (afp_conn, res, &err);
if (!reply)
{
- data->cb (data->afp_backend, error, data->user_data);
+ data->cb (data->afp_backend, err, data->user_data);
+
+ g_error_free (err);
g_slice_free (UpdateCacheData, data);
return;
}
@@ -120,10 +124,10 @@ get_srvr_parms_cb (GVfsAfpConnection *afp_connection,
res_code = g_vfs_afp_reply_get_result_code (reply);
if (res_code != AFP_RESULT_NO_ERROR)
{
- GError *err;
-
- err = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED,
- _("Retrieval of server parameters failed"));
+ g_object_unref (reply);
+
+ err = g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
+ _("Got error code: %d from server"), res_code);
data->cb (data->afp_backend, err, data->user_data);
g_error_free (err);
@@ -156,6 +160,7 @@ get_srvr_parms_cb (GVfsAfpConnection *afp_connection,
data->afp_backend->volumes = g_slist_prepend (data->afp_backend->volumes, volume_data);
}
+ g_object_unref (reply);
data->cb (data->afp_backend, NULL, data->user_data);
g_slice_free (UpdateCacheData, data);
@@ -177,9 +182,9 @@ update_cache (GVfsBackendAfpBrowse *afp_backend, GCancellable *cancellable,
/* pad byte */
g_vfs_afp_command_put_byte (comm, 0);
- g_vfs_afp_connection_queue_command (afp_backend->server->conn, comm,
- get_srvr_parms_cb,
- cancellable, data);
+ g_vfs_afp_connection_send_command (afp_backend->server->conn, comm,
+ get_srvr_parms_cb,
+ cancellable, data);
g_object_unref (comm);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]