diff --git a/src/device.c b/src/device.c
index 65838f5..faf07ba 100644
--- a/src/device.c
+++ b/src/device.c
return dev->bredr_state.connected || dev->le_state.connected;
}
+static void clear_temporary_timer(struct btd_device *dev)
+{
+ if (dev->temporary_timer) {
+ timeout_remove(dev->temporary_timer);
+ dev->temporary_timer = 0;
+ }
+}
+
void device_add_connection(struct btd_device *dev, uint8_t bdaddr_type)
{
struct bearer_state *state = get_state(dev, bdaddr_type);
return;
/* Remove temporary timer while connected */
- if (dev->temporary_timer) {
- timeout_remove(dev->temporary_timer);
- dev->temporary_timer = 0;
- }
+ clear_temporary_timer(dev);
g_dbus_emit_property_changed(dbus_conn, dev->path, DEVICE_INTERFACE,
"Connected");
return FALSE;
}
+static void set_temporary_timer(struct btd_device *dev, unsigned int timeout)
+{
+ clear_temporary_timer(dev);
+
+ if (!timeout)
+ return;
+
+ dev->temporary_timer = timeout_add_seconds(timeout, device_disappeared,
+ dev, NULL);
+}
+
void device_update_last_seen(struct btd_device *device, uint8_t bdaddr_type)
{
if (bdaddr_type == BDADDR_BREDR)
return;
/* Restart temporary timer */
- if (device->temporary_timer)
- timeout_remove(device->temporary_timer);
-
- device->temporary_timer = timeout_add_seconds(btd_opts.tmpto,
- device_disappeared,
- device, NULL);
+ set_temporary_timer(device, btd_opts.tmpto);
}
/* It is possible that we have two device objects for the same device in
disconnect_all(device);
}
- if (device->temporary_timer > 0) {
- timeout_remove(device->temporary_timer);
- device->temporary_timer = 0;
- }
+ clear_temporary_timer(device);
if (device->store_id > 0) {
g_source_remove(device->store_id);
device->temporary = temporary;
- if (device->temporary_timer) {
- timeout_remove(device->temporary_timer);
- device->temporary_timer = 0;
- }
-
if (temporary) {
if (device->bredr)
adapter_whitelist_remove(device->adapter, device);
device->disable_auto_connect = TRUE;
device_set_auto_connect(device, FALSE);
}
- device->temporary_timer = timeout_add_seconds(btd_opts.tmpto,
- device_disappeared,
- device, NULL);
+ set_temporary_timer(device, btd_opts.tmpto);
return;
- }
+ } else
+ clear_temporary_timer(device);
if (device->bredr)
adapter_whitelist_add(device->adapter, device);