From 9f7db15294ea2dc501b12433abe5081f5478804a Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Sat, 24 Jul 2021 13:46:20 +0900 Subject: [PATCH] include/ipc: Add ipc_endpoint_foreach_message() function The IPC module currently does not provide an API that can be used to enquire the state of the queue of an endpoint. This makes it unnecessarily complicated to implement monitoring of IPC endpoints. This commit adds the ipc_endpoint_foreach_message() function that may be used to enquire about messages that are stored in the internal queue of an IPC endpoint. The semantics of this function are similar to those of queue_foreach(), with the exception that the endpoint name is passed in the first parameter of the callback and the message in the second parameter. The remaining parameters are passed on from ipc_endpoint_foreach_message(). --- include/ipc.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/ipc.sh b/include/ipc.sh index 7515bad..be6acab 100644 --- a/include/ipc.sh +++ b/include/ipc.sh @@ -696,3 +696,30 @@ ipc_endpoint_publish() { return 0 } + +_ipc_endpoint_foreach_message_helper() { + local msg="$1" + local endpoint="$2" + local func="$3" + local args=("${@:4}") + + "$func" "$endpoint" "$msg" "${args[@]}" + return "$?" +} + +ipc_endpoint_foreach_message() { + local endpoint="$1" + local func="$2" + local args=("${@:3}") + + local queue + + queue="$__ipc_root/$endpoint/queue" + + if ! queue_foreach "$queue" _ipc_endpoint_foreach_message_helper \ + "$endpoint" "$func" "${args[@]}"; then + return 1 + fi + + return 0 +} -- 2.47.3