static const period_ms_t CONFIG_SETTLE_PERIOD_MS = 3000;
static void timer_config_save_cb(void *data);
-static void btif_config_write(void);
+static void btif_config_write(UINT16 event, char *p_param);
- static void btif_config_devcache_cleanup(void);
+ static void btif_config_remove_unpaired(config_t *config);
// TODO(zachoverflow): Move these two functions out, because they are too specific for this file
// {grumpy-cat/no, monty-python/you-make-me-sad}
pthread_mutex_init(&lock, NULL);
config = config_new(CONFIG_FILE_PATH);
if (!config) {
- LOG_WARN("%s unable to load config file: %s; using backup.",
- __func__, CONFIG_FILE_PATH);
- config = config_new(CONFIG_BACKUP_PATH);
- }
- if (!config) {
- LOG_WARN("%s unable to load backup; attempting to transcode legacy file.", __func__);
- config = btif_config_transcode(CONFIG_LEGACY_FILE_PATH);
- }
- if (!config) {
- LOG_ERROR("%s unable to transcode legacy file; creating empty config.", __func__);
- config = config_new_empty();
- }
- if (!config) {
- LOG_ERROR("%s unable to allocate a config object.", __func__);
- goto error;
+ LOG_WARN("%s unable to load config file; attempting to transcode legacy file.", __func__);
+ config = btif_config_transcode(LEGACY_CONFIG_FILE_PATH);
+ if (!config) {
+ LOG_WARN("%s unable to transcode legacy file, starting unconfigured.", __func__);
+ config = config_new_empty();
+ if (!config) {
+ LOG_ERROR("%s unable to allocate a config object.", __func__);
+ goto error;
+ }
+ }
+
+ if (config_save(config, CONFIG_FILE_PATH))
+ unlink(LEGACY_CONFIG_FILE_PATH);
}
- btif_config_devcache_cleanup();
+ btif_config_remove_unpaired(config);
// TODO(sharvil): use a non-wake alarm for this once we have
// API support for it. There's no need to wake the system to
assert(alarm_timer != NULL);
alarm_cancel(alarm_timer);
- btif_config_write();
+ btif_config_write(0, NULL);
-
- pthread_mutex_lock(&lock);
- config_save(config, CONFIG_FILE_PATH);
- pthread_mutex_unlock(&lock);
}
-bool btif_config_clear(void){
+int btif_config_clear(void){
assert(config != NULL);
assert(alarm_timer != NULL);
assert(config != NULL);
assert(alarm_timer != NULL);
- btif_config_devcache_cleanup();
-
pthread_mutex_lock(&lock);
- config_save(config, CONFIG_FILE_PATH);
- rename(CONFIG_FILE_PATH, CONFIG_BACKUP_PATH);
- sync();
+ config_t *config_paired = config_new_clone(config);
+ btif_config_remove_unpaired(config_paired);
+ config_save(config_paired, CONFIG_FILE_PATH);
+ config_free(config_paired);
pthread_mutex_unlock(&lock);
}