The native protocol should handle unloading modules by name. This updates the protocol and client API. BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=48289 --- PROTOCOL | 7 +++++++ configure.ac | 2 +- src/map-file | 2 ++ src/pulse/introspect.c | 31 ++++++++++++++++++++++++++++++- src/pulse/introspect.h | 12 +++++++++--- src/pulsecore/native-common.h | 5 ++++- src/pulsecore/protocol-native.c | 30 ++++++++++++++++++++++++++---- 7 files changed, 79 insertions(+), 10 deletions(-) diff --git a/PROTOCOL b/PROTOCOL index acd53ba..9b8c9fe 100644 --- a/PROTOCOL +++ b/PROTOCOL @@ -321,6 +321,13 @@ PA_COMMAND_GET_CARD_INFO_LIST), the following is added: Profile names must match earlier sent profile names for the same card. +## v27, implemented by >= 3.0 + +Renamed opcodes: + PA_COMMAND_UNLOAD_MODULE -> PA_COMMAND_UNLOAD_MODULE_BY_INDEX + +New opcodes: + PA_COMMAND_UNLOAD_MODULE_BY_NAME #### If you just changed the protocol, read this ## module-tunnel depends on the sink/source/sink-input/source-input protocol diff --git a/configure.ac b/configure.ac index f5f9b76..62cc5f8 100644 --- a/configure.ac +++ b/configure.ac @@ -36,7 +36,7 @@ AC_SUBST(PA_MINOR, pa_minor) AC_SUBST(PA_MAJORMINOR, pa_major.pa_minor) AC_SUBST(PA_API_VERSION, 12) -AC_SUBST(PA_PROTOCOL_VERSION, 26) +AC_SUBST(PA_PROTOCOL_VERSION, 27) # The stable ABI for client applications, for the version info x:y:z # always will hold y=z diff --git a/src/map-file b/src/map-file index 69cf25b..4a9b95b 100644 --- a/src/map-file +++ b/src/map-file @@ -114,6 +114,8 @@ pa_context_suspend_sink_by_name; pa_context_suspend_source_by_index; pa_context_suspend_source_by_name; pa_context_unload_module; +pa_context_unload_module_by_index; +pa_context_unload_module_by_name; pa_context_unref; pa_cvolume_avg; pa_cvolume_avg_mask; diff --git a/src/pulse/introspect.c b/src/pulse/introspect.c index 38a9d1c..e251bcc 100644 --- a/src/pulse/introspect.c +++ b/src/pulse/introspect.c @@ -1864,8 +1864,37 @@ pa_operation* pa_context_load_module(pa_context *c, const char*name, const char return o; } +PA_WARN_REFERENCE(pa_context_unload_module, "This function is deprecated, use pa_context_unload_module_by_{name,index}"); + pa_operation* pa_context_unload_module(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void *userdata) { - return command_kill(c, PA_COMMAND_UNLOAD_MODULE, idx, cb, userdata); + return command_kill(c, PA_COMMAND_UNLOAD_MODULE_BY_INDEX, idx, cb, userdata); +} + +pa_operation* pa_context_unload_module_by_index(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void *userdata) { + return command_kill(c, PA_COMMAND_UNLOAD_MODULE_BY_INDEX, idx, cb, userdata); +} + +pa_operation* pa_context_unload_module_by_name(pa_context *c, const char *name, pa_context_success_cb_t cb, void *userdata) { + pa_operation *o; + pa_tagstruct *t; + uint32_t tag; + + pa_assert(c); + pa_assert(PA_REFCNT_VALUE(c) >= 1); + + PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED); + PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE); + PA_CHECK_VALIDITY_RETURN_NULL(c, name && *name, PA_ERR_INVALID); + PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 27, PA_ERR_NOTSUPPORTED); + + o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata); + + t = pa_tagstruct_command(c, PA_COMMAND_UNLOAD_MODULE_BY_NAME, &tag); + pa_tagstruct_puts(t, name); + pa_pstream_send_tagstruct(c->pstream, t); + pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref); + + return o; } /*** Autoload stuff ***/ diff --git a/src/pulse/introspect.h b/src/pulse/introspect.h index 0072f5d..203798c 100644 --- a/src/pulse/introspect.h +++ b/src/pulse/introspect.h @@ -176,7 +176,7 @@ * \subsection module_subsec Modules * * Server modules can be remotely loaded and unloaded using - * pa_context_load_module() and pa_context_unload_module(). + * pa_context_load_module() and pa_context_unload_module_by_{name|index}(). * * \subsection client_subsec Clients * @@ -409,8 +409,14 @@ typedef void (*pa_context_index_cb_t)(pa_context *c, uint32_t idx, void *userdat /** Load a module. */ pa_operation* pa_context_load_module(pa_context *c, const char*name, const char *argument, pa_context_index_cb_t cb, void *userdata); -/** Unload a module. */ -pa_operation* pa_context_unload_module(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void *userdata); +/** \deprecated Unload a module. */ +pa_operation* pa_context_unload_module(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void *userdata) PA_GCC_DEPRECATED; + +/** Unload a module by its index. \since 3.0 */ +pa_operation* pa_context_unload_module_by_index(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void *userdata); + +/** Unload a module by its name. \since 3.0 */ +pa_operation* pa_context_unload_module_by_name(pa_context *c, const char*name, pa_context_success_cb_t cb, void *userdata); /** @} */ diff --git a/src/pulsecore/native-common.h b/src/pulsecore/native-common.h index 8fde023..1b50e01 100644 --- a/src/pulsecore/native-common.h +++ b/src/pulsecore/native-common.h @@ -92,7 +92,7 @@ enum { PA_COMMAND_KILL_SOURCE_OUTPUT, PA_COMMAND_LOAD_MODULE, - PA_COMMAND_UNLOAD_MODULE, + PA_COMMAND_UNLOAD_MODULE_BY_INDEX, /* Obsolete */ PA_COMMAND_ADD_AUTOLOAD___OBSOLETE, @@ -173,6 +173,9 @@ enum { PA_COMMAND_SET_SOURCE_OUTPUT_VOLUME, PA_COMMAND_SET_SOURCE_OUTPUT_MUTE, + /* Supported since protocol v27 (3.0) */ + PA_COMMAND_UNLOAD_MODULE_BY_NAME, + PA_COMMAND_MAX }; diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c index 396e143..6ec1cbc 100644 --- a/src/pulsecore/protocol-native.c +++ b/src/pulsecore/protocol-native.c @@ -280,7 +280,8 @@ static void command_set_default_sink_or_source(pa_pdispatch *pd, uint32_t comman static void command_set_stream_name(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata); static void command_kill(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata); static void command_load_module(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata); -static void command_unload_module(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata); +static void command_unload_module_by_index(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata); +static void command_unload_module_by_name(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata); static void command_cork_record_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata); static void command_flush_record_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata); static void command_move_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata); @@ -364,7 +365,8 @@ static const pa_pdispatch_cb_t command_table[PA_COMMAND_MAX] = { [PA_COMMAND_KILL_SINK_INPUT] = command_kill, [PA_COMMAND_KILL_SOURCE_OUTPUT] = command_kill, [PA_COMMAND_LOAD_MODULE] = command_load_module, - [PA_COMMAND_UNLOAD_MODULE] = command_unload_module, + [PA_COMMAND_UNLOAD_MODULE_BY_INDEX] = command_unload_module_by_index, + [PA_COMMAND_UNLOAD_MODULE_BY_NAME] = command_unload_module_by_name, [PA_COMMAND_GET_AUTOLOAD_INFO___OBSOLETE] = NULL, [PA_COMMAND_GET_AUTOLOAD_INFO_LIST___OBSOLETE] = NULL, @@ -393,7 +395,7 @@ static const pa_pdispatch_cb_t command_table[PA_COMMAND_MAX] = { [PA_COMMAND_SET_SINK_PORT] = command_set_sink_or_source_port, [PA_COMMAND_SET_SOURCE_PORT] = command_set_sink_or_source_port, - [PA_COMMAND_EXTENSION] = command_extension + [PA_COMMAND_EXTENSION] = command_extension, }; /* structure management */ @@ -4431,7 +4433,7 @@ static void command_load_module(pa_pdispatch *pd, uint32_t command, uint32_t tag pa_pstream_send_tagstruct(c->pstream, reply); } -static void command_unload_module(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { +static void command_unload_module_by_index(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_native_connection *c = PA_NATIVE_CONNECTION(userdata); uint32_t idx; pa_module *m; @@ -4453,6 +4455,26 @@ static void command_unload_module(pa_pdispatch *pd, uint32_t command, uint32_t t pa_pstream_send_simple_ack(c->pstream, tag); } +static void command_unload_module_by_name(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { + pa_native_connection *c = PA_NATIVE_CONNECTION(userdata); + const char *name; + + pa_native_connection_assert_ref(c); + pa_assert(t); + + if (pa_tagstruct_gets(t, &name) < 0 || + !pa_tagstruct_eof(t)) { + protocol_error(c); + } + + CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS); + CHECK_VALIDITY(c->pstream, name, tag, PA_ERR_INVALID); + + /** Todo add error reporting if no module is unloaded */ + pa_module_unload_request_by_name(c->protocol->core, name, FALSE); + pa_pstream_send_simple_ack(c->pstream, tag); +} + static void command_move_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { pa_native_connection *c = PA_NATIVE_CONNECTION(userdata); uint32_t idx = PA_INVALID_INDEX, idx_device = PA_INVALID_INDEX; -- 1.7.10.2