From f8ec8f382ff1e9a05296b5a656195d44e8d05b44 Mon Sep 17 00:00:00 2001 From: Colin Guthrie Date: Sun, 20 Sep 2009 12:44:02 +0100 Subject: [PATCH] device-manager: Change the write function to a rename function. The structure itself will contain various bits of info so exposing this fully to the client is a bad idea. By keeping to a rename operation we keep what we do store abstracted from the clients. Also fix some doxy comments. --- src/modules/module-device-manager.c | 63 +++++++++++++++++-------------------- src/pulse/ext-device-manager.c | 40 ++++++----------------- src/pulse/ext-device-manager.h | 16 +++++----- 3 files changed, 44 insertions(+), 75 deletions(-) diff --git a/src/modules/module-device-manager.c b/src/modules/module-device-manager.c index 740b98fa..0a0c39dc 100644 --- a/src/modules/module-device-manager.c +++ b/src/modules/module-device-manager.c @@ -109,7 +109,7 @@ struct entry { enum { SUBCOMMAND_TEST, SUBCOMMAND_READ, - SUBCOMMAND_WRITE, + SUBCOMMAND_RENAME, SUBCOMMAND_DELETE, SUBCOMMAND_ROLE_DEVICE_PRIORITY_ROUTING, SUBCOMMAND_PREFER_DEVICE, @@ -451,51 +451,41 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio break; } - case SUBCOMMAND_WRITE: { - uint32_t mode; - pa_bool_t apply_immediately = FALSE; + case SUBCOMMAND_RENAME: { - if (pa_tagstruct_getu32(t, &mode) < 0 || - pa_tagstruct_get_boolean(t, &apply_immediately) < 0) - goto fail; - - if (mode != PA_UPDATE_MERGE && - mode != PA_UPDATE_REPLACE && - mode != PA_UPDATE_SET) - goto fail; - - if (mode == PA_UPDATE_SET) - pa_database_clear(u->database); - - while (!pa_tagstruct_eof(t)) { - const char *name, *description; - struct entry entry; - pa_datum key, data; - - pa_zero(entry); - entry.version = ENTRY_VERSION; + struct entry *e; + const char *device, *description; - if (pa_tagstruct_gets(t, &name) < 0 || + if (pa_tagstruct_gets(t, &device) < 0 || pa_tagstruct_gets(t, &description) < 0) goto fail; - if (!name || !*name) + if (!device || !*device || !description || !*description) goto fail; - pa_strlcpy(entry.description, description, sizeof(entry.description)); + if ((e = read_entry(u, device)) && ENTRY_VERSION == e->version) { + pa_datum key, data; - key.data = (char*) name; - key.size = strlen(name); + pa_strlcpy(e->description, description, sizeof(e->description)); - data.data = &entry; - data.size = sizeof(entry); + key.data = (char *) device; + key.size = strlen(device); - if (pa_database_set(u->database, &key, &data, mode == PA_UPDATE_REPLACE) == 0) - if (apply_immediately) - apply_entry(u, name, &entry); - } + data.data = e; + data.size = sizeof(*e); - trigger_save(u); + if (pa_database_set(u->database, &key, &data, FALSE) == 0) { + apply_entry(u, device, e); + + trigger_save(u); + } + else + pa_log_warn("Could not save device"); + + pa_xfree(e); + } + else + pa_log_warn("Could not rename device %s, no entry in database", device); break; } @@ -671,6 +661,9 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio pa_xfree(prefix); } + else + pa_log_warn("Could not reorder device %s, no entry in database", device); + break; } diff --git a/src/pulse/ext-device-manager.c b/src/pulse/ext-device-manager.c index a634e212..bc6301ca 100644 --- a/src/pulse/ext-device-manager.c +++ b/src/pulse/ext-device-manager.c @@ -39,7 +39,7 @@ enum { SUBCOMMAND_TEST, SUBCOMMAND_READ, - SUBCOMMAND_WRITE, + SUBCOMMAND_RENAME, SUBCOMMAND_DELETE, SUBCOMMAND_ROLE_DEVICE_PRIORITY_ROUTING, SUBCOMMAND_PREFER_DEVICE, @@ -183,12 +183,10 @@ pa_operation *pa_ext_device_manager_read( return o; } -pa_operation *pa_ext_device_manager_write( +pa_operation *pa_ext_device_manager_set_device_description( pa_context *c, - pa_update_mode_t mode, - const pa_ext_device_manager_info data[], - unsigned n, - int apply_immediately, + const char* device, + const char* description, pa_context_success_cb_t cb, void *userdata) { @@ -198,8 +196,8 @@ pa_operation *pa_ext_device_manager_write( pa_assert(c); pa_assert(PA_REFCNT_VALUE(c) >= 1); - pa_assert(mode == PA_UPDATE_MERGE || mode == PA_UPDATE_REPLACE || mode == PA_UPDATE_SET); - pa_assert(data); + pa_assert(device); + pa_assert(description); 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); @@ -210,35 +208,15 @@ pa_operation *pa_ext_device_manager_write( t = pa_tagstruct_command(c, PA_COMMAND_EXTENSION, &tag); pa_tagstruct_putu32(t, PA_INVALID_INDEX); pa_tagstruct_puts(t, "module-device-manager"); - pa_tagstruct_putu32(t, SUBCOMMAND_WRITE); - - pa_tagstruct_putu32(t, mode); - pa_tagstruct_put_boolean(t, apply_immediately); - - for (; n > 0; n--, data++) { - if (!data->name || !*data->name) - goto fail; + pa_tagstruct_putu32(t, SUBCOMMAND_RENAME); - pa_tagstruct_puts(t, data->name); - pa_tagstruct_puts(t, data->description); - } + pa_tagstruct_puts(t, device); + pa_tagstruct_puts(t, description); 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; - -fail: - if (o) { - pa_operation_cancel(o); - pa_operation_unref(o); - } - - if (t) - pa_tagstruct_free(t); - - pa_context_set_error(c, PA_ERR_INVALID); - return NULL; } pa_operation *pa_ext_device_manager_delete( diff --git a/src/pulse/ext-device-manager.h b/src/pulse/ext-device-manager.h index d6de1320..686c8d22 100644 --- a/src/pulse/ext-device-manager.h +++ b/src/pulse/ext-device-manager.h @@ -65,13 +65,11 @@ pa_operation *pa_ext_device_manager_read( pa_ext_device_manager_read_cb_t cb, void *userdata); -/** Store entries in the device database. \since 0.9.19 */ -pa_operation *pa_ext_device_manager_write( +/** Sets the description for a device. \since 0.9.19 */ +pa_operation *pa_ext_device_manager_set_device_description( pa_context *c, - pa_update_mode_t mode, - const pa_ext_device_manager_info data[], - unsigned n, - int apply_immediately, + const char* device, + const char* description, pa_context_success_cb_t cb, void *userdata); @@ -82,14 +80,14 @@ pa_operation *pa_ext_device_manager_delete( pa_context_success_cb_t cb, void *userdata); -/** Subscribe to changes in the device database. \since 0.9.19 */ +/** Enable the role-based device-priority routing mode. \since 0.9.19 */ pa_operation *pa_ext_device_manager_enable_role_device_priority_routing( pa_context *c, int enable, pa_context_success_cb_t cb, void *userdata); -/** Subscribe to changes in the device database. \since 0.9.19 */ +/** Prefer a given device in the priority list. \since 0.9.19 */ pa_operation *pa_ext_device_manager_prefer_device( pa_context *c, const char* role, @@ -97,7 +95,7 @@ pa_operation *pa_ext_device_manager_prefer_device( pa_context_success_cb_t cb, void *userdata); -/** Subscribe to changes in the device database. \since 0.9.19 */ +/** Defer a given device in the priority list. \since 0.9.19 */ pa_operation *pa_ext_device_manager_defer_device( pa_context *c, const char* role, -- 2.11.4.GIT