aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pipewire/pipewire.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/pipewire/pipewire.go')
-rw-r--r--internal/pipewire/pipewire.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/internal/pipewire/pipewire.go b/internal/pipewire/pipewire.go
index 5473797c..636c7590 100644
--- a/internal/pipewire/pipewire.go
+++ b/internal/pipewire/pipewire.go
@@ -16,6 +16,7 @@ package pipewire
import (
"encoding/binary"
+ "errors"
"fmt"
"io"
"net"
@@ -786,6 +787,40 @@ func (ctx *Context) Close() (err error) {
}
}
+// expectsCoreError returns a function that inspects an error value and
+// returns the address of a [CoreError] if it is the only error present
+// and targets the specified proxy and sequence.
+//
+// The behaviour of expectsCoreError is only correct for an empty buf
+// prior to calling. If buf is not empty, [Core.Sync] is called, with
+// its return value stored to the value pointed to by errP if not nil,
+// and the function is not populated.
+//
+// The caller must queue a message and call [Core.Sync] immediately
+// after calling expectsCoreError.
+func (ctx *Context) expectsCoreError(id Int, errP *error) (asCoreError func() (coreError *CoreError)) {
+ if len(ctx.buf) > 0 {
+ if err := ctx.GetCore().Sync(); err != nil {
+ *errP = err
+ return nil
+ }
+ }
+
+ sequence := ctx.sequence
+ return func() (coreError *CoreError) {
+ if proxyErrors, ok := (*errP).(ProxyConsumeError); !ok ||
+ len(proxyErrors) != 1 ||
+ !errors.As(proxyErrors[0], &coreError) ||
+ coreError == nil ||
+ coreError.ID != id ||
+ coreError.Sequence != sequence {
+ // do not return a non-matching CoreError
+ coreError = nil
+ }
+ return
+ }
+}
+
// A PermissionError describes an error emitted by the server when trying to
// perform an operation that the client has no permission for.
type PermissionError struct {