summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2012-10-15 14:05:13 +0300
committerJohan Hedberg <johan.hedberg@intel.com>2012-10-15 14:05:13 +0300
commitcabc76409c5ffd1aba686b5ae5b3e046aa73774a (patch)
tree9eff82011254f5f9ce36cc3cde084d07b62ce7ee
parent85f7f418190d54686a8be4d4836db96e025fc590 (diff)
core: Add timer for removing temporary discovered device objects
-rw-r--r--src/adapter.c40
-rw-r--r--src/device.c9
2 files changed, 47 insertions, 2 deletions
diff --git a/src/adapter.c b/src/adapter.c
index 44d79bae..f9427eed 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -84,6 +84,7 @@
#define OFF_TIMER 3
+#define REMOVE_TEMP_TIMEOUT (3 * 60)
#define PENDING_FOUND_MAX 5
static GSList *adapter_drivers = NULL;
@@ -146,6 +147,7 @@ struct btd_adapter {
GQueue *auths; /* Ongoing and pending auths */
GSList *connections; /* Connected devices */
GSList *devices; /* Devices structure pointers */
+ guint remove_temp; /* Remove devices timer */
GSList *mode_sessions; /* Request Mode sessions */
GSList *disc_sessions; /* Discovery sessions */
struct session_req *scanning_session;
@@ -2510,8 +2512,6 @@ static void adapter_free(gpointer user_data)
sdp_list_free(adapter->services, NULL);
- discovery_cleanup(adapter);
-
g_slist_free(adapter->connections);
g_free(adapter->path);
@@ -2621,6 +2621,13 @@ void adapter_remove(struct btd_adapter *adapter)
DBG("Removing adapter %s", adapter->path);
+ if (adapter->remove_temp > 0) {
+ g_source_remove(adapter->remove_temp);
+ adapter->remove_temp = 0;
+ }
+
+ discovery_cleanup(adapter);
+
for (l = adapter->devices; l; l = l->next)
device_remove(l->data, FALSE);
g_slist_free(adapter->devices);
@@ -2680,6 +2687,27 @@ static gboolean send_found(gpointer user_data)
return FALSE;
}
+static gboolean adapter_remove_temp(gpointer data)
+{
+ struct btd_adapter *adapter = data;
+ GSList *l, *next;
+
+ DBG("%s", adapter->path);
+
+ adapter->remove_temp = 0;
+
+ for (l = adapter->devices; l != NULL; l = next) {
+ struct btd_device *dev = l->data;
+
+ next = g_slist_next(l);
+
+ if (device_is_temporary(dev))
+ adapter_remove_device(adapter, dev, TRUE);
+ }
+
+ return FALSE;
+}
+
void adapter_set_discovering(struct btd_adapter *adapter,
gboolean discovering)
{
@@ -2695,12 +2723,20 @@ void adapter_set_discovering(struct btd_adapter *adapter,
ADAPTER_INTERFACE, "Discovering");
if (discovering) {
+ if (adapter->remove_temp > 0) {
+ g_source_remove(adapter->remove_temp);
+ adapter->remove_temp = 0;
+ }
discovery->id = g_timeout_add_seconds(1, send_found, adapter);
return;
}
discovery_cleanup(adapter);
+ adapter->remove_temp = g_timeout_add_seconds(REMOVE_TEMP_TIMEOUT,
+ adapter_remove_temp,
+ adapter);
+
if (adapter->discov_suspended)
return;
diff --git a/src/device.c b/src/device.c
index 349ae208..7e940a17 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1271,6 +1271,8 @@ static DBusMessage *dev_connect(DBusConnection *conn, DBusMessage *msg,
if (dev->pending || dev->connect || dev->browse)
return btd_error_in_progress(msg);
+ device_set_temporary(dev, FALSE);
+
if (!dev->svc_resolved) {
err = device_resolve_svc(dev, msg);
if (err < 0)
@@ -1359,6 +1361,8 @@ static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg,
const char *agent_path, *capability;
uint8_t io_cap;
+ device_set_temporary(device, FALSE);
+
if (!dbus_message_get_args(msg, NULL,
DBUS_TYPE_OBJECT_PATH, &agent_path,
DBUS_TYPE_STRING, &capability,
@@ -1438,6 +1442,8 @@ void device_add_connection(struct btd_device *device)
return;
}
+ device_set_temporary(device, FALSE);
+
device->connected = TRUE;
g_dbus_emit_property_changed(btd_get_dbus_connection(), device->path,
@@ -2860,6 +2866,9 @@ void device_set_temporary(struct btd_device *device, gboolean temporary)
if (!device)
return;
+ if (device->temporary == temporary)
+ return;
+
DBG("temporary %d", temporary);
if (temporary)