From 57e1082eb0facbff6d2af6d35ec97bb028dfd781 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Mon, 11 Jul 2011 10:47:34 +0300 Subject: [PATCH] gobex: Use guint instead of gint for request callback id --- gobex/gobex-transfer.c | 16 +++++++------- gobex/gobex.c | 48 ++++++++++++++++++++++++++---------------- gobex/gobex.h | 4 ++-- 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/gobex/gobex-transfer.c b/gobex/gobex-transfer.c index a3931a529..bd69812a7 100644 --- a/gobex/gobex-transfer.c +++ b/gobex/gobex-transfer.c @@ -34,9 +34,9 @@ struct transfer { guint req_id; - gint put_id; - gint get_id; - gint abort_id; + guint put_id; + guint get_id; + guint abort_id; GObexDataProducer data_producer; GObexDataConsumer data_consumer; @@ -52,15 +52,15 @@ static void transfer_free(struct transfer *transfer) if (transfer->req_id > 0) g_obex_cancel_req(transfer->obex, transfer->req_id, TRUE); - if (transfer->put_id) + if (transfer->put_id > 0) g_obex_remove_request_function(transfer->obex, transfer->put_id); - if (transfer->get_id) + if (transfer->get_id > 0) g_obex_remove_request_function(transfer->obex, transfer->req_id); - if (transfer->abort_id) + if (transfer->abort_id > 0) g_obex_remove_request_function(transfer->obex, transfer->abort_id); @@ -301,7 +301,7 @@ guint g_obex_put_rsp(GObex *obex, GObexPacket *req, { struct transfer *transfer; va_list args; - gint id; + guint id; transfer = transfer_new(obex, G_OBEX_OP_PUT, complete_func, user_data); transfer->data_consumer = data_func; @@ -415,7 +415,7 @@ guint g_obex_get_rsp(GObex *obex, GObexDataProducer data_func, { struct transfer *transfer; va_list args; - gint id; + guint id; transfer = transfer_new(obex, G_OBEX_OP_GET, complete_func, user_data); transfer->data_producer = data_func; diff --git a/gobex/gobex.c b/gobex/gobex.c index cd0a948ad..1a0e048a1 100644 --- a/gobex/gobex.c +++ b/gobex/gobex.c @@ -87,6 +87,7 @@ struct pending_pkt { }; struct req_handler { + guint id; guint8 opcode; GObexRequestFunc func; gpointer user_data; @@ -408,7 +409,7 @@ create_pending: static gint pending_pkt_cmp(gconstpointer a, gconstpointer b) { const struct pending_pkt *p = a; - guint id = GPOINTER_TO_INT(b); + guint id = GPOINTER_TO_UINT(b); return (p->id - id); } @@ -461,7 +462,7 @@ gboolean g_obex_cancel_req(GObex *obex, guint req_id, gboolean remove_callback) return TRUE; } - match = g_queue_find_custom(obex->tx_queue, GINT_TO_POINTER(req_id), + match = g_queue_find_custom(obex->tx_queue, GUINT_TO_POINTER(req_id), pending_pkt_cmp); if (match == NULL) return FALSE; @@ -498,28 +499,47 @@ void g_obex_set_disconnect_function(GObex *obex, GObexFunc func, obex->disconn_func_data = user_data; } -gint g_obex_add_request_function(GObex *obex, guint8 opcode, +static gint req_handler_cmpop(gconstpointer a, gconstpointer b) +{ + const struct req_handler *handler = a; + guint8 opcode = GPOINTER_TO_UINT(b); + + return (gint) handler->opcode - (gint) opcode; +} + +static gint req_handler_cmpid(gconstpointer a, gconstpointer b) +{ + const struct req_handler *handler = a; + guint id = GPOINTER_TO_UINT(b); + + return (gint) handler->id - (gint) id; +} + +guint g_obex_add_request_function(GObex *obex, guint8 opcode, GObexRequestFunc func, gpointer user_data) { struct req_handler *handler; + static guint next_id = 1; handler = g_new0(struct req_handler, 1); + handler->id = next_id++; handler->opcode = opcode; handler->func = func; handler->user_data = user_data; obex->req_handlers = g_slist_prepend(obex->req_handlers, handler); - return GPOINTER_TO_INT(handler); + return handler->id; } -gboolean g_obex_remove_request_function(GObex *obex, gint id) +gboolean g_obex_remove_request_function(GObex *obex, guint id) { struct req_handler *handler; GSList *match; - match = g_slist_find(obex->req_handlers, GINT_TO_POINTER(id)); + match = g_slist_find_custom(obex->req_handlers, GUINT_TO_POINTER(id), + req_handler_cmpid); if (match == NULL) return FALSE; @@ -606,27 +626,19 @@ static void handle_response(GObex *obex, GError *err, GObexPacket *rsp) enable_tx(obex); } -static gint req_handler_cmp(gconstpointer a, gconstpointer b) -{ - const struct req_handler *handler = a; - const guint8 *opcode = b; - - return (gint) handler->opcode - (gint) *opcode; -} - static void handle_request(GObex *obex, GObexPacket *req) { GObexPacket *rsp; GSList *match; - guint8 opcode; + guint8 op; if (g_obex_packet_get_operation(req, NULL) == G_OBEX_OP_CONNECT) parse_connect_data(obex, req); - opcode = g_obex_packet_get_operation(req, NULL); + op = g_obex_packet_get_operation(req, NULL); - match = g_slist_find_custom(obex->req_handlers, &opcode, - req_handler_cmp); + match = g_slist_find_custom(obex->req_handlers, GUINT_TO_POINTER(op), + req_handler_cmpop); if (match) { struct req_handler *handler = match->data; handler->func(obex, req, handler->user_data); diff --git a/gobex/gobex.h b/gobex/gobex.h index cec57c21c..dfcd66f0c 100644 --- a/gobex/gobex.h +++ b/gobex/gobex.h @@ -52,10 +52,10 @@ gboolean g_obex_send_rsp(GObex *obex, guint8 rspcode, GError **err); void g_obex_set_disconnect_function(GObex *obex, GObexFunc func, gpointer user_data); -gint g_obex_add_request_function(GObex *obex, guint8 opcode, +guint g_obex_add_request_function(GObex *obex, guint8 opcode, GObexRequestFunc func, gpointer user_data); -gboolean g_obex_remove_request_function(GObex *obex, gint id); +gboolean g_obex_remove_request_function(GObex *obex, guint id); void g_obex_suspend(GObex *obex); void g_obex_resume(GObex *obex);