From b07f6ad805818286e0107a3c057b4b5f6acca48b Mon Sep 17 00:00:00 2001 From: fuleyi Date: Tue, 15 Jul 2025 16:45:38 +0800 Subject: [PATCH] feat: add GetModuleList method add GetModuleList method Log: pms: BUG-323877 --- pulse/pulse.go | 18 ++++++++++++++++++ pulse/sync.go | 2 ++ pulse/wrap.go | 23 +++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/pulse/pulse.go b/pulse/pulse.go index bef82d2..aa460bd 100644 --- a/pulse/pulse.go +++ b/pulse/pulse.go @@ -341,6 +341,24 @@ func (c *Context) MoveSourceOutputsByIndex(sourceOutputs []uint32, sourceIdx uin }) } +// GetModuleList retrieves the list of loaded modules +func (c *Context) GetModuleList() (r []*Module) { + ck := newCookie() + + c.safeDo(func() { + C._get_module_info_list(c.loop, c.ctx, C.int64_t(ck.id)) + }) + + for _, info := range ck.ReplyList() { + module := info.data.(*Module) + if module == nil { + continue + } + r = append(r, module) + } + return +} + var ( __context *Context __ctxLocker sync.Mutex diff --git a/pulse/sync.go b/pulse/sync.go index d811dfe..08fab4c 100644 --- a/pulse/sync.go +++ b/pulse/sync.go @@ -38,6 +38,8 @@ func NewPaInfo(data unsafe.Pointer, Type int) *paInfo { info.data = toServerInfo((*C.pa_server_info)(data)) case C.PA_SUBSCRIPTION_EVENT_CARD: info.data = toCardInfo((*C.pa_card_info)(data)) + case C.PA_SUBSCRIPTION_EVENT_MODULE: + info.data = toModuleInfo((*C.pa_module_info)(data)) default: // current didn't support this type return nil diff --git a/pulse/wrap.go b/pulse/wrap.go index 967283b..68f7226 100644 --- a/pulse/wrap.go +++ b/pulse/wrap.go @@ -154,3 +154,26 @@ type SampleSpec struct { Rate uint32 Channels uint8 } + +type Module struct { + Index uint32 + Name string + Argument string + NUsed uint32 + AutoUnload int // deprecated, but keep for completeness + PropList map[string]string +} + +func toModuleInfo(info *C.pa_module_info) *Module { + if info == nil { + return nil + } + return &Module{ + Index: uint32(info.index), + Name: C.GoString(info.name), + Argument: C.GoString(info.argument), + NUsed: uint32(info.n_used), + AutoUnload: int(info.auto_unload), + PropList: toProplist(info.proplist), + } +}