mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-11-16 16:54:38 +08:00
gobex: Use guint instead of gint for request callback id
This commit is contained in:
parent
562f84396b
commit
57e1082eb0
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user