summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Wagner <daniel.wagner@bmw-carit.de>2013-06-07 11:41:10 (GMT)
committerPatrik Flykt <patrik.flykt@linux.intel.com>2013-06-10 06:48:22 (GMT)
commit934226962d3caaa538e1424eba9364915bbe7278 (patch)
tree6071f8ac7e5808976dc4e66e23766b16df4b3325
parent2386b677cb7223094b3348d852514df06d39b16b (diff)
downloadconnman-934226962d3caaa538e1424eba9364915bbe7278.zip
connman-934226962d3caaa538e1424eba9364915bbe7278.tar.gz
connman-934226962d3caaa538e1424eba9364915bbe7278.tar.bz2
session: Use service iterator instead of match/creation callbacks
When a new session is created we need to get the initial list of services which match the session AllowedBearers criteria. As soon the session is running add or removed services are tracked via the notifier interface. We concluded that exposing all the services is not really necessary and therefore we are using currently two callbacks to get the initial list. That exposes implementation details from session to service, that is GSequence. We also need to expose the type 'struct service_entry'. Instead doing so we are using an iterator and keep all the implementation details in session.c.
-rw-r--r--src/connman.h15
-rw-r--r--src/service.c25
-rw-r--r--src/session.c24
3 files changed, 28 insertions, 36 deletions
diff --git a/src/connman.h b/src/connman.h
index f4de887..75f136f 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -710,19 +710,12 @@ void __connman_service_counter_unregister(const char *counter);
#include <connman/session.h>
-struct service_entry;
-typedef connman_bool_t (* service_match_cb) (struct connman_session *session,
- struct connman_service *service);
-typedef struct service_entry* (* create_service_entry_cb) (
- struct connman_session *session,
- struct connman_service *service,
+typedef void (* service_iterate_cb) (struct connman_service *service,
const char *name,
- enum connman_service_state state);
+ enum connman_service_state state,
+ void *user_data);
-GSequence *__connman_service_get_list(struct connman_session *session,
- service_match_cb service_match,
- create_service_entry_cb create_service_entry,
- GDestroyNotify destroy_service_entry);
+int __connman_service_iterate_services(service_iterate_cb cb, void *user_data);
void __connman_service_session_inc(struct connman_service *service);
connman_bool_t __connman_service_session_dec(struct connman_service *service);
diff --git a/src/service.c b/src/service.c
index 5649788..df5a10d 100644
--- a/src/service.c
+++ b/src/service.c
@@ -2125,38 +2125,21 @@ void __connman_service_counter_unregister(const char *counter)
counter_list = g_slist_remove(counter_list, counter);
}
-GSequence *__connman_service_get_list(struct connman_session *session,
- service_match_cb service_match,
- create_service_entry_cb create_service_entry,
- GDestroyNotify destroy_service_entry)
+int __connman_service_iterate_services(service_iterate_cb cb, void *user_data)
{
- GSequence *list;
GSequenceIter *iter;
- struct connman_service *service;
- struct service_entry *entry;
-
- list = g_sequence_new(destroy_service_entry);
- if (list == NULL)
- return NULL;
iter = g_sequence_get_begin_iter(service_list);
while (g_sequence_iter_is_end(iter) == FALSE) {
- service = g_sequence_get(iter);
-
- if (service_match(session, service) == TRUE) {
- entry = create_service_entry(session, service,
- service->name, service->state);
- if (entry == NULL)
- return list;
+ struct connman_service *service = g_sequence_get(iter);
- g_sequence_append(list, entry);
- }
+ cb(service, service->name, service->state, user_data);
iter = g_sequence_iter_next(iter);
}
- return list;
+ return 0;
}
void __connman_service_session_inc(struct connman_service *service)
diff --git a/src/session.c b/src/session.c
index bdb22d0..98b22db 100644
--- a/src/session.c
+++ b/src/session.c
@@ -1245,6 +1245,24 @@ static struct service_entry *create_service_entry(struct connman_session * sessi
return entry;
}
+static void iterate_service_cb(struct connman_service *service,
+ const char *name,
+ enum connman_service_state state,
+ void *user_data)
+{
+ struct connman_session *session = user_data;
+ struct service_entry *entry;
+
+ if (service_match(session, service) == FALSE)
+ return;
+
+ entry = create_service_entry(session, service, name, state);
+ if (entry == NULL)
+ return;
+
+ g_sequence_append(session->service_list, entry);
+}
+
static void destroy_service_entry(gpointer data)
{
struct service_entry *entry = data;
@@ -1270,10 +1288,8 @@ static void populate_service_list(struct connman_session *session)
session->service_hash =
g_hash_table_new_full(g_direct_hash, g_direct_equal,
NULL, NULL);
- session->service_list = __connman_service_get_list(session,
- service_match,
- create_service_entry,
- destroy_service_entry);
+ session->service_list = g_sequence_new(destroy_service_entry);
+ __connman_service_iterate_services(iterate_service_cb, session);
g_sequence_sort(session->service_list, sort_services, session);