From 029ba9b35e7ca19ae95f1ecd848bbd30a25504e1 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 4 Jan 2013 11:04:43 -0800 Subject: [PATCH] shared: Add support for canceling all management request of one index --- src/shared/mgmt.c | 37 +++++++++++++++++++++++++++++-------- src/shared/mgmt.h | 1 + 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c index de63ae74b..2297caf98 100644 --- a/src/shared/mgmt.c +++ b/src/shared/mgmt.c @@ -99,6 +99,14 @@ static gint compare_request_id(gconstpointer a, gconstpointer b) return request->id - id; } +static gint compare_request_index(gconstpointer a, gconstpointer b) +{ + const struct mgmt_request *request = a; + uint16_t index = GPOINTER_TO_UINT(b); + + return request->index - index; +} + static void destroy_notify(gpointer data, gpointer user_data) { struct mgmt_notify *notify = data; @@ -508,23 +516,19 @@ unsigned int mgmt_send(struct mgmt *mgmt, uint16_t opcode, uint16_t index, return request->id; } -bool mgmt_cancel(struct mgmt *mgmt, unsigned int id) +static bool cancel_request(struct mgmt *mgmt, gconstpointer data, + GCompareFunc func) { struct mgmt_request *request; GList *list; - if (!mgmt || !id) - return false; - - list = g_queue_find_custom(mgmt->request_queue, - GUINT_TO_POINTER(id), compare_request_id); + list = g_queue_find_custom(mgmt->request_queue, data, func); if (list) { request = list->data; g_queue_delete_link(mgmt->request_queue, list); } else { - list = g_list_find_custom(mgmt->pending_list, - GUINT_TO_POINTER(id), compare_request_id); + list = g_list_find_custom(mgmt->pending_list, data, func); if (!list) return false; @@ -539,6 +543,23 @@ bool mgmt_cancel(struct mgmt *mgmt, unsigned int id) return true; } +bool mgmt_cancel(struct mgmt *mgmt, unsigned int id) +{ + if (!mgmt || !id) + return false; + + return cancel_request(mgmt, GUINT_TO_POINTER(id), compare_request_id); +} + +bool mgmt_cancel_index(struct mgmt *mgmt, uint16_t index) +{ + if (!mgmt) + return false; + + return cancel_request(mgmt, GUINT_TO_POINTER(index), + compare_request_index); +} + bool mgmt_cancel_all(struct mgmt *mgmt) { if (!mgmt) diff --git a/src/shared/mgmt.h b/src/shared/mgmt.h index a43de1011..c38c6f1b5 100644 --- a/src/shared/mgmt.h +++ b/src/shared/mgmt.h @@ -49,6 +49,7 @@ unsigned int mgmt_send(struct mgmt *mgmt, uint16_t opcode, uint16_t index, mgmt_request_func_t callback, void *user_data, mgmt_destroy_func_t destroy); bool mgmt_cancel(struct mgmt *mgmt, unsigned int id); +bool mgmt_cancel_index(struct mgmt *mgmt, uint16_t index); bool mgmt_cancel_all(struct mgmt *mgmt); typedef void (*mgmt_notify_func_t)(uint16_t index, uint16_t length, -- 2.47.3