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,
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,
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);
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)
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);