There's no real configurability yet, because only one condition is supported. Support for more conditions will be added later. The syntax of the configuration option pretends to be some programming language: [General] remote-device-tunnel-enabled-condition = !device.is_monitor However, here's no real parser for the language. A proper parser may be implemented later, but for now the option values are parsed simply by comparing to a list of predefined string constants (and currently the only defined string is "!device.is_monitor"). --- src/modules/tunnel-manager/remote-device.c | 9 ++++- src/modules/tunnel-manager/tunnel-manager-config.c | 19 +++++++--- src/modules/tunnel-manager/tunnel-manager-config.h | 1 + src/modules/tunnel-manager/tunnel-manager.c | 43 ++++++++++++++++++++++ src/modules/tunnel-manager/tunnel-manager.h | 10 +++++ 5 files changed, 76 insertions(+), 6 deletions(-) diff --git a/src/modules/tunnel-manager/remote-device.c b/src/modules/tunnel-manager/remote-device.c index 859800b..137f1e1 100644 --- a/src/modules/tunnel-manager/remote-device.c +++ b/src/modules/tunnel-manager/remote-device.c @@ -343,6 +343,13 @@ static void apply_tunnel_enabled_policy(pa_tunnel_manager_remote_device *device) pa_assert(device); - enabled = !device->is_monitor; + enabled = device->tunnel_enabled; + + switch (device->server->manager->remote_device_tunnel_enabled_condition) { + case PA_TUNNEL_MANAGER_REMOTE_DEVICE_TUNNEL_ENABLED_CONDITION_NOT_MONITOR: + enabled = !device->is_monitor; + break; + } + set_tunnel_enabled(device, enabled); } diff --git a/src/modules/tunnel-manager/tunnel-manager-config.c b/src/modules/tunnel-manager/tunnel-manager-config.c index 55c9fcd..f89f0fd 100644 --- a/src/modules/tunnel-manager/tunnel-manager-config.c +++ b/src/modules/tunnel-manager/tunnel-manager-config.c @@ -31,6 +31,7 @@ #include <pulsecore/core-util.h> #include <pulsecore/namereg.h> +#define GENERAL_SECTION_NAME "General" #define REMOTE_SERVER_SECTION_NAME "RemoteServer" #define REMOTE_SERVER_SECTION_PREFIX REMOTE_SERVER_SECTION_NAME " " @@ -100,12 +101,17 @@ static int parse_config_value(pa_config_parser_state *state) { manager_config = state->userdata; - if (!state->section) { - pa_log("[%s:%u] \"%s\" is not valid in the General section.", state->filename, state->lineno, state->lvalue); - return 0; - } + if (!state->section || pa_streq(state->section, GENERAL_SECTION_NAME)) { + if (pa_streq(state->lvalue, "remote_device_tunnel_enabled_condition")) { + if (manager_config->remote_device_tunnel_enabled_condition) + config_value_free(manager_config->remote_device_tunnel_enabled_condition); - if (pa_startswith(state->section, REMOTE_SERVER_SECTION_PREFIX)) { + manager_config->remote_device_tunnel_enabled_condition = config_value_new(state->rvalue, state->filename, + state->lineno); + } else + pa_log("[%s:%u] \"%s\" is not valid in the " GENERAL_SECTION_NAME " section.", state->filename, + state->lineno, state->lvalue); + } else if (pa_startswith(state->section, REMOTE_SERVER_SECTION_PREFIX)) { int r; pa_tunnel_manager_remote_server_config *server_config; @@ -166,6 +172,9 @@ void pa_tunnel_manager_config_free(pa_tunnel_manager_config *manager_config) { pa_hashmap_free(manager_config->remote_servers); } + if (manager_config->remote_device_tunnel_enabled_condition) + config_value_free(manager_config->remote_device_tunnel_enabled_condition); + pa_xfree(manager_config); } diff --git a/src/modules/tunnel-manager/tunnel-manager-config.h b/src/modules/tunnel-manager/tunnel-manager-config.h index 8eac0e8..1a476f5 100644 --- a/src/modules/tunnel-manager/tunnel-manager-config.h +++ b/src/modules/tunnel-manager/tunnel-manager-config.h @@ -35,6 +35,7 @@ struct pa_tunnel_manager_config_value { }; struct pa_tunnel_manager_config { + pa_tunnel_manager_config_value *remote_device_tunnel_enabled_condition; pa_hashmap *remote_servers; /* name -> pa_tunnel_manager_remote_server_config */ }; diff --git a/src/modules/tunnel-manager/tunnel-manager.c b/src/modules/tunnel-manager/tunnel-manager.c index e391209..be90343 100644 --- a/src/modules/tunnel-manager/tunnel-manager.c +++ b/src/modules/tunnel-manager/tunnel-manager.c @@ -31,9 +31,36 @@ #include <pulsecore/core-util.h> #include <pulsecore/shared.h> +const char *pa_tunnel_manager_remote_device_tunnel_enabled_condition_to_string( + pa_tunnel_manager_remote_device_tunnel_enabled_condition_t condition) { + switch (condition) { + case PA_TUNNEL_MANAGER_REMOTE_DEVICE_TUNNEL_ENABLED_CONDITION_NOT_MONITOR: + return "!device.is_monitor"; + } + + pa_assert_not_reached(); +} + +int pa_tunnel_manager_remote_device_tunnel_enabled_condition_from_string( + const char *str, pa_tunnel_manager_remote_device_tunnel_enabled_condition_t *_r) { + pa_tunnel_manager_remote_device_tunnel_enabled_condition_t condition; + + pa_assert(str); + pa_assert(_r); + + if (pa_streq(str, "!device.is_monitor")) + condition = PA_TUNNEL_MANAGER_REMOTE_DEVICE_TUNNEL_ENABLED_CONDITION_NOT_MONITOR; + else + return -PA_ERR_INVALID; + + *_r = condition; + return 0; +} + static pa_tunnel_manager *tunnel_manager_new(pa_core *core) { pa_tunnel_manager *manager; pa_tunnel_manager_config *manager_config; + pa_tunnel_manager_config_value *config_value; pa_tunnel_manager_remote_server_config *server_config; void *state; @@ -41,12 +68,28 @@ static pa_tunnel_manager *tunnel_manager_new(pa_core *core) { manager = pa_xnew0(pa_tunnel_manager, 1); manager->core = core; + manager->remote_device_tunnel_enabled_condition = PA_TUNNEL_MANAGER_REMOTE_DEVICE_TUNNEL_ENABLED_CONDITION_NOT_MONITOR; manager->remote_servers = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); manager->refcnt = 1; manager_config = pa_tunnel_manager_config_new(); + config_value = manager_config->remote_device_tunnel_enabled_condition; + if (config_value) { + int r; + pa_tunnel_manager_remote_device_tunnel_enabled_condition_t condition; + + r = pa_tunnel_manager_remote_device_tunnel_enabled_condition_from_string(config_value->value, &condition); + if (r >= 0) + manager->remote_device_tunnel_enabled_condition = condition; + else + pa_log("[%s:%u] Invalid condition: \"%s\"", config_value->filename, config_value->lineno, config_value->value); + } + pa_log_debug("Created the tunnel manager."); + pa_log_debug(" Remote device tunnel enabled condition: %s", + pa_tunnel_manager_remote_device_tunnel_enabled_condition_to_string( + manager->remote_device_tunnel_enabled_condition)); PA_HASHMAP_FOREACH(server_config, manager_config->remote_servers, state) pa_tunnel_manager_remote_server_new(manager, server_config); diff --git a/src/modules/tunnel-manager/tunnel-manager.h b/src/modules/tunnel-manager/tunnel-manager.h index fbddb35..75f567d 100644 --- a/src/modules/tunnel-manager/tunnel-manager.h +++ b/src/modules/tunnel-manager/tunnel-manager.h @@ -28,8 +28,18 @@ typedef struct pa_tunnel_manager pa_tunnel_manager; +typedef enum { + PA_TUNNEL_MANAGER_REMOTE_DEVICE_TUNNEL_ENABLED_CONDITION_NOT_MONITOR, +} pa_tunnel_manager_remote_device_tunnel_enabled_condition_t; + +const char *pa_tunnel_manager_remote_device_tunnel_enabled_condition_to_string( + pa_tunnel_manager_remote_device_tunnel_enabled_condition_t condition); +int pa_tunnel_manager_remote_device_tunnel_enabled_condition_from_string( + const char *str, pa_tunnel_manager_remote_device_tunnel_enabled_condition_t *_r); + struct pa_tunnel_manager { pa_core *core; + pa_tunnel_manager_remote_device_tunnel_enabled_condition_t remote_device_tunnel_enabled_condition; pa_hashmap *remote_servers; /* name -> pa_tunnel_manager_remote_server */ unsigned refcnt; -- 1.9.3