diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c
index de63ae7..2297caf 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;
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;
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 a43de10..c38c6f1 100644
--- a/src/shared/mgmt.h
+++ b/src/shared/mgmt.h
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,