aboutsummaryrefslogtreecommitdiff
path: root/health
diff options
context:
space:
mode:
authorSantiago Carot-Nemesio <sancane@gmail.com>2010-11-11 16:09:00 +0100
committerJohan Hedberg <johan.hedberg@nokia.com>2010-11-18 16:56:26 +0200
commit8cc8784b8f353b8c5a86143cd21aec7d86e0baf9 (patch)
tree787efcd340057e813828b45a0ba019d9072badef /health
parentfda9a5a1bc6e81e70a6b139f94abbcf24d7e4e9c (diff)
downloadbluez-8cc8784b8f353b8c5a86143cd21aec7d86e0baf9.tar.gz
Add reference counter to hdp_device
Diffstat (limited to 'health')
-rw-r--r--health/hdp.c36
-rw-r--r--health/hdp_types.h1
-rw-r--r--health/hdp_util.c3
-rw-r--r--health/hdp_util.h5
4 files changed, 38 insertions, 7 deletions
diff --git a/health/hdp.c b/health/hdp.c
index 69ac5b55..768d6dfe 100644
--- a/health/hdp.c
+++ b/health/hdp.c
@@ -93,6 +93,7 @@ static void free_hdp_create_dc(struct hdp_create_dc *dc_data)
dbus_message_unref(dc_data->msg);
dbus_connection_unref(dc_data->conn);
hdp_application_unref(dc_data->app);
+ health_device_unref(dc_data->dev);
g_free(dc_data);
}
@@ -700,6 +701,7 @@ static void health_channel_destroy(void *data)
free_echo_data(hdp_chan->edata);
hdp_application_unref(hdp_chan->app);
+ health_device_unref(hdp_chan->dev);
g_free(hdp_chan->path);
g_free(hdp_chan);
}
@@ -723,7 +725,7 @@ static struct hdp_channel *create_channel(struct hdp_device *dev,
hdp_chann = g_new0(struct hdp_channel, 1);
hdp_chann->config = config;
- hdp_chann->dev = dev;
+ hdp_chann->dev = health_device_ref(dev);
hdp_chann->mdl = mdl;
hdp_chann->mdlid = mdlid;
hdp_chann->app = hdp_application_ref(app);
@@ -1723,7 +1725,7 @@ static DBusMessage *device_echo(DBusConnection *conn,
GError *err = NULL;
data = g_new0(struct hdp_create_dc, 1);
- data->dev = device;
+ data->dev = health_device_ref(device);
data->mdep = HDP_MDEP_ECHO;
data->config = HDP_RELIABLE_DC;
data->msg = dbus_message_ref(msg);
@@ -1842,7 +1844,7 @@ static DBusMessage *device_create_channel(DBusConnection *conn,
"channel should be reliable");
data = g_new0(struct hdp_create_dc, 1);
- data->dev = device;
+ data->dev = health_device_ref(device);
data->config = config;
data->app = hdp_application_ref(app);
data->msg = dbus_message_ref(msg);
@@ -2001,7 +2003,7 @@ static void health_device_destroy(void *data)
remove_channels(device);
devices = g_slist_remove(devices, device);
- free_health_device(device);
+ health_device_unref(device);
}
static GDBusMethodTable health_device_methods[] = {
@@ -2036,8 +2038,9 @@ static struct hdp_device *create_health_device(DBusConnection *conn,
dev = g_new0(struct hdp_device, 1);
dev->conn = dbus_connection_ref(conn);
dev->dev = btd_device_ref(device);
- l = g_slist_find_custom(adapters, adapter, cmp_adapter);
+ health_device_ref(dev);
+ l = g_slist_find_custom(adapters, adapter, cmp_adapter);
if (!l)
goto fail;
@@ -2056,7 +2059,7 @@ static struct hdp_device *create_health_device(DBusConnection *conn,
return dev;
fail:
- free_health_device(dev);
+ health_device_unref(dev);
return NULL;
}
@@ -2121,3 +2124,24 @@ void hdp_manager_stop()
dbus_connection_unref(connection);
DBG("Stopped Health manager");
}
+
+struct hdp_device *health_device_ref(struct hdp_device *hdp_dev)
+{
+ hdp_dev->ref++;
+
+ DBG("health_device_ref(%p): ref=%d", hdp_dev, hdp_dev->ref);
+
+ return hdp_dev;
+}
+
+void health_device_unref(struct hdp_device *hdp_dev)
+{
+ hdp_dev->ref--;
+
+ DBG("health_device_unref(%p): ref=%d", hdp_dev, hdp_dev->ref);
+
+ if (hdp_dev->ref > 0)
+ return;
+
+ free_health_device(hdp_dev);
+}
diff --git a/health/hdp_types.h b/health/hdp_types.h
index a9937235..9c07c329 100644
--- a/health/hdp_types.h
+++ b/health/hdp_types.h
@@ -107,6 +107,7 @@ struct hdp_device {
GSList *channels; /* Data Channel list */
struct hdp_channel *ndc; /* Data channel being negotiated */
struct hdp_channel *fr; /* First reliable data channel */
+ gint ref; /* Reference counting */
};
struct hdp_echo_data;
diff --git a/health/hdp_util.c b/health/hdp_util.c
index a766be42..2718fcec 100644
--- a/health/hdp_util.c
+++ b/health/hdp_util.c
@@ -992,6 +992,7 @@ static void con_mcl_data_unref(struct conn_mcl_data *conn_data)
if (conn_data->destroy)
conn_data->destroy(conn_data->data);
+ health_device_unref(conn_data->dev);
g_free(conn_data);
}
@@ -1083,7 +1084,7 @@ gboolean hdp_establish_mcl(struct hdp_device *device,
conn_data->func = func;
conn_data->data = data;
conn_data->destroy = destroy;
- conn_data->dev = device;
+ conn_data->dev = health_device_ref(device);
bt_string2uuid(&uuid, HDP_UUID);
if (bt_search_service(&src, &dst, &uuid, search_cb, conn_data,
diff --git a/health/hdp_util.h b/health/hdp_util.h
index c943ce2f..fc59f502 100644
--- a/health/hdp_util.h
+++ b/health/hdp_util.h
@@ -50,7 +50,12 @@ gboolean hdp_get_dcpsm(struct hdp_device *device, hdp_continue_dcpsm_f func,
GDestroyNotify destroy,
GError **err);
+
struct hdp_application *hdp_application_ref(struct hdp_application *app);
void hdp_application_unref(struct hdp_application *app);
+struct hdp_device *health_device_ref(struct hdp_device *hdp_dev);
+void health_device_unref(struct hdp_device *hdp_dev);
+
+
#endif /* __HDP_UTIL_H__ */