5 * Copyright (C) 2007-2009 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 static GSList *storage_list = NULL;
30 static gint compare_priority(gconstpointer a, gconstpointer b)
32 const struct connman_storage *storage1 = a;
33 const struct connman_storage *storage2 = b;
35 return storage2->priority - storage1->priority;
39 * connman_storage_register:
40 * @storage: storage module
42 * Register a new storage module
44 * Returns: %0 on success
46 int connman_storage_register(struct connman_storage *storage)
48 DBG("storage %p name %s", storage, storage->name);
50 storage_list = g_slist_insert_sorted(storage_list, storage,
57 * connman_storage_unregister:
58 * @storage: storage module
60 * Remove a previously registered storage module
62 void connman_storage_unregister(struct connman_storage *storage)
64 DBG("storage %p name %s", storage, storage->name);
66 storage_list = g_slist_remove(storage_list, storage);
69 GKeyFile *__connman_storage_open(void)
72 gchar *pathname, *data = NULL;
78 pathname = g_strdup_printf("%s/%s.conf", STORAGEDIR,
79 __connman_profile_active_ident());
83 result = g_file_get_contents(pathname, &data, &length, NULL);
90 keyfile = g_key_file_new();
93 if (g_key_file_load_from_data(keyfile, data, length,
101 DBG("keyfile %p", keyfile);
106 void __connman_storage_close(GKeyFile *keyfile, gboolean save)
108 gchar *pathname, *data = NULL;
111 DBG("keyfile %p save %d", keyfile, save);
114 g_key_file_free(keyfile);
118 pathname = g_strdup_printf("%s/%s.conf", STORAGEDIR,
119 __connman_profile_active_ident());
120 if (pathname == NULL)
123 data = g_key_file_to_data(keyfile, &length, NULL);
125 if (g_file_set_contents(pathname, data, length, NULL) == FALSE)
126 connman_error("Failed to store information");
132 g_key_file_free(keyfile);
135 int __connman_storage_load_global(void)
141 for (list = storage_list; list; list = list->next) {
142 struct connman_storage *storage = list->data;
144 if (storage->global_load) {
145 if (storage->global_load() == 0)
153 int __connman_storage_save_global(void)
159 for (list = storage_list; list; list = list->next) {
160 struct connman_storage *storage = list->data;
162 if (storage->global_save) {
163 if (storage->global_save() == 0)
171 int __connman_storage_load_device(struct connman_device *device)
175 DBG("device %p", device);
177 for (list = storage_list; list; list = list->next) {
178 struct connman_storage *storage = list->data;
180 if (storage->device_load) {
181 if (storage->device_load(device) == 0)
189 int __connman_storage_save_device(struct connman_device *device)
193 DBG("device %p", device);
195 for (list = storage_list; list; list = list->next) {
196 struct connman_storage *storage = list->data;
198 if (storage->device_save) {
199 if (storage->device_save(device) == 0)
207 int __connman_storage_load_service(struct connman_service *service)
211 DBG("service %p", service);
213 for (list = storage_list; list; list = list->next) {
214 struct connman_storage *storage = list->data;
216 if (storage->service_load) {
217 if (storage->service_load(service) == 0)
225 int __connman_storage_save_service(struct connman_service *service)
229 DBG("service %p", service);
231 for (list = storage_list; list; list = list->next) {
232 struct connman_storage *storage = list->data;
234 if (storage->service_save) {
235 if (storage->service_save(service) == 0)
243 int __connman_storage_init(void)
250 void __connman_storage_cleanup(void)