database: extract common method to handle machine id and architecture

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/425>
This commit is contained in:
Igor V. Kovalenko 2020-11-29 11:21:29 +03:00 committed by PulseAudio Marge Bot
parent 0efae0488c
commit 0ac6b16787
12 changed files with 154 additions and 65 deletions

View file

@ -618,7 +618,7 @@ static pa_hook_result_t card_preferred_port_changed_callback(pa_core *core, pa_c
int pa__init(pa_module*m) {
pa_modargs *ma = NULL;
struct userdata *u;
char *fname;
char *state_path;
bool restore_bluetooth_profile;
pa_assert(m);
@ -648,17 +648,15 @@ int pa__init(pa_module*m) {
pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_CARD_PROFILE_ADDED], PA_HOOK_NORMAL, (pa_hook_cb_t) card_profile_added_callback, u);
pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_PORT_LATENCY_OFFSET_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) port_offset_change_callback, u);
if (!(fname = pa_state_path("card-database", true)))
if (!(state_path = pa_state_path(NULL, true)))
goto fail;
if (!(u->database = pa_database_open(fname, true))) {
pa_log("Failed to open volume database '%s': %s", fname, pa_cstrerror(errno));
pa_xfree(fname);
if (!(u->database = pa_database_open(state_path, "card-database", true, true))) {
pa_xfree(state_path);
goto fail;
}
pa_log_info("Successfully opened database file '%s'.", fname);
pa_xfree(fname);
pa_xfree(state_path);
pa_modargs_free(ma);
return 0;

View file

@ -1544,7 +1544,7 @@ struct prioritised_indexes {
int pa__init(pa_module*m) {
pa_modargs *ma = NULL;
struct userdata *u;
char *fname;
char *state_path;
pa_sink *sink;
pa_source *source;
uint32_t idx;
@ -1601,17 +1601,15 @@ int pa__init(pa_module*m) {
u->source_unlink_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK], PA_HOOK_LATE+5, (pa_hook_cb_t) source_unlink_hook_callback, u);
}
if (!(fname = pa_state_path("device-manager", true)))
if (!(state_path = pa_state_path(NULL, true)))
goto fail;
if (!(u->database = pa_database_open(fname, true))) {
pa_log("Failed to open volume database '%s': %s", fname, pa_cstrerror(errno));
pa_xfree(fname);
if (!(u->database = pa_database_open(state_path, "device-manager", true, true))) {
pa_xfree(state_path);
goto fail;
}
pa_log_info("Successfully opened database file '%s'.", fname);
pa_xfree(fname);
pa_xfree(state_path);
/* Attempt to inject the devices into the list in priority order */
total_devices = PA_MAX(pa_idxset_size(m->core->sinks), pa_idxset_size(m->core->sources));

View file

@ -1202,7 +1202,7 @@ static pa_hook_result_t connection_unlink_hook_cb(pa_native_protocol *p, pa_nati
int pa__init(pa_module*m) {
pa_modargs *ma = NULL;
struct userdata *u;
char *fname;
char *state_path;
pa_sink *sink;
pa_source *source;
uint32_t idx;
@ -1259,17 +1259,15 @@ int pa__init(pa_module*m) {
if (restore_formats)
pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_EARLY, (pa_hook_cb_t) sink_put_hook_callback, u);
if (!(fname = pa_state_path("device-volumes", true)))
if (!(state_path = pa_state_path(NULL, true)))
goto fail;
if (!(u->database = pa_database_open(fname, true))) {
pa_log("Failed to open volume database '%s': %s", fname, pa_cstrerror(errno));
pa_xfree(fname);
if (!(u->database = pa_database_open(state_path, "device-volumes", true, true))) {
pa_xfree(state_path);
goto fail;
}
pa_log_info("Successfully opened database file '%s'.", fname);
pa_xfree(fname);
pa_xfree(state_path);
PA_IDXSET_FOREACH(sink, m->core->sinks, idx)
subscribe_callback(m->core, PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_NEW, sink->index, u);

View file

@ -946,7 +946,7 @@ static void save_state(struct userdata *u) {
float *H;
pa_datum key, data;
pa_database *database;
char *dbname;
char *state_path;
char *packed;
size_t packed_length;
@ -969,9 +969,9 @@ static void save_state(struct userdata *u) {
data.data = state;
data.size = filter_state_size + packed_length;
//thread safety for 0.9.17?
pa_assert_se(dbname = pa_state_path(EQ_STATE_DB, false));
pa_assert_se(database = pa_database_open(dbname, true));
pa_xfree(dbname);
pa_assert_se(state_path = pa_state_path(NULL, false));
pa_assert_se(database = pa_database_open(state_path, EQ_STATE_DB, false, true));
pa_xfree(state_path);
pa_database_set(database, &key, &data, true);
pa_database_sync(database);
@ -1020,10 +1020,10 @@ static void load_state(struct userdata *u) {
float *H;
pa_datum key, value;
pa_database *database;
char *dbname;
pa_assert_se(dbname = pa_state_path(EQ_STATE_DB, false));
database = pa_database_open(dbname, false);
pa_xfree(dbname);
char *state_path;
pa_assert_se(state_path = pa_state_path(NULL, false));
database = pa_database_open(state_path, EQ_STATE_DB, false, false);
pa_xfree(state_path);
if (!database) {
pa_log("No resume state");
return;
@ -1626,12 +1626,12 @@ void dbus_init(struct userdata *u) {
sink_list = pa_shared_get(u->sink->core, SINKLIST);
u->database = pa_shared_get(u->sink->core, EQDB);
if (sink_list == NULL) {
char *dbname;
char *state_path;
sink_list=pa_idxset_new(&pa_idxset_trivial_hash_func, &pa_idxset_trivial_compare_func);
pa_shared_set(u->sink->core, SINKLIST, sink_list);
pa_assert_se(dbname = pa_state_path("equalizer-presets", false));
pa_assert_se(u->database = pa_database_open(dbname, true));
pa_xfree(dbname);
pa_assert_se(state_path = pa_state_path(NULL, false));
pa_assert_se(u->database = pa_database_open(state_path, "equalizer-presets", false, true));
pa_xfree(state_path);
pa_shared_set(u->sink->core, EQDB, u->database);
pa_dbus_protocol_add_interface(u->dbus_protocol, MANAGER_PATH, &manager_info, u->sink->core);
pa_dbus_protocol_register_extension(u->dbus_protocol, EXTNAME);

View file

@ -2266,7 +2266,7 @@ static void clean_up_db(struct userdata *u) {
int pa__init(pa_module*m) {
pa_modargs *ma = NULL;
struct userdata *u;
char *fname;
char *state_path;
pa_sink_input *si;
pa_source_output *so;
uint32_t idx;
@ -2324,17 +2324,15 @@ int pa__init(pa_module*m) {
pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_FIXATE], PA_HOOK_EARLY, (pa_hook_cb_t) source_output_fixate_hook_callback, u);
}
if (!(fname = pa_state_path("stream-volumes", true)))
if (!(state_path = pa_state_path(NULL, true)))
goto fail;
if (!(u->database = pa_database_open(fname, true))) {
pa_log("Failed to open volume database '%s': %s", fname, pa_cstrerror(errno));
pa_xfree(fname);
if (!(u->database = pa_database_open(state_path, "stream-volumes", true, true))) {
pa_xfree(state_path);
goto fail;
}
pa_log_info("Successfully opened database file '%s'.", fname);
pa_xfree(fname);
pa_xfree(state_path);
clean_up_db(u);