*
* Connection Manager
*
- * Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2009 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
#include "connman.h"
-int __connman_storage_init(void)
+static GSList *storage_list = NULL;
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
{
- DBG("");
+ const struct connman_storage *storage1 = a;
+ const struct connman_storage *storage2 = b;
+
+ return storage2->priority - storage1->priority;
+}
+
+/**
+ * connman_storage_register:
+ * @storage: storage module
+ *
+ * Register a new storage module
+ *
+ * Returns: %0 on success
+ */
+int connman_storage_register(struct connman_storage *storage)
+{
+ DBG("storage %p name %s", storage, storage->name);
+
+ storage_list = g_slist_insert_sorted(storage_list, storage,
+ compare_priority);
return 0;
}
-void __connman_storage_cleanup(void)
+/**
+ * connman_storage_unregister:
+ * @storage: storage module
+ *
+ * Remove a previously registered storage module
+ */
+void connman_storage_unregister(struct connman_storage *storage)
+{
+ DBG("storage %p name %s", storage, storage->name);
+
+ storage_list = g_slist_remove(storage_list, storage);
+}
+
+int __connman_storage_init_device(void)
{
+ GSList *list;
+
DBG("");
+
+ for (list = storage_list; list; list = list->next) {
+ struct connman_storage *storage = list->data;
+
+ if (storage->device_init) {
+ if (storage->device_init() == 0)
+ return 0;
+ }
+ }
+
+ return -ENOENT;
}
-int __connman_element_load(struct connman_element *element)
+int __connman_storage_load_device(struct connman_device *device)
{
- DBG("element %p name %s", element, element->name);
+ GSList *list;
- return 0;
+ DBG("device %p", device);
+
+ for (list = storage_list; list; list = list->next) {
+ struct connman_storage *storage = list->data;
+
+ if (storage->device_load) {
+ if (storage->device_load(device) == 0)
+ return 0;
+ }
+ }
+
+ return -ENOENT;
}
-static void do_update(GKeyFile *keyfile, struct connman_element *element)
+int __connman_storage_save_device(struct connman_device *device)
{
GSList *list;
- DBG("element %p name %s", element, element->name);
+ DBG("device %p", device);
- g_key_file_set_string(keyfile, element->path, "Name", element->name);
+ for (list = storage_list; list; list = list->next) {
+ struct connman_storage *storage = list->data;
- g_key_file_set_boolean(keyfile, element->path, "Enabled",
- element->enabled);
+ if (storage->device_save) {
+ if (storage->device_save(device) == 0)
+ return 0;
+ }
+ }
- connman_element_lock(element);
+ return -ENOENT;
+}
- for (list = element->properties; list; list = list->next) {
- struct connman_property *property = list->data;
+int __connman_storage_init_network(struct connman_device *device)
+{
+ GSList *list;
- if (property->flags & CONNMAN_PROPERTY_FLAG_STATIC)
- continue;
+ DBG("device %p", device);
- if (property->flags & CONNMAN_PROPERTY_FLAG_REFERENCE)
- continue;
+ for (list = storage_list; list; list = list->next) {
+ struct connman_storage *storage = list->data;
- if (property->type == DBUS_TYPE_STRING)
- g_key_file_set_string(keyfile, element->path,
- property->name, property->value);
+ if (storage->network_init) {
+ if (storage->network_init(device) == 0)
+ return 0;
+ }
}
- connman_element_unlock(element);
+ return -ENOENT;
}
-int __connman_element_store(struct connman_element *element)
+int __connman_storage_load_network(struct connman_network *network)
{
- GKeyFile *keyfile;
- gchar *pathname, *data = NULL;
- gsize length;
+ GSList *list;
- DBG("element %p name %s", element, element->name);
+ DBG("network %p", network);
- pathname = g_strdup_printf("%s/elements.conf", STORAGEDIR);
- if (pathname == NULL)
- return -ENOMEM;
+ for (list = storage_list; list; list = list->next) {
+ struct connman_storage *storage = list->data;
- keyfile = g_key_file_new();
+ if (storage->network_load) {
+ if (storage->network_load(network) == 0)
+ return 0;
+ }
+ }
+
+ return -ENOENT;
+}
+
+int __connman_storage_save_network(struct connman_network *network)
+{
+ GSList *list;
+
+ DBG("network %p", network);
+
+ for (list = storage_list; list; list = list->next) {
+ struct connman_storage *storage = list->data;
+
+ if (storage->network_save) {
+ if (storage->network_save(network) == 0)
+ return 0;
+ }
+ }
+
+ return -ENOENT;
+}
+
+int __connman_storage_init_service(void)
+{
+ DBG("");
+
+ return -ENOENT;
+}
- if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE)
- goto update;
+int __connman_storage_load_service(struct connman_service *service)
+{
+ GSList *list;
+
+ DBG("service %p", service);
- if (length > 0) {
- if (g_key_file_load_from_data(keyfile, data, length,
- G_KEY_FILE_KEEP_COMMENTS, NULL) == FALSE)
- goto done;
+ for (list = storage_list; list; list = list->next) {
+ struct connman_storage *storage = list->data;
+
+ if (storage->service_load) {
+ if (storage->service_load(service) == 0)
+ return 0;
+ }
}
- g_free(data);
+ return -ENOENT;
+}
-update:
- do_update(keyfile, element);
+int __connman_storage_save_service(struct connman_service *service)
+{
+ GSList *list;
- data = g_key_file_to_data(keyfile, &length, NULL);
+ DBG("service %p", service);
- g_file_set_contents(pathname, data, length, NULL);
+ for (list = storage_list; list; list = list->next) {
+ struct connman_storage *storage = list->data;
-done:
- g_free(data);
+ if (storage->service_save) {
+ if (storage->service_save(service) == 0)
+ return 0;
+ }
+ }
- g_key_file_free(keyfile);
+ return -ENOENT;
+}
- g_free(pathname);
+int __connman_storage_init(void)
+{
+ DBG("");
return 0;
}
+
+void __connman_storage_cleanup(void)
+{
+ DBG("");
+}