From 9ed84fea02bfcd5b90e694b104bb3a57d4844ffa Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Mon, 9 May 2011 17:50:09 +0200 Subject: [PATCH] service: Add __connman_service_session_inc()/dec() --- src/connman.h | 3 +++ src/service.c | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/connman.h b/src/connman.h index 1577a2c..a820367 100644 --- a/src/connman.h +++ b/src/connman.h @@ -585,6 +585,9 @@ connman_bool_t __connman_service_is_connected(struct connman_service *service); connman_bool_t __connman_service_is_idle(struct connman_service *service); const char *__connman_service_get_name(struct connman_service *service); +void __connman_service_session_inc(struct connman_service *service); +connman_bool_t __connman_service_session_dec(struct connman_service *service); + #include int __connman_location_init(void); diff --git a/src/service.c b/src/service.c index ad41cb3..7d25c9f 100644 --- a/src/service.c +++ b/src/service.c @@ -53,6 +53,7 @@ struct connman_stats_counter { struct connman_service { gint refcount; + gint session_usage_count; char *identifier; char *path; enum connman_service_type type; @@ -1610,6 +1611,27 @@ const char *__connman_service_get_name(struct connman_service *service) return service->name; } +void __connman_service_session_inc(struct connman_service *service) +{ + DBG("service %p", service); + + g_atomic_int_inc(&service->session_usage_count); +} + +connman_bool_t __connman_service_session_dec(struct connman_service *service) +{ + connman_bool_t in_use; + + if (g_atomic_int_dec_and_test(&service->session_usage_count) == TRUE) + in_use = FALSE; + else + in_use = TRUE; + + DBG("service %p last %d", service, in_use); + + return in_use; +} + static void append_properties(DBusMessageIter *dict, dbus_bool_t limited, struct connman_service *service) { @@ -3046,6 +3068,7 @@ static void service_initialize(struct connman_service *service) DBG("service %p", service); service->refcount = 1; + service->session_usage_count = 0; service->type = CONNMAN_SERVICE_TYPE_UNKNOWN; service->mode = CONNMAN_SERVICE_MODE_UNKNOWN; -- 2.7.4