From d8438b083a72749366a62921fa6b4969c84d91f1 Mon Sep 17 00:00:00 2001 From: fuleyi Date: Fri, 31 Oct 2025 15:55:05 +0800 Subject: [PATCH] feat: add module unloading functionality MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Implement UnloadModule function to unload modules by index 2. Add UnloadModuleByName helper to unload modules by name 3. Use safeDo wrapper for thread-safe PulseAudio operations 4. Follow existing pattern of operation cleanup with pa_operation_unref 5. Provide both direct index-based and name-based unloading options Influence: 1. Test unloading modules with valid and invalid indices 2. Verify UnloadModuleByName finds and unloads correct modules 3. Test behavior when module name doesn't exist 4. Verify thread safety during concurrent unload operations 5. Test module state after unloading 6. Verify no memory leaks from operation cleanup feat: 添加模块卸载功能 1. 实现 UnloadModule 函数通过索引卸载模块 2. 添加 UnloadModuleByName 辅助函数通过名称卸载模块 3. 使用 safeDo 包装器确保 PulseAudio 操作线程安全 4. 遵循现有的 pa_operation_unref 操作清理模式 5. 提供基于索引和基于名称的卸载选项 Influence: 1. 测试使用有效和无效索引卸载模块 2. 验证 UnloadModuleByName 能正确找到并卸载模块 3. 测试模块名称不存在时的行为 4. 验证并发卸载操作期间的线程安全性 5. 测试卸载后模块状态 6. 验证操作清理无内存泄漏 --- pulse/pulse.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pulse/pulse.go b/pulse/pulse.go index aa460bd..2efce9b 100644 --- a/pulse/pulse.go +++ b/pulse/pulse.go @@ -510,3 +510,22 @@ func (c *Context) LoadModule(name, argument string) { C.pa_operation_unref(op) }) } + +// UnloadModule unloads a module by its index +func (c *Context) UnloadModule(index uint32) { + c.safeDo(func() { + op := C.pa_context_unload_module(c.ctx, C.uint32_t(index), C.get_success_cb(), nil) + C.pa_operation_unref(op) + }) +} + +// UnloadModuleByName unloads the first module matching the given name +func (c *Context) UnloadModuleByName(name string) { + modules := c.GetModuleList() + for _, module := range modules { + if module.Name == name { + c.UnloadModule(module.Index) + return + } + } +}