From: Patrik Flykt <patrik.fl...@linux.intel.com> Add function for counting the number of sessions using a certain service type. Add a type specific boolean to know if the session type is used and a general one to know if there exists any technology types requested by sessions.
Also keep track of the technology powered state in order to compute the technology type and general booleans. --- src/connman.h | 1 + src/service.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/src/connman.h b/src/connman.h index 764422c..efff509 100644 --- a/src/connman.h +++ b/src/connman.h @@ -625,6 +625,7 @@ int __connman_service_indicate_default(struct connman_service *service); int __connman_service_connect(struct connman_service *service); int __connman_service_disconnect(struct connman_service *service); int __connman_service_disconnect_all(void); +void __connman_service_filter_types(connman_bool_t select, GSList *list); void __connman_service_auto_connect(void); gboolean __connman_service_remove(struct connman_service *service); connman_bool_t __connman_service_is_provider_pending(struct connman_service *service); diff --git a/src/service.c b/src/service.c index 7381af3..b36c083 100644 --- a/src/service.c +++ b/src/service.c @@ -3349,6 +3349,76 @@ static connman_bool_t is_ignore(struct connman_service *service) return FALSE; } +#define MAX_SERVICE 10 +static struct { + int users; + connman_bool_t in_use; + connman_bool_t powered; +} session_users[MAX_SERVICE]; +static connman_bool_t sessions_active; + +static void update_session_filter(void) +{ + int i; + + sessions_active = FALSE; + for (i = 0; i < MAX_SERVICE; i++) { + __sync_synchronize(); + if (session_users[i].users > 0 && + session_users[i].powered == TRUE) { + session_users[i].in_use = TRUE; + sessions_active = TRUE; + } else + session_users[i].in_use = FALSE; + } + + DBG("eth %d/%s wifi %d/%s bt %d/%s cellular %d/%s sessions %s", + session_users[CONNMAN_SERVICE_TYPE_ETHERNET].users, + session_users[CONNMAN_SERVICE_TYPE_ETHERNET].in_use == TRUE? "yes" : "no", + session_users[CONNMAN_SERVICE_TYPE_WIFI].users, + session_users[CONNMAN_SERVICE_TYPE_WIFI].in_use == TRUE? "yes" : "no", + session_users[CONNMAN_SERVICE_TYPE_BLUETOOTH].users, + session_users[CONNMAN_SERVICE_TYPE_BLUETOOTH].in_use == TRUE? "yes" : "no", + session_users[CONNMAN_SERVICE_TYPE_CELLULAR].users, + session_users[CONNMAN_SERVICE_TYPE_CELLULAR].in_use == TRUE? "yes" : "no", + sessions_active == TRUE ? "TRUE" : "FALSE"); +} + +void __connman_service_filter_types(connman_bool_t add, GSList *list) +{ + while (list != NULL) { + enum connman_service_type type = GPOINTER_TO_INT(list->data); + int *session_count; + + switch (type) { + case CONNMAN_SERVICE_TYPE_ETHERNET: + case CONNMAN_SERVICE_TYPE_WIFI: + case CONNMAN_SERVICE_TYPE_WIMAX: + case CONNMAN_SERVICE_TYPE_BLUETOOTH: + case CONNMAN_SERVICE_TYPE_CELLULAR: + session_count = &session_users[type].users; + if (add == TRUE) + __sync_add_and_fetch(session_count, 1); + else + __sync_add_and_fetch(session_count, 1); + break; + + case CONNMAN_SERVICE_TYPE_UNKNOWN: + case CONNMAN_SERVICE_TYPE_SYSTEM: + case CONNMAN_SERVICE_TYPE_GPS: + case CONNMAN_SERVICE_TYPE_VPN: + case CONNMAN_SERVICE_TYPE_GADGET: + break; + } + + list = g_slist_next(list); + } + + update_session_filter(); +} + +} + struct preferred_tech_data { GSequence *preferred_list; enum connman_service_type type; -- 1.7.10.4 _______________________________________________ connman mailing list connman@connman.net http://lists.connman.net/listinfo/connman