From b1d822465166dba78f8ad54837f106c3ec513631 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 7 Jan 2009 20:24:16 +0100 Subject: [PATCH] Add support for storage setup callbacks --- include/storage.h | 2 ++ src/connman.h | 2 ++ src/device.c | 10 ++++++++++ src/element.c | 2 ++ src/network.c | 8 ++++++++ src/storage.c | 36 ++++++++++++++++++++++++++++++++++++ 6 files changed, 60 insertions(+) diff --git a/include/storage.h b/include/storage.h index 9182675..cd31b69 100644 --- a/include/storage.h +++ b/include/storage.h @@ -43,9 +43,11 @@ struct connman_storage { const char *name; int priority; enum connman_device_type device_type; + int (*device_init) (void); int (*device_load) (struct connman_device *device); int (*device_save) (struct connman_device *device); enum connman_network_type network_type; + int (*network_init) (struct connman_device *device); int (*network_load) (struct connman_network *network); int (*network_save) (struct connman_network *network); }; diff --git a/src/connman.h b/src/connman.h index f98fc79..cca7ea8 100644 --- a/src/connman.h +++ b/src/connman.h @@ -87,8 +87,10 @@ int __connman_resolver_selftest(void); int __connman_storage_init(void); void __connman_storage_cleanup(void); +int __connman_storage_init_device(); int __connman_storage_load_device(struct connman_device *device); int __connman_storage_save_device(struct connman_device *device); +int __connman_storage_init_network(); int __connman_storage_load_network(struct connman_network *network); int __connman_storage_save_network(struct connman_network *network); diff --git a/src/device.c b/src/device.c index 4575dd2..2a65e69 100644 --- a/src/device.c +++ b/src/device.c @@ -1250,6 +1250,16 @@ int connman_device_register(struct connman_device *device) { __connman_storage_load_device(device); + switch (device->mode) { + case CONNMAN_DEVICE_MODE_UNKNOWN: + case CONNMAN_DEVICE_MODE_TRANSPORT_IP: + break; + case CONNMAN_DEVICE_MODE_NETWORK_SINGLE: + case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE: + __connman_storage_init_network(device); + break; + } + return connman_element_register(&device->element, NULL); } diff --git a/src/element.c b/src/element.c index 57c2566..fb11f79 100644 --- a/src/element.c +++ b/src/element.c @@ -1455,6 +1455,8 @@ void __connman_element_start(void) started = TRUE; + __connman_storage_init_device(); + __connman_connection_init(); __connman_ipv4_init(); __connman_detect_init(); diff --git a/src/network.c b/src/network.c index 2c6d6b8..7b3d49b 100644 --- a/src/network.c +++ b/src/network.c @@ -1008,6 +1008,13 @@ static struct connman_driver network_driver = { .remove = network_remove, }; +static int network_init(struct connman_device *device) +{ + DBG("device %p", device); + + return 0; +} + static int network_load(struct connman_network *network) { GKeyFile *keyfile; @@ -1131,6 +1138,7 @@ done: static struct connman_storage network_storage = { .name = "network", .priority = CONNMAN_STORAGE_PRIORITY_LOW, + .network_init = network_init, .network_load = network_load, .network_save = network_save, }; diff --git a/src/storage.c b/src/storage.c index d881a5c..b63c43b 100644 --- a/src/storage.c +++ b/src/storage.c @@ -66,6 +66,24 @@ void connman_storage_unregister(struct connman_storage *storage) 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_storage_load_device(struct connman_device *device) { GSList *list; @@ -102,6 +120,24 @@ int __connman_storage_save_device(struct connman_device *device) return -ENOENT; } +int __connman_storage_init_network(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->network_init) { + if (storage->network_init(device) == 0) + return 0; + } + } + + return -ENOENT; +} + int __connman_storage_load_network(struct connman_network *network) { GSList *list; -- 2.7.4