[PATCH v5 25/42] provider: Removed the connect part from the create() function

Jukka Rissanen jukka.rissanen at linux.intel.com
Mon Nov 12 04:07:41 PST 2012


The connect operation is done separately from create operation
in connman-vpnd so change the function to reflect that.
---
 vpn/vpn-manager.c  |  2 +-
 vpn/vpn-provider.c | 45 ++++++++++++---------------------------------
 vpn/vpn.h          |  2 +-
 3 files changed, 14 insertions(+), 35 deletions(-)

diff --git a/vpn/vpn-manager.c b/vpn/vpn-manager.c
index cd85165..1ba745b 100644
--- a/vpn/vpn-manager.c
+++ b/vpn/vpn-manager.c
@@ -43,7 +43,7 @@ static DBusMessage *create(DBusConnection *conn, DBusMessage *msg, void *data)
 
 	DBG("conn %p", conn);
 
-	err = __vpn_provider_create_and_connect(msg);
+	err = __vpn_provider_create(msg);
 	if (err < 0) {
 		if (err == -EINPROGRESS) {
 			connman_error("Invalid return code (%d) "
diff --git a/vpn/vpn-provider.c b/vpn/vpn-provider.c
index 72bf686..300ce85 100644
--- a/vpn/vpn-provider.c
+++ b/vpn/vpn-provider.c
@@ -75,7 +75,6 @@ struct vpn_provider {
 	GSList *user_networks;
 	GResolv *resolv;
 	char **host_ip;
-	DBusMessage *pending_msg;
 	struct vpn_ipconfig *ipconfig_ipv4;
 	struct vpn_ipconfig *ipconfig_ipv6;
 	char **nameservers;
@@ -1543,7 +1542,7 @@ static void provider_create_all_from_type(const char *provider_type)
 	g_strfreev(providers);
 }
 
-int __vpn_provider_create_and_connect(DBusMessage *msg)
+int __vpn_provider_create(DBusMessage *msg)
 {
 	struct vpn_provider *provider;
 	DBusMessageIter iter, array;
@@ -1650,32 +1649,22 @@ int __vpn_provider_create_and_connect(DBusMessage *msg)
 
 	g_free(ident);
 
-	provider->pending_msg = dbus_message_ref(msg);
-
-	DBG("provider %p pending %p", provider, provider->pending_msg);
-
-	if (provider->index > 0) {
-		DBG("provider already connected");
-	} else {
-		err = __vpn_provider_connect(provider);
-		if (err < 0 && err != -EINPROGRESS)
-			goto failed;
-	}
-
 	vpn_provider_save(provider);
 
-	return 0;
+	err = provider_register(provider);
+	if (err != 0 && err != -EALREADY)
+		return err;
 
-failed:
-	DBG("Can not connect (%d), deleting provider %p %s", err, provider,
-		provider->identifier);
+	connection_register(provider);
 
-	vpn_provider_indicate_error(provider,
-				VPN_PROVIDER_ERROR_CONNECT_FAILED);
+	DBG("provider %p index %d path %s", provider, provider->index,
+							provider->path);
 
-	g_hash_table_remove(provider_hash, provider->identifier);
+	g_dbus_send_reply(connection, msg,
+				DBUS_TYPE_OBJECT_PATH, &provider->path,
+				DBUS_TYPE_INVALID);
 
-	return err;
+	return 0;
 }
 
 static void append_connection_structs(DBusMessageIter *iter, void *user_data)
@@ -1801,17 +1790,7 @@ void vpn_provider_set_data(struct vpn_provider *provider, void *data)
 
 void vpn_provider_set_index(struct vpn_provider *provider, int index)
 {
-	DBG("index %d provider %p pending %p", index, provider,
-		provider->pending_msg);
-
-	if (provider->pending_msg != NULL) {
-		g_dbus_send_reply(connection, provider->pending_msg,
-				DBUS_TYPE_STRING, &provider->identifier,
-				DBUS_TYPE_INT32, &index,
-				DBUS_TYPE_INVALID);
-		dbus_message_unref(provider->pending_msg);
-		provider->pending_msg = NULL;
-	}
+	DBG("index %d provider %p", index, provider);
 
 	if (provider->ipconfig_ipv4 == NULL) {
 		provider->ipconfig_ipv4 = __vpn_ipconfig_create(index,
diff --git a/vpn/vpn.h b/vpn/vpn.h
index 96f4e87..598c86d 100644
--- a/vpn/vpn.h
+++ b/vpn/vpn.h
@@ -76,7 +76,7 @@ int __vpn_provider_append_user_route(struct vpn_provider *provider,
 			int family, const char *network, const char *netmask);
 void __vpn_provider_append_properties(struct vpn_provider *provider, DBusMessageIter *iter);
 void __vpn_provider_list(DBusMessageIter *iter, void *user_data);
-int __vpn_provider_create_and_connect(DBusMessage *msg);
+int __vpn_provider_create(DBusMessage *msg);
 DBusMessage *__vpn_provider_get_connections(DBusMessage *msg);
 const char * __vpn_provider_get_ident(struct vpn_provider *provider);
 int __vpn_provider_indicate_state(struct vpn_provider *provider,
-- 
1.7.11.4




More information about the connman mailing list