5 * Copyright (C) 2007-2008 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 int __connman_storage_init(void)
35 void __connman_storage_cleanup(void)
40 int __connman_element_load(struct connman_element *element)
42 DBG("element %p name %s", element, element->name);
47 static void do_update(GKeyFile *keyfile, struct connman_element *element)
51 DBG("element %p name %s", element, element->name);
53 g_key_file_set_string(keyfile, element->path, "Name", element->name);
55 g_key_file_set_boolean(keyfile, element->path, "Enabled",
58 connman_element_lock(element);
60 for (list = element->properties; list; list = list->next) {
61 struct connman_property *property = list->data;
63 if (property->flags & CONNMAN_PROPERTY_FLAG_STATIC)
66 if (property->flags & CONNMAN_PROPERTY_FLAG_REFERENCE)
69 if (property->type == DBUS_TYPE_STRING)
70 g_key_file_set_string(keyfile, element->path,
71 property->name, property->value);
74 connman_element_unlock(element);
77 int __connman_element_store(struct connman_element *element)
80 gchar *pathname, *data = NULL;
83 DBG("element %p name %s", element, element->name);
85 pathname = g_strdup_printf("%s/elements.conf", STORAGEDIR);
89 keyfile = g_key_file_new();
91 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE)
95 if (g_key_file_load_from_data(keyfile, data, length,
96 G_KEY_FILE_KEEP_COMMENTS, NULL) == FALSE)
103 do_update(keyfile, element);
105 data = g_key_file_to_data(keyfile, &length, NULL);
107 g_file_set_contents(pathname, data, length, NULL);
112 g_key_file_free(keyfile);