Link providers with services
authorSamuel Ortiz <sameo@linux.intel.com>
Fri, 30 Jul 2010 14:08:44 +0000 (16:08 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Mon, 2 Aug 2010 17:16:11 +0000 (19:16 +0200)
With each provider we now have a VPN type service.

src/connman.h
src/provider.c
src/service.c

index d0b1d2d..1a913a1 100644 (file)
@@ -425,6 +425,19 @@ connman_bool_t __connman_tethering_get_status(void);
 int __connman_tethering_set_status(connman_bool_t status);
 void __connman_tethering_update_interface(const char *interface);
 
+#include <connman/provider.h>
+
+void __connman_provider_list(DBusMessageIter *iter, void *user_data);
+int __connman_provider_create_and_connect(DBusMessage *msg);
+const char * __connman_provider_get_ident(struct connman_provider *provider);
+int __connman_provider_indicate_state(struct connman_provider *provider,
+                                    enum connman_provider_state state);
+int __connman_provider_indicate_error(struct connman_provider *provider,
+                                    enum connman_provider_error error);
+int __connman_provider_remove(const char *path);
+void __connman_provider_cleanup(void);
+int __connman_provider_init(void);
+
 #include <connman/service.h>
 
 int __connman_service_init(void);
@@ -438,6 +451,7 @@ void __connman_service_put(struct connman_service *service);
 
 struct connman_service *__connman_service_lookup_from_network(struct connman_network *network);
 struct connman_service *__connman_service_create_from_network(struct connman_network *network);
+struct connman_service *__connman_service_create_from_provider(struct connman_provider *provider);
 void __connman_service_update_from_network(struct connman_network *network);
 void __connman_service_remove_from_network(struct connman_network *network);
 
@@ -513,18 +527,6 @@ struct connman_location *__connman_service_get_location(struct connman_service *
 int __connman_location_detect(struct connman_service *service);
 int __connman_location_finish(struct connman_service *service);
 
-#include <connman/provider.h>
-
-void __connman_provider_list(DBusMessageIter *iter, void *user_data);
-int __connman_provider_create_and_connect(DBusMessage *msg);
-int __connman_provider_indicate_state(struct connman_provider *provider,
-                                    enum connman_provider_state state);
-int __connman_provider_indicate_error(struct connman_provider *provider,
-                                    enum connman_provider_error error);
-int __connman_provider_remove(const char *path);
-void __connman_provider_cleanup(void);
-int __connman_provider_init(void);
-
 #include <connman/notifier.h>
 
 int __connman_technology_init(void);
index 81c7b4d..66fb628 100644 (file)
@@ -37,6 +37,7 @@ static GSList *driver_list = NULL;
 
 struct connman_provider {
        struct connman_element element;
+       struct connman_service *vpn_service;
        char *identifier;
        char *path;
        enum connman_provider_state state;
@@ -140,6 +141,8 @@ static void connman_provider_setup_vpn_ipv4(struct connman_provider *provider,
 
 struct connman_provider *connman_provider_ref(struct connman_provider *provider)
 {
+       DBG("provider %p", provider);
+
        if (connman_element_ref(&provider->element) == NULL)
                return NULL;
 
@@ -148,6 +151,8 @@ struct connman_provider *connman_provider_ref(struct connman_provider *provider)
 
 void connman_provider_unref(struct connman_provider *provider)
 {
+       DBG("provider %p", provider);
+
        connman_element_unref(&provider->element);
 }
 
@@ -241,6 +246,9 @@ static int connman_provider_disconnect(struct connman_provider *provider)
 
        __connman_provider_indicate_state(provider,
                                        CONNMAN_PROVIDER_STATE_DISCONNECT);
+
+       __connman_service_indicate_state(provider->vpn_service,
+                                       CONNMAN_SERVICE_STATE_DISCONNECT);
        if (err < 0) {
                if (err != -EINPROGRESS)
                        return err;
@@ -512,11 +520,15 @@ int connman_provider_set_connected(struct connman_provider *provider,
                }
                __connman_provider_indicate_state(provider,
                                                  CONNMAN_PROVIDER_STATE_READY);
+               __connman_service_indicate_state(provider->vpn_service,
+                                               CONNMAN_SERVICE_STATE_READY);
        } else {
                reply_pending(provider, ECONNABORTED);
                connman_element_unregister_children(&provider->element);
                __connman_provider_indicate_state(provider,
                                        CONNMAN_PROVIDER_STATE_DISCONNECT);
+               __connman_service_indicate_state(provider->vpn_service,
+                                       CONNMAN_SERVICE_STATE_DISCONNECT);
        }
 
        return 0;
@@ -543,6 +555,7 @@ static void provider_free(gpointer user_data)
        g_free(provider->domain);
        g_free(provider->identifier);
        g_free(provider->dns);
+       __connman_service_put(provider->vpn_service);
 }
 
 static void unregister_provider(gpointer data)
@@ -561,6 +574,8 @@ static void provider_destruct(struct connman_element *element)
 {
        struct connman_provider *provider = element->private;
 
+       DBG("provider %p", provider);
+
        provider_free(provider);
 }
 
@@ -768,6 +783,10 @@ int __connman_provider_create_and_connect(DBusMessage *msg)
        g_dbus_send_reply(connection, msg,
                                DBUS_TYPE_OBJECT_PATH, &provider->path,
                                                        DBUS_TYPE_INVALID);
+
+       provider->vpn_service =
+                       __connman_service_create_from_provider(provider);
+
        return 0;
 
 failed:
@@ -779,6 +798,14 @@ failed:
        return err;
 }
 
+const char * __connman_provider_get_ident(struct connman_provider *provider)
+{
+       if (provider == NULL)
+               return NULL;
+
+       return provider->identifier;
+}
+
 int connman_provider_set_string(struct connman_provider *provider,
                                        const char *key, const char *value)
 {
index 2ddda9f..4ad1432 100644 (file)
@@ -90,6 +90,7 @@ struct connman_service {
        connman_bool_t login_required;
        struct connman_ipconfig *ipconfig;
        struct connman_network *network;
+       struct connman_provider *provider;
        char **nameservers;
        char *nameserver;
        char **domains;
@@ -3275,7 +3276,7 @@ static void update_from_network(struct connman_service *service,
  *
  * Look up service by network and if not found, create one
  */
-struct connman_service *__connman_service_create_from_network(struct connman_network *network)
+struct connman_service * __connman_service_create_from_network(struct connman_network *network)
 {
        struct connman_service *service;
        const char *ident, *group;
@@ -3416,6 +3417,68 @@ void __connman_service_remove_from_network(struct connman_network *network)
        __connman_service_put(service);
 }
 
+/**
+ * __connman_service_create_from_provider:
+ * @provider: provider structure
+ *
+ * Look up service by provider and if not found, create one
+ */
+struct connman_service *
+__connman_service_create_from_provider(struct connman_provider *provider)
+{
+       struct connman_service *service;
+       const char *ident, *str;
+       char *name;
+       int index = connman_provider_get_index(provider);
+
+       DBG("provider %p", provider);
+
+       ident = __connman_provider_get_ident(provider);
+       if (ident == NULL)
+               return NULL;
+
+       name = g_strdup_printf("vpn_%s", ident);
+       service = __connman_service_get(name);
+       g_free(name);
+
+       if (service == NULL)
+               return NULL;
+
+       service->type = CONNMAN_SERVICE_TYPE_VPN;
+       service->provider = provider;
+       service->autoconnect = FALSE;
+
+       service->state = CONNMAN_SERVICE_STATE_IDLE;
+
+       str = connman_provider_get_string(provider, "Name");
+       if (str != NULL) {
+               g_free(service->name);
+               service->name = g_strdup(str);
+               service->hidden = FALSE;
+       } else {
+               g_free(service->name);
+               service->name = NULL;
+               service->hidden = TRUE;
+       }
+
+       service->strength = 0;
+
+       service->ipconfig = connman_ipconfig_create(index);
+       if (service->ipconfig == NULL)
+               return service;
+
+       connman_ipconfig_set_method(service->ipconfig,
+                                       CONNMAN_IPCONFIG_METHOD_MANUAL);
+
+       connman_ipconfig_set_data(service->ipconfig, service);
+
+       connman_ipconfig_set_ops(service->ipconfig, &service_ops);
+
+       service_register(service);
+
+       return service;
+}
+
 void __connman_service_stats_update(struct connman_service *service,
                                unsigned int rx_packets, unsigned int tx_packets,
                                unsigned int rx_bytes, unsigned int tx_bytes,