3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-16 17:09:24 +01:00

knownnetwork: add known_network_frequency_sync

This API will sync the known frequencies of a network_info object
to disk. This will allow network to sync known frequencies as
known networks are added, rather that when IWD closes.

Since this will result in more frequent syncing that before, the
known_freqs settings pointer was moved globally in knownnetworks.c
as to only parse the file one time rather than on every sync.
This commit is contained in:
James Prestwood 2019-09-12 09:53:34 -07:00 committed by Denis Kenzior
parent 3dba205de1
commit 9ed5fba57b
2 changed files with 18 additions and 31 deletions

View File

@ -46,6 +46,7 @@ static struct l_queue *known_networks;
static size_t num_known_hidden_networks; static size_t num_known_hidden_networks;
static struct l_dir_watch *storage_dir_watch; static struct l_dir_watch *storage_dir_watch;
static struct watchlist known_network_watches; static struct watchlist known_network_watches;
static struct l_settings *known_freqs;
static void network_info_free(void *data) static void network_info_free(void *data)
{ {
@ -737,7 +738,6 @@ static char *known_frequencies_to_string(struct l_queue *known_frequencies)
static void known_network_frequencies_load(void) static void known_network_frequencies_load(void)
{ {
char **network_names; char **network_names;
struct l_settings *known_freqs;
struct l_queue *known_frequencies; struct l_queue *known_frequencies;
uint32_t i; uint32_t i;
@ -782,45 +782,31 @@ next:
done: done:
l_strv_free(network_names); l_strv_free(network_names);
l_settings_free(known_freqs);
} }
static bool known_network_frequencies_to_settings( /*
const struct network_info *network_info, * Syncs a single network_info frequency to the global frequency file
void *user_data) */
void known_network_frequency_sync(const struct network_info *info)
{ {
struct l_settings *known_freqs = user_data;
char *freq_list_str; char *freq_list_str;
char *network_path; char *file_path;
if (!network_info->known_frequencies) if (!info->known_frequencies)
return true; return;
freq_list_str = known_frequencies_to_string( if (!known_freqs)
network_info->known_frequencies); known_freqs = l_settings_new();
network_path = storage_get_network_file_path(network_info->type, freq_list_str = known_frequencies_to_string(info->known_frequencies);
network_info->ssid);
l_settings_set_value(known_freqs, network_path, "list", freq_list_str); file_path = info->ops->get_file_path(info);
l_free(network_path);
l_settings_set_value(known_freqs, file_path, "list", freq_list_str);
l_free(file_path);
l_free(freq_list_str); l_free(freq_list_str);
return true;
}
static void known_network_frequencies_sync(void)
{
struct l_settings *known_freqs;
known_freqs = l_settings_new();
known_networks_foreach(known_network_frequencies_to_settings,
known_freqs);
storage_known_frequencies_sync(known_freqs); storage_known_frequencies_sync(known_freqs);
l_settings_free(known_freqs);
} }
uint32_t known_networks_watch_add(known_networks_watch_func_t func, uint32_t known_networks_watch_add(known_networks_watch_func_t func,
@ -907,11 +893,11 @@ static void known_networks_exit(void)
l_dir_watch_destroy(storage_dir_watch); l_dir_watch_destroy(storage_dir_watch);
known_network_frequencies_sync();
l_queue_destroy(known_networks, network_info_free); l_queue_destroy(known_networks, network_info_free);
known_networks = NULL; known_networks = NULL;
l_settings_free(known_freqs);
l_dbus_unregister_interface(dbus, IWD_KNOWN_NETWORK_INTERFACE); l_dbus_unregister_interface(dbus, IWD_KNOWN_NETWORK_INTERFACE);
watchlist_destroy(&known_network_watches); watchlist_destroy(&known_network_watches);

View File

@ -88,6 +88,7 @@ struct network_info *known_networks_find(const char *ssid,
struct scan_freq_set *known_networks_get_recent_frequencies( struct scan_freq_set *known_networks_get_recent_frequencies(
uint8_t num_networks_tosearch); uint8_t num_networks_tosearch);
int known_network_add_frequency(struct network_info *info, uint32_t frequency); int known_network_add_frequency(struct network_info *info, uint32_t frequency);
void known_network_frequency_sync(const struct network_info *info);
uint32_t known_networks_watch_add(known_networks_watch_func_t func, uint32_t known_networks_watch_add(known_networks_watch_func_t func,
void *user_data, void *user_data,