[PATCH v3 11/42] provider: Support functions added

Jukka Rissanen jukka.rissanen at linux.intel.com
Wed Nov 7 03:48:37 PST 2012


---
 include/provider.h |  2 ++
 src/provider.c     | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)

diff --git a/include/provider.h b/include/provider.h
index 67df67a..b663f37 100644
--- a/include/provider.h
+++ b/include/provider.h
@@ -94,6 +94,8 @@ int connman_provider_set_ipaddress(struct connman_provider *provider,
 int connman_provider_set_pac(struct connman_provider *provider,
 				const char *pac);
 int connman_provider_create_service(struct connman_provider *provider);
+struct connman_provider *connman_provider_get(const char *identifier);
+void connman_provider_put(struct connman_provider *provider);
 int connman_provider_set_domain(struct connman_provider *provider,
 				const char *domain);
 int connman_provider_set_nameservers(struct connman_provider *provider,
diff --git a/src/provider.c b/src/provider.c
index 977f1f1..696ed87 100644
--- a/src/provider.c
+++ b/src/provider.c
@@ -600,6 +600,71 @@ static void provider_offline_mode(connman_bool_t enabled)
 
 }
 
+static void destroy_route(gpointer user_data)
+{
+	struct connman_route *route = user_data;
+
+	g_free(route->host);
+	g_free(route->netmask);
+	g_free(route->gateway);
+	g_free(route);
+}
+
+static void provider_initialize(struct connman_provider *provider)
+{
+	DBG("provider %p", provider);
+
+	provider->index = 0;
+	provider->identifier = NULL;
+	provider->user_networks = NULL;
+	provider->routes = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+					NULL, destroy_route);
+	provider->user_routes = g_hash_table_new_full(g_str_hash, g_str_equal,
+					g_free, destroy_route);
+}
+
+static struct connman_provider *provider_new(void)
+{
+	struct connman_provider *provider;
+
+	provider = g_try_new0(struct connman_provider, 1);
+	if (provider == NULL)
+		return NULL;
+
+	provider->refcount = 1;
+
+	DBG("provider %p", provider);
+	provider_initialize(provider);
+
+	return provider;
+}
+
+struct connman_provider *connman_provider_get(const char *identifier)
+{
+	struct connman_provider *provider;
+
+	provider = g_hash_table_lookup(provider_hash, identifier);
+	if (provider != NULL)
+		return provider;
+
+	provider = provider_new();
+	if (provider == NULL)
+		return NULL;
+
+	DBG("provider %p", provider);
+
+	provider->identifier = g_strdup(identifier);
+
+	g_hash_table_insert(provider_hash, provider->identifier, provider);
+
+	return provider;
+}
+
+void connman_provider_put(struct connman_provider *provider)
+{
+	g_hash_table_remove(provider_hash, provider->identifier);
+}
+
 static struct connman_provider *provider_get(int index)
 {
 	GHashTableIter iter;
-- 
1.7.11.4




More information about the connman mailing list