Add infrastructure for built-in plugins
[connman] / src / service.c
index 57337bb..ec09cc1 100644 (file)
@@ -274,6 +274,8 @@ static DBusMessage *set_property(DBusConnection *conn,
                if (service->network != NULL)
                        connman_network_set_string(service->network,
                                "WiFi.Passphrase", service->passphrase);
+
+               __connman_storage_save_service(service);
        }
 
        return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
@@ -373,6 +375,8 @@ static DBusMessage *remove_service(DBusConnection *conn,
 
        connman_service_set_favorite(service, FALSE);
 
+       __connman_storage_save_service(service);
+
        return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 }
 
@@ -689,6 +693,8 @@ struct connman_service *connman_service_get(const char *identifier)
 
        service->identifier = g_strdup(identifier);
 
+       __connman_storage_load_service(service);
+
        iter = g_sequence_insert_sorted(service_list, service,
                                                service_compare, NULL);
 
@@ -699,7 +705,7 @@ struct connman_service *connman_service_get(const char *identifier)
 
 static int service_register(struct connman_service *service)
 {
-       const char *path = __connman_profile_active();
+       const char *path = __connman_profile_active_path();
 
        DBG("service %p", service);
 
@@ -729,10 +735,15 @@ static int service_register(struct connman_service *service)
 struct connman_service *__connman_service_lookup_from_device(struct connman_device *device)
 {
        struct connman_service *service;
+       const char *ident;
        char *name;
 
-       name = g_strdup_printf("%s_%d", __connman_device_get_type(device),
-                                       connman_device_get_index(device));
+       ident = __connman_device_get_ident(device);
+       if (ident == NULL)
+               return NULL;
+
+       name = g_strdup_printf("%s_%s",
+                               __connman_device_get_type(device), ident);
 
        service = connman_service_lookup(name);
 
@@ -773,10 +784,15 @@ static enum connman_service_type convert_device_type(struct connman_device *devi
 struct connman_service *__connman_service_create_from_device(struct connman_device *device)
 {
        struct connman_service *service;
+       const char *ident;
        char *name;
 
-       name = g_strdup_printf("%s_%d", __connman_device_get_type(device),
-                                       connman_device_get_index(device));
+       ident = __connman_device_get_ident(device);
+       if (ident == NULL)
+               return NULL;
+
+       name = g_strdup_printf("%s_%s",
+                               __connman_device_get_type(device), ident);
 
        service = connman_service_get(name);
        if (service == NULL)
@@ -809,15 +825,19 @@ done:
 struct connman_service *__connman_service_lookup_from_network(struct connman_network *network)
 {
        struct connman_service *service;
-       const char *group;
+       const char *ident, *group;
        char *name;
 
+       ident = __connman_network_get_ident(network);
+       if (ident == NULL)
+               return NULL;
+
        group = __connman_network_get_group(network);
        if (group == NULL)
                return NULL;
 
-       name = g_strdup_printf("%s_%s",
-                               __connman_network_get_type(network), group);
+       name = g_strdup_printf("%s_%s_%s",
+                       __connman_network_get_type(network), ident, group);
 
        service = connman_service_lookup(name);
 
@@ -924,15 +944,19 @@ static void update_from_network(struct connman_service *service,
 struct connman_service *__connman_service_create_from_network(struct connman_network *network)
 {
        struct connman_service *service;
-       const char *group;
+       const char *ident, *group;
        char *name;
 
+       ident = __connman_network_get_ident(network);
+       if (ident == NULL)
+               return NULL;
+
        group = __connman_network_get_group(network);
        if (group == NULL)
                return NULL;
 
-       name = g_strdup_printf("%s_%s",
-                               __connman_network_get_type(network), group);
+       name = g_strdup_printf("%s_%s_%s",
+                       __connman_network_get_type(network), ident, group);
 
        service = connman_service_get(name);
        if (service == NULL)
@@ -960,12 +984,36 @@ done:
        return service;
 }
 
+static int service_load(struct connman_service *service)
+{
+       DBG("service %p", service);
+
+       return 0;
+}
+
+static int service_save(struct connman_service *service)
+{
+       DBG("service %p", service);
+
+       return 0;
+}
+
+static struct connman_storage service_storage = {
+       .name           = "service",
+       .priority       = CONNMAN_STORAGE_PRIORITY_LOW,
+       .service_load   = service_load,
+       .service_save   = service_save,
+};
+
 int __connman_service_init(void)
 {
        DBG("");
 
        connection = connman_dbus_get_connection();
 
+       if (connman_storage_register(&service_storage) < 0)
+               connman_error("Failed to register service storage");
+
        service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
                                                                NULL, NULL);
 
@@ -984,5 +1032,7 @@ void __connman_service_cleanup(void)
        g_hash_table_destroy(service_hash);
        service_hash = NULL;
 
+       connman_storage_unregister(&service_storage);
+
        dbus_connection_unref(connection);
 }