X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fstorage.c;h=08b7249cedb9f5a7beda41d032ae3cd0954f5d92;hb=b5ecc8c4f4cf4a299af6a4408d2ee3f5924ed2b8;hp=d67d0d2c17d8abe3bc9ff6fe25ab671321f5b0c5;hpb=80de79e829a572a49fabffc08988b835840b4cc6;p=connman diff --git a/src/storage.c b/src/storage.c index d67d0d2..08b7249 100644 --- a/src/storage.c +++ b/src/storage.c @@ -2,7 +2,7 @@ * * 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 @@ -23,99 +23,208 @@ #include #endif -#if 0 -#include -#endif - #include "connman.h" -#if 0 -static sqlite3 *db = NULL; +static GSList *storage_list = NULL; -static int create_tables(void) +static gint compare_priority(gconstpointer a, gconstpointer b) { - char *msg; - int err; + const struct connman_storage *storage1 = a; + const struct connman_storage *storage2 = b; - DBG(""); + return storage2->priority - storage1->priority; +} - err = sqlite3_exec(db, "CREATE TABLE properties (" - "element TEXT NOT NULL," - "name TEXT NOT NULL," - "value TEXT NOT NULL," - "PRIMARY KEY(element, name))", - NULL, NULL, &msg); - - if (err != SQLITE_OK) { - connman_error("SQL error: %s", msg); - sqlite3_free(msg); - return -1; - } +/** + * 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; } -#endif -int __connman_storage_init(void) +/** + * connman_storage_unregister: + * @storage: storage module + * + * Remove a previously registered storage module + */ +void connman_storage_unregister(struct connman_storage *storage) { -#if 0 - int err; + 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(""); -#if 0 - if (!sqlite3_threadsafe()) { - connman_error("SQLite is missing thread support"); - return -1; + 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; + } } -#endif - err = sqlite3_open(STORAGEDIR "/config.db", &db); - if (err != SQLITE_OK) { - connman_error("Can't open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); - return -1; + return -ENOENT; +} + +int __connman_storage_load_device(struct connman_device *device) +{ + GSList *list; + + 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; + } } - create_tables(); -#endif + return -ENOENT; +} - return 0; +int __connman_storage_save_device(struct connman_device *device) +{ + GSList *list; + + DBG("device %p", device); + + for (list = storage_list; list; list = list->next) { + struct connman_storage *storage = list->data; + + if (storage->device_save) { + if (storage->device_save(device) == 0) + return 0; + } + } + + return -ENOENT; } -void __connman_storage_cleanup(void) +int __connman_storage_init_network(struct connman_device *device) { -#if 0 - DBG(""); + GSList *list; - sqlite3_close(db); -#endif + DBG("device %p", device); + + for (list = storage_list; list; list = list->next) { + struct connman_storage *storage = list->data; + + if (storage->network_init) { + if (storage->network_init(device) == 0) + return 0; + } + } + + return -ENOENT; } -int __connman_element_load(struct connman_element *element) +int __connman_storage_load_network(struct connman_network *network) { - return 0; + GSList *list; + + DBG("network %p", network); + + for (list = storage_list; list; list = list->next) { + struct connman_storage *storage = list->data; + + if (storage->network_load) { + if (storage->network_load(network) == 0) + return 0; + } + } + + return -ENOENT; } -int __connman_element_store(struct connman_element *element) +int __connman_storage_save_network(struct connman_network *network) { -#if 0 - char *sql, *msg; + 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(""); - if (element->priority > 0) { - sql = g_strdup_printf("INSERT INTO properties " - "VALUES ('%s','%s','%d')", - element->path, "Priority", - element->priority); + return -ENOENT; +} + +int __connman_storage_load_service(struct connman_service *service) +{ + GSList *list; + + DBG("service %p", service); + + for (list = storage_list; list; list = list->next) { + struct connman_storage *storage = list->data; - if (sqlite3_exec(db, sql, NULL, NULL, &msg) != SQLITE_OK) { - connman_error("SQL error: %s", msg); - sqlite3_free(msg); + if (storage->service_load) { + if (storage->service_load(service) == 0) + return 0; } } -#endif + + return -ENOENT; +} + +int __connman_storage_save_service(struct connman_service *service) +{ + GSList *list; + + DBG("service %p", service); + + for (list = storage_list; list; list = list->next) { + struct connman_storage *storage = list->data; + + if (storage->service_save) { + if (storage->service_save(service) == 0) + return 0; + } + } + + return -ENOENT; +} + +int __connman_storage_init(void) +{ + DBG(""); return 0; } + +void __connman_storage_cleanup(void) +{ + DBG(""); +}