]> git.corax.cc Git - toolbox/commitdiff
include/ipc: Add ipc_endpoint_foreach_message() function
authorMatthias Kruk <m@m10k.eu>
Sat, 24 Jul 2021 04:46:20 +0000 (13:46 +0900)
committerMatthias Kruk <m@m10k.eu>
Sat, 24 Jul 2021 04:46:20 +0000 (13:46 +0900)
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

index 7515bad83b8f132316e0fb070ff019708cc24dca..be6acabc9f88599acff8de756d64823276bd582f 100644 (file)
@@ -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
+}