summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2009-05-26 16:20:00 -0300
committerLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2009-05-27 11:25:24 -0300
commit21e9b05eb5c160e0271af06b0ad3c70baff07994 (patch)
tree0251cf9efcf69efe03a3653f1b3d87041267fc0b /src
parent5e5fbd39b64ff0ad84e9be9a51daa020638e679b (diff)
downloadbluez-21e9b05eb5c160e0271af06b0ad3c70baff07994.tar.gz
Introduce btd_adapter_ref an btd_adapter_unref.
Diffstat (limited to 'src')
-rw-r--r--src/adapter.c38
-rw-r--r--src/adapter.h3
2 files changed, 35 insertions, 6 deletions
diff --git a/src/adapter.c b/src/adapter.c
index 25ec33a87..0dae8603e 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -128,6 +128,7 @@ struct btd_adapter {
gboolean off_requested; /* DEVDOWN ioctl was called */
uint8_t svc_cache; /* For bluetoothd startup */
+ gint ref;
};
static void adapter_set_pairable_timeout(struct btd_adapter *adapter,
@@ -2348,10 +2349,37 @@ static void adapter_free(gpointer user_data)
agent_destroy(adapter->agent, FALSE);
adapter->agent = NULL;
+ debug("adapter_free(%p)", adapter);
+
g_free(adapter->path);
g_free(adapter);
+}
+
+struct btd_adapter *btd_adapter_ref(struct btd_adapter *adapter)
+{
+ adapter->ref++;
+
+ debug("btd_adapter_ref(%p): ref=%d", adapter, adapter->ref);
- return;
+ return adapter;
+}
+
+void btd_adapter_unref(struct btd_adapter *adapter)
+{
+ gchar *path;
+
+ adapter->ref--;
+
+ debug("btd_adapter_unref(%p): ref=%d", adapter, adapter->ref);
+
+ if (adapter->ref > 0)
+ return;
+
+ path = g_strdup(adapter->path);
+
+ g_dbus_unregister_interface(connection, path, ADAPTER_INTERFACE);
+
+ g_free(path);
}
struct btd_adapter *adapter_create(DBusConnection *conn, int id,
@@ -2386,15 +2414,14 @@ struct btd_adapter *adapter_create(DBusConnection *conn, int id,
return NULL;
}
- return adapter;
+ return btd_adapter_ref(adapter);
}
void adapter_remove(struct btd_adapter *adapter)
{
GSList *l;
- char *path = g_strdup(adapter->path);
- debug("Removing adapter %s", path);
+ debug("Removing adapter %s", adapter->path);
for (l = adapter->devices; l; l = l->next)
device_remove(l->data, connection, FALSE);
@@ -2406,8 +2433,7 @@ void adapter_remove(struct btd_adapter *adapter)
if (adapter->up && !adapter->already_up)
adapter_ops->stop(adapter->dev_id);
- g_dbus_unregister_interface(connection, path, ADAPTER_INTERFACE);
- g_free(path);
+ btd_adapter_unref(adapter);
}
uint16_t adapter_get_dev_id(struct btd_adapter *adapter)
diff --git a/src/adapter.h b/src/adapter.h
index a94edc6ed..31eaea6bd 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -125,6 +125,9 @@ void adapter_remove_connection(struct btd_adapter *adapter,
struct btd_device *device, uint16_t handle);
gboolean adapter_has_discov_sessions(struct btd_adapter *adapter);
+struct btd_adapter *btd_adapter_ref(struct btd_adapter *adapter);
+void btd_adapter_unref(struct btd_adapter *adapter);
+
struct btd_adapter_driver {
const char *name;
int (*probe) (struct btd_adapter *adapter);