diff --git a/gobex/gobex-transfer.c b/gobex/gobex-transfer.c
index a3931a5..bd69812 100644
--- a/gobex/gobex-transfer.c
+++ b/gobex/gobex-transfer.c
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;
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);
{
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;
{
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 cd0a948..1a0e048 100644
--- a/gobex/gobex.c
+++ b/gobex/gobex.c
};
struct req_handler {
+ guint id;
guint8 opcode;
GObexRequestFunc func;
gpointer user_data;
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);
}
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;
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;
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 cec57c2..dfcd66f 100644
--- a/gobex/gobex.h
+++ b/gobex/gobex.h
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);