client: Return the request id and error on session API
Luiz Augusto von Dentz
maintainerPATCH 1/1 client: Return the request id and error on session API
From: Luiz Augusto von Dentz <[email protected]>
This is more consistent with the rest of the API and enable the caller to propagate the errors properly or to cancel the request.
--- client/agent.c | 2 +- client/ftp.c | 43 ++++++++++++++++++++++++----------- client/manager.c | 48 +++++++++++++++++++++++++++------------ client/map.c | 34 +++++++++++++++++----------- client/pbap.c | 47 ++++++++++++++++++++++++--------------- client/session.c | 63 ++++++++++++++++++++++++++++------------------------ client/session.h | 22 ++++++++++-------- client/sync.c | 30 ++++++++++++++++++------ client/transfer.c | 28 ++++++++++++++++------ client/transfer.h | 6 +++- 10 files changed, 205 insertions(+), 118 deletions(-)
client/agent.c +1 -1
@@ -122,7 +122,7 @@ static void agent_request_reply(DBusPendingCall *call, void *user_data)pending_request_free (req); } -int obc_agent_request (struct obc_agent *agent,const char *path, +gboolean obc_agent_request (struct obc_agent *agent,const char *path,DBusPendingCallNotifyFunction function,void *user_data,DBusFreeFunction destroy) {
client/ftp.c +29 -14
74 lines not on this page · raw message
client/manager.c +33 -15
84 lines not on this page · raw message
client/map.c +21 -13
@@ -132,14 +132,18 @@ static DBusMessage *map_get_folder_listing(DBusConnection *connection, DBusMessage *message, void *user_data) {struct map_data *map = user_data; -int err; +GError *err =NULL ; - err =obc_session_get (map->session,"x-obex/folder-listing" , -NULL ,NULL ,NULL ,0 , - buffer_cb, map); -if (err <0 ) -return g_dbus_create_error (message,"org.openobex.Error.Failed" , -NULL ); +obc_session_get (map->session,"x-obex/folder-listing" ,NULL , +NULL ,NULL ,0 , + buffer_cb, map, &err); +if (err !=NULL ) { +DBusMessage *reply =g_dbus_create_error (message, +"org.openobex.Error.Failed" , +"%s" , err->message); +g_error_free (err); +return reply; + } map->msg =dbus_message_ref (message);
@@ -150,9 +154,9 @@ static DBusMessage *map_get_message_listing(DBusConnection *connection, DBusMessage *message, void *user_data) {struct map_data *map = user_data; -int err;const char *folder;DBusMessageIter msg_iter; +GError *err =NULL ;dbus_message_iter_init (message, &msg_iter);
@@ -162,12 +166,16 @@ static DBusMessage *map_get_message_listing(DBusConnection *connection,dbus_message_iter_get_basic (&msg_iter, &folder); - err =obc_session_get (map->session,"x-bt/MAP-msg-listing" , folder, +obc_session_get (map->session,"x-bt/MAP-msg-listing" , folder,NULL ,NULL ,0 , - buffer_cb, map); -if (err <0 ) -return g_dbus_create_error (message,"org.openobex.Error.Failed" , -NULL ); + buffer_cb, map, &err); +if (err !=NULL ) { +DBusMessage *reply =g_dbus_create_error (message, +"org.openobex.Error.Failed" , +"%s" , err->message); +g_error_free (err); +return reply; + } map->msg =dbus_message_ref (message);
client/pbap.c +29 -18
89 lines not on this page · raw message
client/session.c +34 -29
142 lines not on this page · raw message
client/session.h +12 -10
@@ -56,19 +56,21 @@ int obc_session_get_contents(struct obc_session *session, char **contents, size_t *size);void *obc_session_get_params (struct obc_session *session,size_t *size); -int obc_session_send (struct obc_session *session,const char *filename, -const char *name); -int obc_session_get (struct obc_session *session,const char *type, -const char *name,const char *targetfile, -const guint8 *apparam,gint apparam_size, -session_callback_t func,void *user_data); -int obc_session_pull (struct obc_session *session, +guint obc_session_send (struct obc_session *session,const char *filename, +const char *name,GError **err); +guint obc_session_get (struct obc_session *session,const char *type, +const char *name,const char *targetfile, +const guint8 *apparam,gint apparam_size, +session_callback_t func,void *user_data, +GError **err); +guint obc_session_pull (struct obc_session *session,const char *type,const char *targetfile, -session_callback_t function,void *user_data); +session_callback_t function,void *user_data, +GError **err);const char *obc_session_register (struct obc_session *session,GDBusDestroyFunction destroy); -int obc_session_put (struct obc_session *session,const char *contents, -size_t size,const char *name); +guint obc_session_put (struct obc_session *session,const char *contents, +size_t size,const char *name,GError **err); guint obc_session_setpath(struct obc_session *session, const char *path, session_callback_t func, void *user_data,
client/sync.c +22 -8
@@ -125,6 +125,7 @@ static DBusMessage *sync_getphonebook(DBusConnection *connection, DBusMessage *message, void *user_data) {struct sync_data *sync = user_data; +GError *err =NULL ;if (sync->msg) return g_dbus_create_error(message,
@@ -134,10 +135,17 @@ static DBusMessage *sync_getphonebook(DBusConnection *connection,if (!sync->phonebook_path) sync->phonebook_path =g_strdup ("telecom/pb.vcf" ); -if (obc_session_get (sync->session,"phonebook" , sync->phonebook_path,NULL , -NULL ,0 , sync_getphonebook_callback, sync) <0 ) -return g_dbus_create_error (message, -ERROR_INF ".Failed" ,"Failed" ); +obc_session_get (sync->session,"phonebook" , sync->phonebook_path, +NULL ,NULL ,0 , + sync_getphonebook_callback, sync, + &err); +if (err !=0 ) { +DBusMessage *reply =g_dbus_create_error (message, +ERROR_INF ".Failed" , + err->message); +g_error_free (err); +return reply; + } sync->msg =dbus_message_ref (message);
@@ -149,6 +157,7 @@ static DBusMessage *sync_putphonebook(DBusConnection *connection, {struct sync_data *sync = user_data;const char *buf; +GError *err =NULL ; if (dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &buf,
@@ -160,10 +169,15 @@ static DBusMessage *sync_putphonebook(DBusConnection *connection,if (!sync->phonebook_path) sync->phonebook_path =g_strdup ("telecom/pb.vcf" ); -if (obc_session_put (sync->session, buf,strlen (buf), - sync->phonebook_path) <0 ) -return g_dbus_create_error (message, -ERROR_INF ".Failed" ,"Failed" ); +obc_session_put (sync->session, buf,strlen (buf), sync->phonebook_path, + &err); +if (err !=NULL ) { +DBusMessage *reply =g_dbus_create_error (message, +ERROR_INF ".Failed" , + err->message); +g_error_free (err); +return reply; + }return dbus_message_new_method_return (message); }
client/transfer.c +20 -8
@@ -229,7 +229,8 @@ static struct obc_transfer *obc_transfer_register(DBusConnection *conn,const char *filename, const char *name, const char *type, - struct obc_transfer_params *params) + struct obc_transfer_params *params, + GError **err) { struct obc_transfer *transfer;
@@ -251,14 +252,20 @@ static struct obc_transfer *obc_transfer_register(DBusConnection *conn, TRANSFER_BASEPATH, counter++); transfer->conn =dbus_bus_get (DBUS_BUS_SESSION ,NULL ); -if (transfer->conn ==NULL ) +if (transfer->conn ==NULL ) { +g_set_error (err,OBC_TRANSFER_ERROR , -EFAULT , +"Unable to connect to D-Bus" ); goto fail; + }if (g_dbus_register_interface (transfer->conn, transfer->path,TRANSFER_INTERFACE , obc_transfer_methods,NULL ,NULL , - transfer,NULL ) == FALSE) + transfer,NULL ) == FALSE) { +g_set_error (err,OBC_TRANSFER_ERROR , -EFAULT , +"Unable to connect to D-Bus" ); goto fail; + } done:DBG ("%p registered %s" , transfer, transfer->path);
@@ -304,16 +311,20 @@ struct obc_transfer *obc_transfer_get(DBusConnection *conn,const char *filename, const char *name, const char *type, - struct obc_transfer_params *params) + struct obc_transfer_params *params, + GError **err) { struct obc_transfer *transfer; +int perr; transfer =obc_transfer_register (conn, agent,G_OBEX_OP_GET , filename, - name, type, params); + name, type, params, err);if (transfer ==NULL )return NULL ; -if (transfer_open (transfer,O_WRONLY |O_CREAT |O_TRUNC ,0600 ) <0 ) { + perr =transfer_open (transfer,O_WRONLY |O_CREAT |O_TRUNC ,0600 ); +if (perr <0 ) { +g_set_error (err,OBC_TRANSFER_ERROR , perr,"Unable open file" );obc_transfer_free (transfer);return NULL ; }
@@ -328,14 +339,15 @@ struct obc_transfer *obc_transfer_put(DBusConnection *conn,const char *type, const char *contents, size_t size, - struct obc_transfer_params *params) + struct obc_transfer_params *params, + GError **err) { struct obc_transfer *transfer;struct stat st;int perr; transfer =obc_transfer_register (conn, agent,G_OBEX_OP_PUT , filename, - name, type, params); + name, type, params, err);if (transfer ==NULL )return NULL ;
client/transfer.h +4 -2
@@ -37,7 +37,8 @@ struct obc_transfer *obc_transfer_get(DBusConnection *conn,const char *filename, const char *name, const char *type, - struct obc_transfer_params *params); + struct obc_transfer_params *params, + GError **err); struct obc_transfer *obc_transfer_put(DBusConnection *conn, const char *agent, const char *filename,
@@ -45,7 +46,8 @@ struct obc_transfer *obc_transfer_put(DBusConnection *conn,const char *type, const char *contents, size_t size, - struct obc_transfer_params *params); + struct obc_transfer_params *params, + GError **err);void obc_transfer_unregister (struct obc_transfer *transfer);
Signature · 1 line
1.7.7.6