summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Wagner <daniel.wagner@bmw-carit.de>2012-10-31 10:33:31 +0100
committerPatrik Flykt <patrik.flykt@linux.intel.com>2012-11-05 14:43:33 +0200
commit571da6449e813c3cf1a3f9515818d69bbc2e264d (patch)
treedfdbeece268dd464411fa722ca41a4f3aef3f58b
parenta475f99d89f5f9615c31400f4a7126be871c3152 (diff)
downloadconnman-571da6449e813c3cf1a3f9515818d69bbc2e264d.tar.gz
connman-571da6449e813c3cf1a3f9515818d69bbc2e264d.tar.bz2
connman-571da6449e813c3cf1a3f9515818d69bbc2e264d.zip
session: Add callback to policy create()
Instead returning directly a config when create() is called in policy plugin, use a callback function for handing over a valid configuration from the plugin to the session core. This prepares support for asynchronous create call.
-rw-r--r--include/session.h9
-rw-r--r--plugins/session_policy.c14
-rw-r--r--src/session.c32
3 files changed, 40 insertions, 15 deletions
diff --git a/include/session.h b/include/session.h
index 63e077be..f006e009 100644
--- a/include/session.h
+++ b/include/session.h
@@ -65,11 +65,16 @@ struct connman_session_config {
GSList *allowed_bearers;
};
+typedef void (* connman_session_config_cb) (struct connman_session *session,
+ struct connman_session_config *config,
+ void *user_data, int err);
+
struct connman_session_policy {
const char *name;
int priority;
- struct connman_session_config *(*create)(
- struct connman_session *session);
+ int (*create)(struct connman_session *session,
+ connman_session_config_cb callback,
+ void *user_data);
void (*destroy)(struct connman_session *session);
};
diff --git a/plugins/session_policy.c b/plugins/session_policy.c
index 98d984ac..85929f96 100644
--- a/plugins/session_policy.c
+++ b/plugins/session_policy.c
@@ -35,20 +35,26 @@
static GHashTable *config_hash;
-static struct connman_session_config *policy_create(
- struct connman_session *session)
+static int policy_create(struct connman_session *session,
+ connman_session_config_cb callback,
+ void *user_data)
{
struct connman_session_config *config;
DBG("session %p", session);
+ if (callback == NULL)
+ return -EINVAL;
+
config = connman_session_create_default_config();
if (config == NULL)
- return NULL;
+ return -ENOMEM;
g_hash_table_replace(config_hash, session, config);
- return config;
+ (*callback)(session, config, user_data, 0);
+
+ return 0;
}
static void policy_destroy(struct connman_session *session)
diff --git a/src/session.c b/src/session.c
index 2b06e3f3..247ff066 100644
--- a/src/session.c
+++ b/src/session.c
@@ -231,21 +231,23 @@ static int assign_policy_plugin(struct connman_session *session)
return 0;
}
-static int create_policy_config(struct connman_session *session)
+static int create_policy_config(struct connman_session *session,
+ connman_session_config_cb callback,
+ void *user_data)
{
struct connman_session_config *config;
- if (session->policy == NULL)
+ if (session->policy == NULL) {
config = connman_session_create_default_config();
- else
- config = (*session->policy->create)(session);
+ if (config == NULL)
+ return -ENOMEM;
- if (config == NULL)
- return -ENOMEM;
+ session->policy_config = config;
- session->policy_config = config;
+ return 0;
+ }
- return 0;
+ return (*session->policy->create)(session, callback, user_data);
}
static void destroy_policy_config(struct connman_session *session)
@@ -1580,6 +1582,18 @@ static const GDBusMethodTable session_methods[] = {
{ },
};
+static void session_create_cb(struct connman_session *session,
+ struct connman_session_config *config,
+ void *user_data, int err)
+{
+ DBG("session %p config %p", session, config);
+
+ if (err != 0)
+ return;
+
+ session->policy_config = config;
+}
+
int __connman_session_create(DBusMessage *msg)
{
const char *owner, *notify_path;
@@ -1696,7 +1710,7 @@ int __connman_session_create(DBusMessage *msg)
err = assign_policy_plugin(session);
if (err < 0)
goto err;
- err = create_policy_config(session);
+ err = create_policy_config(session, session_create_cb, NULL);
if (err < 0)
goto err;