diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c
index f96897d..8352550 100644
--- a/src/shared/mgmt.c
+++ b/src/shared/mgmt.c
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;
if (notify->callback)
notify->callback(index, length, param,
notify->user_data);
+
+ if (mgmt->destroyed)
+ break;
}
mgmt->in_notify = false;
return request->id;
}
-static bool cancel_request(struct mgmt *mgmt, gconstpointer data,
- GCompareFunc func)
+bool mgmt_cancel(struct mgmt *mgmt, unsigned int id)
{
struct mgmt_request *request;
GList *list;
- list = g_queue_find_custom(mgmt->request_queue, data, func);
+ if (!mgmt || !id)
+ return false;
+
+ list = g_queue_find_custom(mgmt->request_queue, GUINT_TO_POINTER(id),
+ compare_request_id);
if (list) {
request = list->data;
g_queue_delete_link(mgmt->request_queue, list);
goto done;
}
- list = g_queue_find_custom(mgmt->reply_queue, data, func);
+ list = g_queue_find_custom(mgmt->reply_queue, GUINT_TO_POINTER(id),
+ compare_request_id);
if (list) {
request = list->data;
g_queue_delete_link(mgmt->reply_queue, list);
goto done;
}
- list = g_list_find_custom(mgmt->pending_list, data, func);
+ list = g_list_find_custom(mgmt->pending_list, GUINT_TO_POINTER(id),
+ compare_request_id);
if (!list)
return false;
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)
{
- unsigned int id = index;
+ GList *list, *next;
if (!mgmt)
return false;
- return cancel_request(mgmt, GUINT_TO_POINTER(id),
- compare_request_index);
+ for (list = g_list_first(mgmt->pending_list); list; list = next) {
+ struct mgmt_request *request = list->data;
+
+ next = g_list_next(list);
+
+ if (request->index != index)
+ continue;
+
+ mgmt->pending_list = g_list_delete_link(mgmt->pending_list,
+ list);
+
+ destroy_request(request, NULL);
+ }
+
+ return true;
}
bool mgmt_cancel_all(struct mgmt *mgmt)