Diff between 8a5b8c17ee00e1d0de8bf6566aa96ad20badf102 and 029ba9b35e7ca19ae95f1ecd848bbd30a25504e1

Changed Files

File Additions Deletions Status
src/shared/mgmt.c +29 -8 modified
src/shared/mgmt.h +1 -0 modified

Full Patch

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
@@ -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 a43de10..c38c6f1 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,