On 19.10.2012 12:11, Patrik Flykt wrote:
Hi again,
On Wed, 2012-10-17 at 14:42 +0200, Daniel Wagner wrote:
From: Daniel Wagner <daniel.wag...@bmw-carit.de>
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 prepars
support for asynchronize create call.
---
include/session.h | 9 +++++++--
plugins/session_policy.c | 11 +++++++----
src/session.c | 29 ++++++++++++++++++++---------
3 files changed, 34 insertions(+), 15 deletions(-)
diff --git a/include/session.h b/include/session.h
index 63e077b..9b6428f 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);
+
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 98d984a..d35d850 100644
--- a/plugins/session_policy.c
+++ b/plugins/session_policy.c
@@ -35,8 +35,9 @@
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;
@@ -44,11 +45,13 @@ static struct connman_session_config *policy_create(
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);
+
+ return 0;
}
static void policy_destroy(struct connman_session *session)
diff --git a/src/session.c b/src/session.c
index e489742..ddc5252 100644
--- a/src/session.c
+++ b/src/session.c
@@ -236,21 +236,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);
Here also a check for the create function is needed before calling it.
Good catch. Will fix it (also the other places)
cheers,
daniel
_______________________________________________
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman