Skip to content

Commit c7aaa2a

Browse files
committed
feat(ds4api): add support for dynamic steering detection and error handling
Signed-off-by: Evan Wies <evan@neomantra.net>
1 parent 80f1398 commit c7aaa2a

6 files changed

Lines changed: 18 additions & 5 deletions

File tree

ds4api/engine.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ func (e *Engine) Close() {
126126
})
127127
}
128128

129-
130129
// require locks the engine and verifies it is open. The returned unlock
131130
// function MUST be called (typically via defer) to release the lock.
132131
func (e *Engine) require() (unlock func(), err error) {

ds4api/loader.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ func (l *Library) Path() string {
9292
return l.path
9393
}
9494

95+
// SupportsDynamicSteering reports whether the loaded library exports
96+
// ds4_session_set_directional_steering. When false, callers should rely on
97+
// engine-level (static) steering via EngineOptions.DirectionalSteering* fields.
98+
func (l *Library) SupportsDynamicSteering() bool {
99+
return l != nil && l.raw.ds4SessionSetDirectionalSteering != nil
100+
}
101+
95102
func (l *Library) register() (err error) {
96103
defer func() {
97104
if r := recover(); r != nil {

ds4api/mock_library.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,9 @@ func NewMockLibrary() *Library {
272272
snap.Ptr = nil
273273
}
274274
}
275-
r.ds4SessionSetDirectionalSteering = func(s uintptr, file unsafe.Pointer, mode int32, ffn float32, attn float32, threshold float32, scope int32, err unsafe.Pointer, errLen uintptr) int32 { return 0 }
275+
r.ds4SessionSetDirectionalSteering = func(s uintptr, file unsafe.Pointer, mode int32, ffn float32, attn float32, threshold float32, scope int32, err unsafe.Pointer, errLen uintptr) int32 {
276+
return 0
277+
}
276278

277279
return lib
278280
}

ds4api/session.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package ds4api
22

33
import (
4+
"errors"
45
"fmt"
56
"runtime"
67
"sync"
78
"unsafe"
89
)
910

11+
// ErrSteeringNotSupported is returned by Session.SetDirectionalSteering when
12+
// the loaded libds4 build does not export ds4_session_set_directional_steering.
13+
// Callers can check with errors.Is and downgrade to a warning so the rest of
14+
// the program can continue without dynamic steering.
15+
var ErrSteeringNotSupported = errors.New("ds4: session directional steering is not supported by the loaded library (missing symbol)")
16+
1017
// Session wraps a ds4_session.
1118
type Session struct {
1219
lib *Library
@@ -510,7 +517,7 @@ func (s *Session) SetDirectionalSteering(file string, mode SteeringMode, ffn flo
510517
defer unlock()
511518

512519
if s.lib.raw.ds4SessionSetDirectionalSteering == nil {
513-
return fmt.Errorf("ds4: session directional steering is not supported by the loaded library (missing symbol)")
520+
return ErrSteeringNotSupported
514521
}
515522

516523
buf, errPtr, n := errorBuffer()

internal/models/lock_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,3 @@ func TestAcquireEngineRunLock(t *testing.T) {
117117
}
118118
lock2.Close()
119119
}
120-

internal/models/progress.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ var (
2121
progressRest = lipgloss.NewStyle().Foreground(colorPrimary).Background(colorSurface)
2222
)
2323

24-
2524
type progressReader struct {
2625
out io.Writer
2726
name string

0 commit comments

Comments
 (0)