2021-03-16 20:55:40

by Frédéric Danis

[permalink] [raw]
Subject: [PATCH Bluez v4 0/4] adapter: Fix discovery trigger for 0 second delay

When calling `StartDiscovery` the effective start can take around 10 ms or
up to 700 ms.
g_timeout_add_seconds() call doesn't ensure the time for the first call of
the timer if the delay is less or equal to 1 second.

v2: Fix issue found by CI
v3: Add a wrapper function for g_timeout_add_seconds and replace calls to it in
src/*, profiles/* and plugins/*
v4: Fix issue found by CI

Frédéric Danis (4):
shared/timeout: Add timeout_add_seconds abstraction
src: Replace calls to g_timeout_add_seconds by timeout_add_seconds
plugins: Replace calls to g_timeout_add_seconds by timeout_add_seconds
profiles: Replace calls to g_timeout_add_seconds by
timeout_add_seconds

plugins/policy.c | 91 ++++++++++++++++++-----------------
profiles/audio/a2dp.c | 17 ++++---
profiles/audio/avctp.c | 44 +++++++++--------
profiles/audio/avdtp.c | 61 ++++++++++++-----------
profiles/audio/avrcp.c | 13 ++---
profiles/health/hdp.c | 16 +++---
profiles/health/mcap.c | 21 ++++----
profiles/input/device.c | 33 +++++++------
profiles/network/bnep.c | 12 +++--
profiles/sap/server.c | 13 ++---
src/adapter.c | 90 ++++++++++++++++++----------------
src/adv_monitor.c | 14 +++---
src/advertising.c | 28 ++++++-----
src/device.c | 60 ++++++++++++-----------
src/main.c | 7 +--
src/sdp-client.c | 13 ++---
src/shared/tester.c | 16 +++---
src/shared/timeout-ell.c | 6 +++
src/shared/timeout-glib.c | 27 +++++++++++
src/shared/timeout-mainloop.c | 6 +++
src/shared/timeout.h | 3 ++
21 files changed, 332 insertions(+), 259 deletions(-)

--
2.18.0


2021-03-16 22:51:51

by Frédéric Danis

[permalink] [raw]
Subject: [PATCH Bluez v4 1/4] shared/timeout: Add timeout_add_seconds abstraction

g_timeout_add_seconds() call doesn't ensure the time for the first call of
the timer if the delay is less or equal to 1 second.
In case of a 0 delay call g_idle_add() instead of g_timeout_add_seconds().
---
src/shared/tester.c | 16 +++++++++-------
src/shared/timeout-ell.c | 6 ++++++
src/shared/timeout-glib.c | 27 +++++++++++++++++++++++++++
src/shared/timeout-mainloop.c | 6 ++++++
src/shared/timeout.h | 3 +++
5 files changed, 51 insertions(+), 7 deletions(-)

diff --git a/src/shared/tester.c b/src/shared/tester.c
index af33a79cd..c07cbc11c 100644
--- a/src/shared/tester.c
+++ b/src/shared/tester.c
@@ -36,6 +36,7 @@
#include "src/shared/util.h"
#include "src/shared/tester.h"
#include "src/shared/log.h"
+#include "src/shared/timeout.h"

#define COLOR_OFF "\x1B[0m"
#define COLOR_BLACK "\x1B[0;30m"
@@ -126,7 +127,7 @@ static void test_destroy(gpointer data)
struct test_case *test = data;

if (test->timeout_id > 0)
- g_source_remove(test->timeout_id);
+ timeout_remove(test->timeout_id);

if (test->teardown_id > 0)
g_source_remove(test->teardown_id);
@@ -429,7 +430,7 @@ static gboolean teardown_callback(gpointer user_data)
return FALSE;
}

-static gboolean test_timeout(gpointer user_data)
+static bool test_timeout(gpointer user_data)
{
struct test_case *test = user_data;

@@ -470,8 +471,9 @@ static void next_test_case(void)
test->start_time = g_timer_elapsed(test_timer, NULL);

if (test->timeout > 0)
- test->timeout_id = g_timeout_add_seconds(test->timeout,
- test_timeout, test);
+ test->timeout_id = timeout_add_seconds(test->timeout,
+ test_timeout, test,
+ NULL);

test->stage = TEST_STAGE_PRE_SETUP;

@@ -542,7 +544,7 @@ void tester_pre_setup_failed(void)
return;

if (test->timeout_id > 0) {
- g_source_remove(test->timeout_id);
+ timeout_remove(test->timeout_id);
test->timeout_id = 0;
}

@@ -583,7 +585,7 @@ void tester_setup_failed(void)
test->stage = TEST_STAGE_POST_TEARDOWN;

if (test->timeout_id > 0) {
- g_source_remove(test->timeout_id);
+ timeout_remove(test->timeout_id);
test->timeout_id = 0;
}

@@ -606,7 +608,7 @@ static void test_result(enum test_result result)
return;

if (test->timeout_id > 0) {
- g_source_remove(test->timeout_id);
+ timeout_remove(test->timeout_id);
test->timeout_id = 0;
}

diff --git a/src/shared/timeout-ell.c b/src/shared/timeout-ell.c
index 023364069..6416d8590 100644
--- a/src/shared/timeout-ell.c
+++ b/src/shared/timeout-ell.c
@@ -101,3 +101,9 @@ void timeout_remove(unsigned int id)
if (to)
l_timeout_remove(to);
}
+
+unsigned int timeout_add_seconds(unsigned int timeout, timeout_func_t func,
+ void *user_data, timeout_destroy_func_t destroy)
+{
+ return timeout_add(timeout * 1000, func, user_data, destroy);
+}
diff --git a/src/shared/timeout-glib.c b/src/shared/timeout-glib.c
index 8bdb7a662..3268d480c 100644
--- a/src/shared/timeout-glib.c
+++ b/src/shared/timeout-glib.c
@@ -71,3 +71,30 @@ void timeout_remove(unsigned int id)
if (source)
g_source_destroy(source);
}
+
+unsigned int timeout_add_seconds(unsigned int timeout, timeout_func_t func,
+ void *user_data, timeout_destroy_func_t destroy)
+{
+ struct timeout_data *data;
+ guint id;
+
+ data = g_try_new0(struct timeout_data, 1);
+ if (!data)
+ return 0;
+
+ data->func = func;
+ data->destroy = destroy;
+ data->user_data = user_data;
+
+ if (!timeout)
+ id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, timeout_callback,
+ data, timeout_destroy);
+ else
+ id = g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, timeout,
+ timeout_callback, data,
+ timeout_destroy);
+ if (!id)
+ g_free(data);
+
+ return id;
+}
diff --git a/src/shared/timeout-mainloop.c b/src/shared/timeout-mainloop.c
index 5ffa65c2a..9be803cda 100644
--- a/src/shared/timeout-mainloop.c
+++ b/src/shared/timeout-mainloop.c
@@ -71,3 +71,9 @@ void timeout_remove(unsigned int id)

mainloop_remove_timeout((int) id);
}
+
+unsigned int timeout_add_seconds(unsigned int timeout, timeout_func_t func,
+ void *user_data, timeout_destroy_func_t destroy)
+{
+ return timeout_add(timeout * 1000, func, user_data, destroy);
+}
diff --git a/src/shared/timeout.h b/src/shared/timeout.h
index 7e22345dd..0945c3318 100644
--- a/src/shared/timeout.h
+++ b/src/shared/timeout.h
@@ -16,3 +16,6 @@ typedef void (*timeout_destroy_func_t)(void *user_data);
unsigned int timeout_add(unsigned int timeout, timeout_func_t func,
void *user_data, timeout_destroy_func_t destroy);
void timeout_remove(unsigned int id);
+
+unsigned int timeout_add_seconds(unsigned int timeout, timeout_func_t func,
+ void *user_data, timeout_destroy_func_t destroy);
--
2.18.0

2021-03-16 22:52:06

by Frédéric Danis

[permalink] [raw]
Subject: [PATCH Bluez v4 2/4] src: Replace calls to g_timeout_add_seconds by timeout_add_seconds

Replace calls to g_timeout_add_seconds() by the timeout_add_seconds() wrapper
which takes care of 0 delay.
---
src/adapter.c | 90 ++++++++++++++++++++++++++---------------------
src/adv_monitor.c | 14 ++++----
src/advertising.c | 28 ++++++++-------
src/device.c | 60 ++++++++++++++++---------------
src/main.c | 7 ++--
src/sdp-client.c | 13 +++----
6 files changed, 115 insertions(+), 97 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index cc0849f99..2fa06b73c 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -46,6 +46,7 @@
#include "src/shared/queue.h"
#include "src/shared/att.h"
#include "src/shared/gatt-db.h"
+#include "src/shared/timeout.h"

#include "btio/btio.h"
#include "btd.h"
@@ -237,10 +238,12 @@ struct btd_adapter {
struct discovery_client *client; /* active discovery client */

GSList *discovery_found; /* list of found devices */
- guint discovery_idle_timeout; /* timeout between discovery runs */
- guint passive_scan_timeout; /* timeout between passive scans */
+ unsigned int discovery_idle_timeout; /* timeout between discovery
+ * runs
+ */
+ unsigned int passive_scan_timeout; /* timeout between passive scans */

- guint pairable_timeout_id; /* pairable timeout id */
+ unsigned int pairable_timeout_id; /* pairable timeout id */
guint auth_idle_id; /* Pending authorization dequeue */
GQueue *auths; /* Ongoing and pending auths */
bool pincode_requested; /* PIN requested during last bonding */
@@ -268,13 +271,13 @@ struct btd_adapter {
struct oob_handler *oob_handler;

unsigned int load_ltks_id;
- guint load_ltks_timeout;
+ unsigned int load_ltks_timeout;

unsigned int confirm_name_id;
- guint confirm_name_timeout;
+ unsigned int confirm_name_timeout;

unsigned int pair_device_id;
- guint pair_device_timeout;
+ unsigned int pair_device_timeout;

unsigned int db_id; /* Service event handler for GATT db */

@@ -695,7 +698,7 @@ static bool set_discoverable(struct btd_adapter *adapter, uint8_t mode,
return false;
}

-static gboolean pairable_timeout_handler(gpointer user_data)
+static bool pairable_timeout_handler(gpointer user_data)
{
struct btd_adapter *adapter = user_data;

@@ -709,7 +712,7 @@ static gboolean pairable_timeout_handler(gpointer user_data)
static void trigger_pairable_timeout(struct btd_adapter *adapter)
{
if (adapter->pairable_timeout_id > 0) {
- g_source_remove(adapter->pairable_timeout_id);
+ timeout_remove(adapter->pairable_timeout_id);
adapter->pairable_timeout_id = 0;
}

@@ -718,8 +721,9 @@ static void trigger_pairable_timeout(struct btd_adapter *adapter)

if (adapter->pairable_timeout > 0)
adapter->pairable_timeout_id =
- g_timeout_add_seconds(adapter->pairable_timeout,
- pairable_timeout_handler, adapter);
+ timeout_add_seconds(adapter->pairable_timeout,
+ pairable_timeout_handler, adapter,
+ NULL);
}

static void local_name_changed_callback(uint16_t index, uint16_t length,
@@ -1323,7 +1327,7 @@ static void passive_scanning_complete(uint8_t status, uint16_t length,
}
}

-static gboolean passive_scanning_timeout(gpointer user_data)
+static bool passive_scanning_timeout(gpointer user_data)
{
struct btd_adapter *adapter = user_data;
struct mgmt_cp_start_discovery cp;
@@ -1347,7 +1351,7 @@ static void trigger_passive_scanning(struct btd_adapter *adapter)
DBG("");

if (adapter->passive_scan_timeout > 0) {
- g_source_remove(adapter->passive_scan_timeout);
+ timeout_remove(adapter->passive_scan_timeout);
adapter->passive_scan_timeout = 0;
}

@@ -1386,8 +1390,9 @@ static void trigger_passive_scanning(struct btd_adapter *adapter)
if (!adapter->connect_list)
return;

- adapter->passive_scan_timeout = g_timeout_add_seconds(CONN_SCAN_TIMEOUT,
- passive_scanning_timeout, adapter);
+ adapter->passive_scan_timeout = timeout_add_seconds(CONN_SCAN_TIMEOUT,
+ passive_scanning_timeout, adapter,
+ NULL);
}

static void stop_passive_scanning_complete(uint8_t status, uint16_t length,
@@ -1467,7 +1472,7 @@ static void cancel_passive_scanning(struct btd_adapter *adapter)
DBG("");

if (adapter->passive_scan_timeout > 0) {
- g_source_remove(adapter->passive_scan_timeout);
+ timeout_remove(adapter->passive_scan_timeout);
adapter->passive_scan_timeout = 0;
}
}
@@ -1512,7 +1517,7 @@ static void discovery_cleanup(struct btd_adapter *adapter, int timeout)
adapter->discovery_type = 0x00;

if (adapter->discovery_idle_timeout > 0) {
- g_source_remove(adapter->discovery_idle_timeout);
+ timeout_remove(adapter->discovery_idle_timeout);
adapter->discovery_idle_timeout = 0;
}

@@ -1688,7 +1693,7 @@ static void start_discovery_complete(uint8_t status, uint16_t length,
trigger_start_discovery(adapter, IDLE_DISCOV_TIMEOUT * 2);
}

-static gboolean start_discovery_timeout(gpointer user_data)
+static bool start_discovery_timeout(gpointer user_data)
{
struct btd_adapter *adapter = user_data;
struct mgmt_cp_start_service_discovery *sd_cp;
@@ -1784,7 +1789,7 @@ static void trigger_start_discovery(struct btd_adapter *adapter, guint delay)
cancel_passive_scanning(adapter);

if (adapter->discovery_idle_timeout > 0) {
- g_source_remove(adapter->discovery_idle_timeout);
+ timeout_remove(adapter->discovery_idle_timeout);
adapter->discovery_idle_timeout = 0;
}

@@ -1797,8 +1802,8 @@ static void trigger_start_discovery(struct btd_adapter *adapter, guint delay)
if (!btd_adapter_get_powered(adapter))
return;

- adapter->discovery_idle_timeout = g_timeout_add_seconds(delay,
- start_discovery_timeout, adapter);
+ adapter->discovery_idle_timeout = timeout_add_seconds(delay,
+ start_discovery_timeout, adapter, NULL);
}

static void suspend_discovery_complete(uint8_t status, uint16_t length,
@@ -1837,7 +1842,7 @@ static void suspend_discovery(struct btd_adapter *adapter)
* The restart will be triggered when the discovery is resumed.
*/
if (adapter->discovery_idle_timeout > 0) {
- g_source_remove(adapter->discovery_idle_timeout);
+ timeout_remove(adapter->discovery_idle_timeout);
adapter->discovery_idle_timeout = 0;
}

@@ -1918,7 +1923,7 @@ static void discovering_callback(uint16_t index, uint16_t length,

case 0x01:
if (adapter->discovery_idle_timeout > 0) {
- g_source_remove(adapter->discovery_idle_timeout);
+ timeout_remove(adapter->discovery_idle_timeout);
adapter->discovery_idle_timeout = 0;
}

@@ -2404,7 +2409,7 @@ static bool parse_pathloss(DBusMessageIter *value,
return true;
}

-static bool parse_transport(DBusMessageIter *value,
+static bool parse_transport(DBusMessageIter *value,
struct discovery_filter *filter)
{
char *transport_str;
@@ -3931,7 +3936,7 @@ static void load_link_keys(struct btd_adapter *adapter, GSList *keys,
adapter->dev_id);
}

-static gboolean load_ltks_timeout(gpointer user_data)
+static bool load_ltks_timeout(gpointer user_data)
{
struct btd_adapter *adapter = user_data;

@@ -3959,7 +3964,7 @@ static void load_ltks_complete(uint8_t status, uint16_t length,

adapter->load_ltks_id = 0;

- g_source_remove(adapter->load_ltks_timeout);
+ timeout_remove(adapter->load_ltks_timeout);
adapter->load_ltks_timeout = 0;

DBG("LTKs loaded for hci%u", adapter->dev_id);
@@ -4036,8 +4041,9 @@ static void load_ltks(struct btd_adapter *adapter, GSList *keys)
* and forgets to send a command complete response. However in
* case of failures it does send a command status.
*/
- adapter->load_ltks_timeout = g_timeout_add_seconds(2,
- load_ltks_timeout, adapter);
+ adapter->load_ltks_timeout = timeout_add_seconds(2,
+ load_ltks_timeout, adapter,
+ NULL);
}

static void load_irks_complete(uint8_t status, uint16_t length,
@@ -5337,23 +5343,23 @@ static void adapter_free(gpointer user_data)
remove_discovery_list(adapter);

if (adapter->pairable_timeout_id > 0) {
- g_source_remove(adapter->pairable_timeout_id);
+ timeout_remove(adapter->pairable_timeout_id);
adapter->pairable_timeout_id = 0;
}

if (adapter->passive_scan_timeout > 0) {
- g_source_remove(adapter->passive_scan_timeout);
+ timeout_remove(adapter->passive_scan_timeout);
adapter->passive_scan_timeout = 0;
}

if (adapter->load_ltks_timeout > 0)
- g_source_remove(adapter->load_ltks_timeout);
+ timeout_remove(adapter->load_ltks_timeout);

if (adapter->confirm_name_timeout > 0)
- g_source_remove(adapter->confirm_name_timeout);
+ timeout_remove(adapter->confirm_name_timeout);

if (adapter->pair_device_timeout > 0)
- g_source_remove(adapter->pair_device_timeout);
+ timeout_remove(adapter->pair_device_timeout);

if (adapter->auth_idle_id)
g_source_remove(adapter->auth_idle_id);
@@ -6386,7 +6392,7 @@ const bdaddr_t *btd_adapter_get_address(struct btd_adapter *adapter)
return &adapter->bdaddr;
}

-static gboolean confirm_name_timeout(gpointer user_data)
+static bool confirm_name_timeout(gpointer user_data)
{
struct btd_adapter *adapter = user_data;

@@ -6414,7 +6420,7 @@ static void confirm_name_complete(uint8_t status, uint16_t length,

adapter->confirm_name_id = 0;

- g_source_remove(adapter->confirm_name_timeout);
+ timeout_remove(adapter->confirm_name_timeout);
adapter->confirm_name_timeout = 0;

DBG("Confirm name complete for hci%u", adapter->dev_id);
@@ -6445,7 +6451,7 @@ static void confirm_name(struct btd_adapter *adapter, const bdaddr_t *bdaddr,
}

if (adapter->confirm_name_timeout > 0) {
- g_source_remove(adapter->confirm_name_timeout);
+ timeout_remove(adapter->confirm_name_timeout);
adapter->confirm_name_timeout = 0;
}

@@ -6470,8 +6476,9 @@ static void confirm_name(struct btd_adapter *adapter, const bdaddr_t *bdaddr,
* and forgets to send a command complete response. However in
* case of failures it does send a command status.
*/
- adapter->confirm_name_timeout = g_timeout_add_seconds(2,
- confirm_name_timeout, adapter);
+ adapter->confirm_name_timeout = timeout_add_seconds(2,
+ confirm_name_timeout, adapter,
+ NULL);
}

static void adapter_msd_notify(struct btd_adapter *adapter,
@@ -7722,7 +7729,7 @@ static void free_pair_device_data(void *user_data)
g_free(data);
}

-static gboolean pair_device_timeout(gpointer user_data)
+static bool pair_device_timeout(gpointer user_data)
{
struct pair_device_data *data = user_data;
struct btd_adapter *adapter = data->adapter;
@@ -7749,7 +7756,7 @@ static void pair_device_complete(uint8_t status, uint16_t length,
adapter->pair_device_id = 0;

if (adapter->pair_device_timeout > 0) {
- g_source_remove(adapter->pair_device_timeout);
+ timeout_remove(adapter->pair_device_timeout);
adapter->pair_device_timeout = 0;
}

@@ -7835,8 +7842,9 @@ int adapter_bonding_attempt(struct btd_adapter *adapter, const bdaddr_t *bdaddr,
* request never times out. Therefore, add a timer to clean up
* if no response arrives
*/
- adapter->pair_device_timeout = g_timeout_add_seconds(BONDING_TIMEOUT,
- pair_device_timeout, data);
+ adapter->pair_device_timeout = timeout_add_seconds(BONDING_TIMEOUT,
+ pair_device_timeout, data,
+ NULL);

return 0;
}
diff --git a/src/adv_monitor.c b/src/adv_monitor.c
index 54751db0b..33e7c8454 100644
--- a/src/adv_monitor.c
+++ b/src/adv_monitor.c
@@ -31,6 +31,7 @@
#include "src/error.h"
#include "src/shared/mgmt.h"
#include "src/shared/queue.h"
+#include "src/shared/timeout.h"
#include "src/shared/util.h"

#include "adv_monitor.h"
@@ -125,7 +126,7 @@ struct adv_monitor_device {
*/
time_t last_seen; /* Time when last Adv was received */
bool found; /* State of the device - lost/found */
- guint lost_timer; /* Timer to track if the device goes
+ unsigned int lost_timer; /* Timer to track if the device goes
* offline/out-of-range
*/
};
@@ -1385,7 +1386,7 @@ static void monitor_device_free(void *data)
}

if (dev->lost_timer) {
- g_source_remove(dev->lost_timer);
+ timeout_remove(dev->lost_timer);
dev->lost_timer = 0;
}

@@ -1468,7 +1469,7 @@ static void report_device_state_setup(DBusMessageIter *iter, void *user_data)
}

/* Handles a situation where the device goes offline/out-of-range */
-static gboolean handle_device_lost_timeout(gpointer user_data)
+static bool handle_device_lost_timeout(gpointer user_data)
{
struct adv_monitor_device *dev = user_data;
struct adv_monitor *monitor = dev->monitor;
@@ -1534,7 +1535,7 @@ static void adv_monitor_filter_rssi(struct adv_monitor *monitor,
}

if (dev->lost_timer) {
- g_source_remove(dev->lost_timer);
+ timeout_remove(dev->lost_timer);
dev->lost_timer = 0;
}

@@ -1609,7 +1610,8 @@ static void adv_monitor_filter_rssi(struct adv_monitor *monitor,
*/
if (dev->found) {
dev->lost_timer =
- g_timeout_add_seconds(monitor->low_rssi_timeout,
- handle_device_lost_timeout, dev);
+ timeout_add_seconds(monitor->low_rssi_timeout,
+ handle_device_lost_timeout, dev,
+ NULL);
}
}
diff --git a/src/advertising.c b/src/advertising.c
index 15a343e52..d76e97a74 100644
--- a/src/advertising.c
+++ b/src/advertising.c
@@ -32,6 +32,7 @@
#include "src/shared/ad.h"
#include "src/shared/mgmt.h"
#include "src/shared/queue.h"
+#include "src/shared/timeout.h"
#include "src/shared/util.h"
#include "advertising.h"

@@ -111,10 +112,10 @@ static void client_free(void *data)
struct btd_adv_client *client = data;

if (client->to_id > 0)
- g_source_remove(client->to_id);
+ timeout_remove(client->to_id);

if (client->disc_to_id > 0)
- g_source_remove(client->disc_to_id);
+ timeout_remove(client->disc_to_id);

if (client->client) {
g_dbus_client_set_disconnect_watch(client->client, NULL, NULL);
@@ -574,7 +575,7 @@ static bool parse_duration(DBusMessageIter *iter,
return true;
}

-static gboolean client_timeout(void *user_data)
+static bool client_timeout(void *user_data)
{
struct btd_adv_client *client = user_data;

@@ -593,7 +594,7 @@ static bool parse_timeout(DBusMessageIter *iter,
{
if (!iter) {
client->timeout = 0;
- g_source_remove(client->to_id);
+ timeout_remove(client->to_id);
client->to_id = 0;
return true;
}
@@ -604,11 +605,12 @@ static bool parse_timeout(DBusMessageIter *iter,
dbus_message_iter_get_basic(iter, &client->timeout);

if (client->to_id)
- g_source_remove(client->to_id);
+ timeout_remove(client->to_id);

if (client->timeout > 0)
- client->to_id = g_timeout_add_seconds(client->timeout,
- client_timeout, client);
+ client->to_id = timeout_add_seconds(client->timeout,
+ client_timeout, client,
+ NULL);

return true;
}
@@ -945,7 +947,7 @@ static int refresh_advertisement(struct btd_adv_client *client,
return refresh_legacy_adv(client, func, mgmt_id);
}

-static gboolean client_discoverable_timeout(void *user_data)
+static bool client_discoverable_timeout(void *user_data)
{
struct btd_adv_client *client = user_data;

@@ -965,7 +967,7 @@ static bool parse_discoverable_timeout(DBusMessageIter *iter,
{
if (!iter) {
client->discoverable_to = 0;
- g_source_remove(client->disc_to_id);
+ timeout_remove(client->disc_to_id);
client->disc_to_id = 0;
return true;
}
@@ -976,11 +978,11 @@ static bool parse_discoverable_timeout(DBusMessageIter *iter,
dbus_message_iter_get_basic(iter, &client->discoverable_to);

if (client->disc_to_id)
- g_source_remove(client->disc_to_id);
+ timeout_remove(client->disc_to_id);

- client->disc_to_id = g_timeout_add_seconds(client->discoverable_to,
+ client->disc_to_id = timeout_add_seconds(client->discoverable_to,
client_discoverable_timeout,
- client);
+ client, NULL);

return true;
}
@@ -1361,7 +1363,7 @@ static DBusMessage *parse_advertisement(struct btd_adv_client *client)
}
} else if (client->disc_to_id) {
/* Ignore DiscoverableTimeout if not discoverable */
- g_source_remove(client->disc_to_id);
+ timeout_remove(client->disc_to_id);
client->disc_to_id = 0;
client->discoverable_to = 0;
}
diff --git a/src/device.c b/src/device.c
index b99f6fbb0..7a6f7643a 100644
--- a/src/device.c
+++ b/src/device.c
@@ -41,6 +41,7 @@
#include "src/shared/gatt-client.h"
#include "src/shared/gatt-server.h"
#include "src/shared/ad.h"
+#include "src/shared/timeout.h"
#include "btio/btio.h"
#include "lib/mgmt.h"
#include "attrib/att.h"
@@ -219,9 +220,9 @@ struct btd_device {
GSList *watches; /* List of disconnect_data */
bool temporary;
bool connectable;
- guint disconn_timer;
- guint discov_timer;
- guint temporary_timer; /* Temporary/disappear timer */
+ unsigned int disconn_timer;
+ unsigned int discov_timer;
+ unsigned int temporary_timer; /* Temporary/disappear timer */
struct browse_req *browse; /* service discover request */
struct bonding_req *bonding;
struct authentication_req *authr; /* authentication request */
@@ -691,13 +692,13 @@ static void device_free(gpointer user_data)
(sdp_free_func_t) sdp_record_free);

if (device->disconn_timer)
- g_source_remove(device->disconn_timer);
+ timeout_remove(device->disconn_timer);

if (device->discov_timer)
- g_source_remove(device->discov_timer);
+ timeout_remove(device->discov_timer);

if (device->temporary_timer)
- g_source_remove(device->temporary_timer);
+ timeout_remove(device->temporary_timer);

if (device->connect)
dbus_message_unref(device->connect);
@@ -1469,7 +1470,7 @@ static gboolean dev_property_wake_allowed_exist(
return device_get_wake_support(device);
}

-static gboolean disconnect_all(gpointer user_data)
+static bool disconnect_all(gpointer user_data)
{
struct btd_device *device = user_data;

@@ -1494,7 +1495,7 @@ int device_block(struct btd_device *device, gboolean update_only)
return 0;

if (device->disconn_timer > 0)
- g_source_remove(device->disconn_timer);
+ timeout_remove(device->disconn_timer);

disconnect_all(device);

@@ -1644,9 +1645,9 @@ void device_request_disconnect(struct btd_device *device, DBusMessage *msg)
return;
}

- device->disconn_timer = g_timeout_add_seconds(DISCONNECT_TIMER,
+ device->disconn_timer = timeout_add_seconds(DISCONNECT_TIMER,
disconnect_all,
- device);
+ device, NULL);
}

bool device_is_disconnecting(struct btd_device *device)
@@ -2991,7 +2992,7 @@ void device_add_connection(struct btd_device *dev, uint8_t bdaddr_type)

/* Remove temporary timer while connected */
if (dev->temporary_timer) {
- g_source_remove(dev->temporary_timer);
+ timeout_remove(dev->temporary_timer);
dev->temporary_timer = 0;
}

@@ -3014,7 +3015,7 @@ void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type)
device_set_svc_refreshed(device, false);

if (device->disconn_timer > 0) {
- g_source_remove(device->disconn_timer);
+ timeout_remove(device->disconn_timer);
device->disconn_timer = 0;
}

@@ -4268,7 +4269,7 @@ void device_set_le_support(struct btd_device *device, uint8_t bdaddr_type)
store_device_info(device);
}

-static gboolean device_disappeared(gpointer user_data)
+static bool device_disappeared(gpointer user_data)
{
struct btd_device *dev = user_data;

@@ -4291,11 +4292,11 @@ void device_update_last_seen(struct btd_device *device, uint8_t bdaddr_type)

/* Restart temporary timer */
if (device->temporary_timer)
- g_source_remove(device->temporary_timer);
+ timeout_remove(device->temporary_timer);

- device->temporary_timer = g_timeout_add_seconds(btd_opts.tmpto,
+ device->temporary_timer = timeout_add_seconds(btd_opts.tmpto,
device_disappeared,
- device);
+ device, NULL);
}

/* It is possible that we have two device objects for the same device in
@@ -4482,12 +4483,12 @@ void device_remove(struct btd_device *device, gboolean remove_stored)

if (btd_device_is_connected(device)) {
if (device->disconn_timer > 0)
- g_source_remove(device->disconn_timer);
+ timeout_remove(device->disconn_timer);
disconnect_all(device);
}

if (device->temporary_timer > 0) {
- g_source_remove(device->temporary_timer);
+ timeout_remove(device->temporary_timer);
device->temporary_timer = 0;
}

@@ -5636,7 +5637,7 @@ int device_discover_services(struct btd_device *device)
err = device_browse_gatt(device, NULL);

if (err == 0 && device->discov_timer) {
- g_source_remove(device->discov_timer);
+ timeout_remove(device->discov_timer);
device->discov_timer = 0;
}

@@ -5689,7 +5690,7 @@ void btd_device_set_temporary(struct btd_device *device, bool temporary)
device->temporary = temporary;

if (device->temporary_timer) {
- g_source_remove(device->temporary_timer);
+ timeout_remove(device->temporary_timer);
device->temporary_timer = 0;
}

@@ -5701,9 +5702,9 @@ void btd_device_set_temporary(struct btd_device *device, bool temporary)
device->disable_auto_connect = TRUE;
device_set_auto_connect(device, FALSE);
}
- device->temporary_timer = g_timeout_add_seconds(btd_opts.tmpto,
+ device->temporary_timer = timeout_add_seconds(btd_opts.tmpto,
device_disappeared,
- device);
+ device, NULL);
return;
}

@@ -5934,7 +5935,7 @@ bool device_is_connectable(struct btd_device *device)
return (device->ad_flags[0] & 0x03);
}

-static gboolean start_discovery(gpointer user_data)
+static bool start_discovery(gpointer user_data)
{
struct btd_device *device = user_data;

@@ -6083,7 +6084,7 @@ void device_bonding_complete(struct btd_device *device, uint8_t bdaddr_type,
/* If we are initiators remove any discovery timer and just
* start discovering services directly */
if (device->discov_timer) {
- g_source_remove(device->discov_timer);
+ timeout_remove(device->discov_timer);
device->discov_timer = 0;
}

@@ -6100,10 +6101,10 @@ void device_bonding_complete(struct btd_device *device, uint8_t bdaddr_type,
* active discovery or discovery timer, set discovery
* timer */
DBG("setting timer for reverse service discovery");
- device->discov_timer = g_timeout_add_seconds(
+ device->discov_timer = timeout_add_seconds(
DISCOVERY_TIMER,
start_discovery,
- device);
+ device, NULL);
}
}
}
@@ -6142,8 +6143,11 @@ unsigned int device_wait_for_svc_complete(struct btd_device *dev,
if (state->svc_resolved || !btd_opts.reverse_discovery)
cb->idle_id = g_idle_add(svc_idle_cb, cb);
else if (dev->discov_timer > 0) {
- g_source_remove(dev->discov_timer);
- dev->discov_timer = g_idle_add(start_discovery, dev);
+ timeout_remove(dev->discov_timer);
+ dev->discov_timer = timeout_add_seconds(
+ 0,
+ start_discovery,
+ dev, NULL);
}

return cb->id;
diff --git a/src/main.c b/src/main.c
index 572dc939c..c32bda7d4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -41,6 +41,7 @@

#include "shared/att-types.h"
#include "shared/mainloop.h"
+#include "shared/timeout.h"
#include "lib/uuid.h"
#include "shared/util.h"
#include "btd.h"
@@ -853,7 +854,7 @@ void btd_exit(void)
mainloop_quit();
}

-static gboolean quit_eventloop(gpointer user_data)
+static bool quit_eventloop(gpointer user_data)
{
btd_exit();
return FALSE;
@@ -868,8 +869,8 @@ static void signal_callback(int signum, void *user_data)
case SIGTERM:
if (!terminated) {
info("Terminating");
- g_timeout_add_seconds(SHUTDOWN_GRACE_SECONDS,
- quit_eventloop, NULL);
+ timeout_add_seconds(SHUTDOWN_GRACE_SECONDS,
+ quit_eventloop, NULL, NULL);

mainloop_sd_notify("STATUS=Powering down");
adapter_shutdown();
diff --git a/src/sdp-client.c b/src/sdp-client.c
index 55f5bc323..71d3d9e95 100644
--- a/src/sdp-client.c
+++ b/src/sdp-client.c
@@ -21,6 +21,7 @@
#include "lib/sdp_lib.h"

#include "btio/btio.h"
+#include "shared/timeout.h"
#include "log.h"
#include "sdp-client.h"

@@ -31,7 +32,7 @@ struct cached_sdp_session {
bdaddr_t src;
bdaddr_t dst;
sdp_session_t *session;
- guint timer;
+ unsigned int timer;
guint io_id;
};

@@ -44,7 +45,7 @@ static void cleanup_cached_session(struct cached_sdp_session *cached)
g_free(cached);
}

-static gboolean cached_session_expired(gpointer user_data)
+static bool cached_session_expired(gpointer user_data)
{
struct cached_sdp_session *cached = user_data;

@@ -66,7 +67,7 @@ static sdp_session_t *get_cached_sdp_session(const bdaddr_t *src,
if (bacmp(&c->src, src) || bacmp(&c->dst, dst))
continue;

- g_source_remove(c->timer);
+ timeout_remove(c->timer);
g_source_remove(c->io_id);

session = c->session;
@@ -85,7 +86,7 @@ static gboolean disconnect_watch(GIOChannel *chan, GIOCondition cond,
{
struct cached_sdp_session *cached = user_data;

- g_source_remove(cached->timer);
+ timeout_remove(cached->timer);
cleanup_cached_session(cached);

return FALSE;
@@ -107,9 +108,9 @@ static void cache_sdp_session(bdaddr_t *src, bdaddr_t *dst,

cached_sdp_sessions = g_slist_append(cached_sdp_sessions, cached);

- cached->timer = g_timeout_add_seconds(CACHE_TIMEOUT,
+ cached->timer = timeout_add_seconds(CACHE_TIMEOUT,
cached_session_expired,
- cached);
+ cached, NULL);

/* Watch the connection state during cache timeout */
sk = sdp_get_socket(session);
--
2.18.0

2021-03-16 22:52:49

by Frédéric Danis

[permalink] [raw]
Subject: [PATCH Bluez v4 4/4] profiles: Replace calls to g_timeout_add_seconds by timeout_add_seconds

Replace calls to g_timeout_add_seconds() by the timeout_add_seconds() wrapper
which takes care of 0 delay.
---
profiles/audio/a2dp.c | 17 ++++++------
profiles/audio/avctp.c | 44 +++++++++++++++--------------
profiles/audio/avdtp.c | 61 ++++++++++++++++++++---------------------
profiles/audio/avrcp.c | 13 +++++----
profiles/health/hdp.c | 16 +++++------
profiles/health/mcap.c | 21 +++++++-------
profiles/input/device.c | 33 ++++++++++++----------
profiles/network/bnep.c | 12 ++++----
profiles/sap/server.c | 13 +++++----
9 files changed, 120 insertions(+), 110 deletions(-)

diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index 98cae97b9..d31ed845c 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -41,6 +41,7 @@
#include "src/log.h"
#include "src/sdpd.h"
#include "src/shared/queue.h"
+#include "src/shared/timeout.h"
#include "src/shared/util.h"

#include "btio/btio.h"
@@ -69,7 +70,7 @@ struct a2dp_sep {
struct avdtp_local_sep *lsep;
struct avdtp *session;
struct avdtp_stream *stream;
- guint suspend_timer;
+ unsigned int suspend_timer;
gboolean delay_reporting;
gboolean locked;
gboolean suspending;
@@ -480,7 +481,7 @@ static void stream_state_changed(struct avdtp_stream *stream,
return;

if (sep->suspend_timer) {
- g_source_remove(sep->suspend_timer);
+ timeout_remove(sep->suspend_timer);
sep->suspend_timer = 0;
}

@@ -970,7 +971,7 @@ static void open_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
return;
}

-static gboolean suspend_timeout(struct a2dp_sep *sep)
+static bool suspend_timeout(struct a2dp_sep *sep)
{
if (avdtp_suspend(sep->session, sep->stream) == 0)
sep->suspending = TRUE;
@@ -997,9 +998,9 @@ static gboolean start_ind(struct avdtp *session, struct avdtp_local_sep *sep,

if (!a2dp_sep->locked) {
a2dp_sep->session = avdtp_ref(session);
- a2dp_sep->suspend_timer = g_timeout_add_seconds(SUSPEND_TIMEOUT,
- (GSourceFunc) suspend_timeout,
- a2dp_sep);
+ a2dp_sep->suspend_timer = timeout_add_seconds(SUSPEND_TIMEOUT,
+ (timeout_func_t) suspend_timeout,
+ a2dp_sep, NULL);
}

if (!a2dp_sep->starting)
@@ -1055,7 +1056,7 @@ static gboolean suspend_ind(struct avdtp *session, struct avdtp_local_sep *sep,
DBG("Source %p: Suspend_Ind", sep);

if (a2dp_sep->suspend_timer) {
- g_source_remove(a2dp_sep->suspend_timer);
+ timeout_remove(a2dp_sep->suspend_timer);
a2dp_sep->suspend_timer = 0;
avdtp_unref(a2dp_sep->session);
a2dp_sep->session = NULL;
@@ -2995,7 +2996,7 @@ unsigned int a2dp_resume(struct avdtp *session, struct a2dp_sep *sep,
break;
case AVDTP_STATE_STREAMING:
if (!sep->suspending && sep->suspend_timer) {
- g_source_remove(sep->suspend_timer);
+ timeout_remove(sep->suspend_timer);
sep->suspend_timer = 0;
avdtp_unref(sep->session);
sep->session = NULL;
diff --git a/profiles/audio/avctp.c b/profiles/audio/avctp.c
index c959b4f49..50de33618 100644
--- a/profiles/audio/avctp.c
+++ b/profiles/audio/avctp.c
@@ -39,6 +39,7 @@
#include "src/log.h"
#include "src/error.h"
#include "src/uinput.h"
+#include "src/shared/timeout.h"

#include "avctp.h"
#include "avrcp.h"
@@ -148,7 +149,7 @@ typedef int (*avctp_process_cb) (void *data);
struct avctp_pending_req {
struct avctp_queue *queue;
uint8_t transaction;
- guint timeout;
+ unsigned int timeout;
bool retry;
int err;
avctp_process_cb process;
@@ -179,7 +180,7 @@ struct avctp_channel {

struct key_pressed {
uint16_t op;
- guint timer;
+ unsigned int timer;
bool hold;
};

@@ -320,7 +321,7 @@ static void send_key(int fd, uint16_t key, int pressed)
send_event(fd, EV_SYN, SYN_REPORT, 0);
}

-static gboolean auto_release(gpointer user_data)
+static bool auto_release(gpointer user_data)
{
struct avctp *session = user_data;

@@ -350,14 +351,15 @@ static void handle_press(struct avctp *session, uint16_t op)
send_key(session->uinput, op, 1);

done:
- session->key.timer = g_timeout_add_seconds(AVC_PRESS_TIMEOUT,
- auto_release, session);
+ session->key.timer = timeout_add_seconds(AVC_PRESS_TIMEOUT,
+ auto_release, session,
+ NULL);
}

static void handle_release(struct avctp *session, uint16_t op)
{
if (session->key.timer > 0) {
- g_source_remove(session->key.timer);
+ timeout_remove(session->key.timer);
session->key.timer = 0;
}

@@ -507,7 +509,7 @@ static void pending_destroy(gpointer data, gpointer user_data)
req->destroy(req->data);

if (req->timeout > 0)
- g_source_remove(req->timeout);
+ timeout_remove(req->timeout);

g_free(req);
}
@@ -565,7 +567,7 @@ static void avctp_disconnected(struct avctp *session)
}

if (session->key.timer > 0)
- g_source_remove(session->key.timer);
+ timeout_remove(session->key.timer);

if (session->uinput >= 0) {
char address[18];
@@ -778,7 +780,7 @@ done:
g_free(req);
}

-static gboolean req_timeout(gpointer user_data)
+static bool req_timeout(gpointer user_data)
{
struct avctp_queue *queue = user_data;
struct avctp_pending_req *p = queue->p;
@@ -816,8 +818,8 @@ static int process_passthrough(void *data)
if (ret < 0)
return ret;

- p->timeout = g_timeout_add_seconds(AVC_PRESS_TIMEOUT, req_timeout,
- p->queue);
+ p->timeout = timeout_add_seconds(AVC_PRESS_TIMEOUT, req_timeout,
+ p->queue, NULL);

return 0;
}
@@ -836,8 +838,8 @@ static int process_control(void *data)

p->retry = !p->retry;

- p->timeout = g_timeout_add_seconds(CONTROL_TIMEOUT, req_timeout,
- p->queue);
+ p->timeout = timeout_add_seconds(CONTROL_TIMEOUT, req_timeout,
+ p->queue, NULL);

return 0;
}
@@ -853,8 +855,8 @@ static int process_browsing(void *data)
if (ret < 0)
return ret;

- p->timeout = g_timeout_add_seconds(BROWSING_TIMEOUT, req_timeout,
- p->queue);
+ p->timeout = timeout_add_seconds(BROWSING_TIMEOUT, req_timeout,
+ p->queue, NULL);

return 0;
}
@@ -912,7 +914,7 @@ static void control_response(struct avctp_channel *control,
control->processed = g_slist_prepend(control->processed, p);

if (p->timeout > 0) {
- g_source_remove(p->timeout);
+ timeout_remove(p->timeout);
p->timeout = 0;
}

@@ -964,7 +966,7 @@ static void browsing_response(struct avctp_channel *browsing,
browsing->processed = g_slist_prepend(browsing->processed, p);

if (p->timeout > 0) {
- g_source_remove(p->timeout);
+ timeout_remove(p->timeout);
p->timeout = 0;
}

@@ -1833,7 +1835,7 @@ static int avctp_passthrough_release(struct avctp *session, uint8_t op)
NULL, NULL);
}

-static gboolean repeat_timeout(gpointer user_data)
+static bool repeat_timeout(gpointer user_data)
{
struct avctp *session = user_data;

@@ -1847,7 +1849,7 @@ static int release_pressed(struct avctp *session)
int ret = avctp_passthrough_release(session, session->key.op);

if (session->key.timer > 0)
- g_source_remove(session->key.timer);
+ timeout_remove(session->key.timer);

session->key.timer = 0;
session->key.op = AVC_INVALID;
@@ -1862,9 +1864,9 @@ static bool hold_pressed(struct avctp *session, uint8_t op)
return FALSE;

if (session->key.timer == 0)
- session->key.timer = g_timeout_add_seconds(AVC_HOLD_TIMEOUT,
+ session->key.timer = timeout_add_seconds(AVC_HOLD_TIMEOUT,
repeat_timeout,
- session);
+ session, NULL);

return TRUE;
}
diff --git a/profiles/audio/avdtp.c b/profiles/audio/avdtp.c
index 1d5871c62..623fe30d3 100644
--- a/profiles/audio/avdtp.c
+++ b/profiles/audio/avdtp.c
@@ -31,6 +31,7 @@
#include "btio/btio.h"
#include "src/btd.h"
#include "src/log.h"
+#include "src/shared/timeout.h"
#include "src/shared/util.h"
#include "src/shared/queue.h"
#include "src/adapter.h"
@@ -298,7 +299,7 @@ struct pending_req {
void *data;
size_t data_size;
struct avdtp_stream *stream; /* Set if the request targeted a stream */
- guint timeout;
+ unsigned int timeout;
gboolean collided;
};

@@ -357,12 +358,12 @@ struct avdtp_stream {
GSList *callbacks;
struct avdtp_service_capability *codec;
guint io_id; /* Transport GSource ID */
- guint timer; /* Waiting for other side to close or open
+ unsigned int timer; /* Waiting for other side to close or open
* the transport channel */
gboolean open_acp; /* If we are in ACT role for Open */
gboolean close_int; /* If we are in INT role for Close */
gboolean abort_int; /* If we are in INT role for Abort */
- guint start_timer; /* Wait START command timer */
+ unsigned int start_timer; /* Wait START command timer */
gboolean delay_reporting;
uint16_t delay; /* AVDTP 1.3 Delay Reporting feature */
gboolean starting; /* only valid while sep state == OPEN */
@@ -404,7 +405,7 @@ struct avdtp {
struct discover_callback *discover;
struct pending_req *req;

- guint dc_timer;
+ unsigned int dc_timer;
int dc_timeout;

/* Attempt stream setup instead of disconnecting */
@@ -568,7 +569,7 @@ static void pending_req_free(void *data)
struct pending_req *req = data;

if (req->timeout)
- g_source_remove(req->timeout);
+ timeout_remove(req->timeout);
g_free(req->data);
g_free(req);
}
@@ -590,7 +591,7 @@ static void close_stream(struct avdtp_stream *stream)
stream->io = NULL;
}

-static gboolean stream_close_timeout(gpointer user_data)
+static bool stream_close_timeout(gpointer user_data)
{
struct avdtp_stream *stream = user_data;

@@ -603,7 +604,7 @@ static gboolean stream_close_timeout(gpointer user_data)
return FALSE;
}

-static gboolean stream_open_timeout(gpointer user_data)
+static bool stream_open_timeout(gpointer user_data)
{
struct avdtp_stream *stream = user_data;

@@ -624,12 +625,12 @@ static gboolean stream_open_timeout(gpointer user_data)
}

static void stream_set_timer(struct avdtp_stream *stream, guint timeout,
- GSourceFunc func)
+ timeout_func_t func)
{
if (stream->timer)
- g_source_remove(stream->timer);
+ timeout_remove(stream->timer);

- stream->timer = g_timeout_add_seconds(timeout, func, stream);
+ stream->timer = timeout_add_seconds(timeout, func, stream, NULL);
}

static void stream_set_pending_open(struct avdtp_stream *stream, GIOChannel *io)
@@ -729,7 +730,7 @@ static void stream_free(void *data)
rsep->stream = NULL;

if (stream->timer)
- g_source_remove(stream->timer);
+ timeout_remove(stream->timer);

if (stream->io)
close_stream(stream);
@@ -809,7 +810,7 @@ static void handle_transport_connect(struct avdtp *session, GIOChannel *io,
session->pending_open = NULL;

if (stream->timer) {
- g_source_remove(stream->timer);
+ timeout_remove(stream->timer);
stream->timer = 0;
}

@@ -1001,7 +1002,7 @@ static void avdtp_sep_set_state(struct avdtp *session,
break;
case AVDTP_STATE_STREAMING:
if (stream->start_timer) {
- g_source_remove(stream->start_timer);
+ timeout_remove(stream->start_timer);
stream->start_timer = 0;
}
stream->open_acp = FALSE;
@@ -1009,13 +1010,13 @@ static void avdtp_sep_set_state(struct avdtp *session,
case AVDTP_STATE_CLOSING:
case AVDTP_STATE_ABORTING:
if (stream->start_timer) {
- g_source_remove(stream->start_timer);
+ timeout_remove(stream->start_timer);
stream->start_timer = 0;
}
break;
case AVDTP_STATE_IDLE:
if (stream->start_timer) {
- g_source_remove(stream->start_timer);
+ timeout_remove(stream->start_timer);
stream->start_timer = 0;
}
if (session->pending_open == stream)
@@ -1107,7 +1108,7 @@ static void remove_disconnect_timer(struct avdtp *session)
if (!session->dc_timer)
return;

- g_source_remove(session->dc_timer);
+ timeout_remove(session->dc_timer);
session->dc_timer = 0;
session->stream_setup = FALSE;

@@ -1165,7 +1166,7 @@ static void connection_lost(struct avdtp *session, int err)
avdtp_unref(session);
}

-static gboolean disconnect_timeout(gpointer user_data)
+static bool disconnect_timeout(gpointer user_data)
{
struct avdtp *session = user_data;
struct btd_service *service;
@@ -1204,12 +1205,9 @@ static void set_disconnect_timer(struct avdtp *session)

DBG("timeout %d", session->dc_timeout);

- if (!session->dc_timeout)
- session->dc_timer = g_idle_add(disconnect_timeout, session);
- else
- session->dc_timer = g_timeout_add_seconds(session->dc_timeout,
- disconnect_timeout,
- session);
+ session->dc_timer = timeout_add_seconds(session->dc_timeout,
+ disconnect_timeout,
+ session, NULL);
}

void avdtp_unref(struct avdtp *session)
@@ -1865,9 +1863,9 @@ static gboolean avdtp_close_cmd(struct avdtp *session, uint8_t transaction,
AVDTP_CLOSE, NULL, 0))
return FALSE;

- stream->timer = g_timeout_add_seconds(REQ_TIMEOUT,
+ stream->timer = timeout_add_seconds(REQ_TIMEOUT,
stream_close_timeout,
- stream);
+ stream, NULL);

return TRUE;

@@ -2263,7 +2261,7 @@ static gboolean session_cb(GIOChannel *chan, GIOCondition cond,
return TRUE;
}

- g_source_remove(session->req->timeout);
+ timeout_remove(session->req->timeout);
session->req->timeout = 0;

switch (header->message_type) {
@@ -2608,7 +2606,7 @@ done:
return err;
}

-static gboolean request_timeout(gpointer user_data)
+static bool request_timeout(gpointer user_data)
{
struct avdtp *session = user_data;

@@ -2669,7 +2667,8 @@ static int send_req(struct avdtp *session, gboolean priority,
timeout = REQ_TIMEOUT;
}

- req->timeout = g_timeout_add_seconds(timeout, request_timeout, session);
+ req->timeout = timeout_add_seconds(timeout, request_timeout,
+ session, NULL);
return 0;

failed:
@@ -3567,7 +3566,7 @@ int avdtp_open(struct avdtp *session, struct avdtp_stream *stream)
&req, sizeof(req));
}

-static gboolean start_timeout(gpointer user_data)
+static bool start_timeout(gpointer user_data)
{
struct avdtp_stream *stream = user_data;
struct avdtp *session = stream->session;
@@ -3602,9 +3601,9 @@ int avdtp_start(struct avdtp *session, struct avdtp_stream *stream)
if (stream->start_timer)
return 0;

- stream->start_timer = g_timeout_add_seconds(START_TIMEOUT,
+ stream->start_timer = timeout_add_seconds(START_TIMEOUT,
start_timeout,
- stream);
+ stream, NULL);
return 0;
}

diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index c093deac8..05dd791de 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -46,6 +46,7 @@
#include "src/error.h"
#include "src/sdpd.h"
#include "src/dbus-common.h"
+#include "src/shared/timeout.h"
#include "src/shared/util.h"

#include "avctp.h"
@@ -3942,7 +3943,7 @@ static gboolean avrcp_get_capabilities_resp(struct avctp *conn, uint8_t code,

/* Connect browsing if pending */
if (session->browsing_timer > 0) {
- g_source_remove(session->browsing_timer);
+ timeout_remove(session->browsing_timer);
session->browsing_timer = 0;
avctp_connect_browsing(session->conn);
}
@@ -4037,7 +4038,7 @@ static void destroy_browsing(void *data)
static void session_init_browsing(struct avrcp *session)
{
if (session->browsing_timer > 0) {
- g_source_remove(session->browsing_timer);
+ timeout_remove(session->browsing_timer);
session->browsing_timer = 0;
}

@@ -4072,7 +4073,7 @@ static struct avrcp_data *data_init(struct avrcp *session, const char *uuid)
return data;
}

-static gboolean connect_browsing(gpointer user_data)
+static bool connect_browsing(gpointer user_data)
{
struct avrcp *session = user_data;

@@ -4096,9 +4097,9 @@ static void avrcp_connect_browsing(struct avrcp *session)
if (session->browsing_timer > 0)
return;

- session->browsing_timer = g_timeout_add_seconds(AVRCP_BROWSING_TIMEOUT,
+ session->browsing_timer = timeout_add_seconds(AVRCP_BROWSING_TIMEOUT,
connect_browsing,
- session);
+ session, NULL);
}

static void target_init(struct avrcp *session)
@@ -4261,7 +4262,7 @@ static void session_destroy(struct avrcp *session, int err)
}

if (session->browsing_timer > 0)
- g_source_remove(session->browsing_timer);
+ timeout_remove(session->browsing_timer);

if (session->controller != NULL)
controller_destroy(session);
diff --git a/profiles/health/hdp.c b/profiles/health/hdp.c
index 9f906932d..6bc41946f 100644
--- a/profiles/health/hdp.c
+++ b/profiles/health/hdp.c
@@ -31,6 +31,7 @@
#include "src/adapter.h"
#include "src/device.h"
#include "src/sdpd.h"
+#include "src/shared/timeout.h"
#include "btio/btio.h"

#include "hdp_types.h"
@@ -70,7 +71,7 @@ struct hdp_tmp_dc_data {
struct hdp_echo_data {
gboolean echo_done; /* Is a echo was already done */
gpointer buf; /* echo packet sent */
- guint tid; /* echo timeout */
+ unsigned int tid; /* echo timeout */
};

static struct hdp_channel *hdp_channel_ref(struct hdp_channel *chan)
@@ -683,7 +684,7 @@ static void free_echo_data(struct hdp_echo_data *edata)
return;

if (edata->tid > 0)
- g_source_remove(edata->tid);
+ timeout_remove(edata->tid);

if (edata->buf != NULL)
g_free(edata->buf);
@@ -1524,7 +1525,7 @@ end:
reply = g_dbus_create_reply(hdp_conn->msg, DBUS_TYPE_BOOLEAN, &value,
DBUS_TYPE_INVALID);
g_dbus_send_message(btd_get_dbus_connection(), reply);
- g_source_remove(edata->tid);
+ timeout_remove(edata->tid);
edata->tid = 0;
g_free(edata->buf);
edata->buf = NULL;
@@ -1538,7 +1539,7 @@ end:
return FALSE;
}

-static gboolean echo_timeout(gpointer data)
+static bool echo_timeout(gpointer data)
{
struct hdp_channel *chan = data;
GIOChannel *io;
@@ -1606,10 +1607,9 @@ static void hdp_echo_connect_cb(struct mcap_mdl *mdl, GError *err,
g_io_add_watch(io, G_IO_ERR | G_IO_HUP | G_IO_NVAL | G_IO_IN,
check_echo, hdp_tmp_dc_data_ref(hdp_conn));

- edata->tid = g_timeout_add_seconds_full(G_PRIORITY_DEFAULT,
- ECHO_TIMEOUT, echo_timeout,
- hdp_channel_ref(hdp_conn->hdp_chann),
- (GDestroyNotify) hdp_channel_unref);
+ edata->tid = timeout_add_seconds(ECHO_TIMEOUT, echo_timeout,
+ hdp_channel_ref(hdp_conn->hdp_chann),
+ (timeout_destroy_func_t) hdp_channel_unref);

g_io_channel_unref(io);
}
diff --git a/profiles/health/mcap.c b/profiles/health/mcap.c
index 32365fd50..be13af37a 100644
--- a/profiles/health/mcap.c
+++ b/profiles/health/mcap.c
@@ -26,6 +26,7 @@
#include "bluetooth/l2cap.h"
#include "btio/btio.h"
#include "src/log.h"
+#include "src/shared/timeout.h"

#include "mcap.h"

@@ -43,7 +44,7 @@

#define RELEASE_TIMER(__mcl) do { \
if (__mcl->tid) { \
- g_source_remove(__mcl->tid); \
+ timeout_remove(__mcl->tid); \
__mcl->tid = 0; \
} \
} while(0)
@@ -483,7 +484,7 @@ static int compare_mdl(gconstpointer a, gconstpointer b)
return 1;
}

-static gboolean wait_response_timer(gpointer data)
+static bool wait_response_timer(gpointer data)
{
struct mcap_mcl *mcl = data;

@@ -549,8 +550,8 @@ gboolean mcap_create_mdl(struct mcap_mcl *mcl,

mcl->mdls = g_slist_insert_sorted(mcl->mdls, mcap_mdl_ref(mdl),
compare_mdl);
- mcl->tid = g_timeout_add_seconds(RESPONSE_TIMER, wait_response_timer,
- mcl);
+ mcl->tid = timeout_add_seconds(RESPONSE_TIMER, wait_response_timer,
+ mcl, NULL);
return TRUE;
}

@@ -587,8 +588,8 @@ gboolean mcap_reconnect_mdl(struct mcap_mdl *mdl,
mcl->state = MCL_ACTIVE;
mcl->priv_data = con;

- mcl->tid = g_timeout_add_seconds(RESPONSE_TIMER, wait_response_timer,
- mcl);
+ mcl->tid = timeout_add_seconds(RESPONSE_TIMER, wait_response_timer,
+ mcl, NULL);
return TRUE;
}

@@ -607,8 +608,8 @@ static gboolean send_delete_req(struct mcap_mcl *mcl,

mcl->priv_data = con;

- mcl->tid = g_timeout_add_seconds(RESPONSE_TIMER, wait_response_timer,
- mcl);
+ mcl->tid = timeout_add_seconds(RESPONSE_TIMER, wait_response_timer,
+ mcl, NULL);
return TRUE;
}

@@ -718,8 +719,8 @@ gboolean mcap_mdl_abort(struct mcap_mdl *mdl, mcap_mdl_notify_cb abort_cb,
con->user_data = user_data;

mcl->priv_data = con;
- mcl->tid = g_timeout_add_seconds(RESPONSE_TIMER, wait_response_timer,
- mcl);
+ mcl->tid = timeout_add_seconds(RESPONSE_TIMER, wait_response_timer,
+ mcl, NULL);
return TRUE;
}

diff --git a/profiles/input/device.c b/profiles/input/device.c
index 326a3bcb9..50ae51855 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -39,6 +39,7 @@
#include "src/dbus-common.h"
#include "src/error.h"
#include "src/sdp-client.h"
+#include "src/shared/timeout.h"
#include "src/shared/uhid.h"

#include "device.h"
@@ -68,12 +69,12 @@ struct input_device {
struct hidp_connadd_req *req;
bool disable_sdp;
enum reconnect_mode_t reconnect_mode;
- guint reconnect_timer;
+ unsigned int reconnect_timer;
uint32_t reconnect_attempt;
struct bt_uhid *uhid;
bool uhid_created;
uint8_t report_req_pending;
- guint report_req_timer;
+ unsigned int report_req_timer;
uint32_t report_rsp_id;
bool virtual_cable_unplug;
};
@@ -140,10 +141,10 @@ static void input_device_free(struct input_device *idev)
}

if (idev->reconnect_timer > 0)
- g_source_remove(idev->reconnect_timer);
+ timeout_remove(idev->reconnect_timer);

if (idev->report_req_timer > 0)
- g_source_remove(idev->report_req_timer);
+ timeout_remove(idev->report_req_timer);

g_free(idev);
}
@@ -439,7 +440,7 @@ static void hidp_recv_ctrl_handshake(struct input_device *idev, uint8_t param)
if (pending_req_complete) {
idev->report_req_pending = 0;
if (idev->report_req_timer > 0) {
- g_source_remove(idev->report_req_timer);
+ timeout_remove(idev->report_req_timer);
idev->report_req_timer = 0;
}
idev->report_rsp_id = 0;
@@ -499,7 +500,7 @@ static void hidp_recv_ctrl_data(struct input_device *idev, uint8_t param,

idev->report_req_pending = 0;
if (idev->report_req_timer > 0) {
- g_source_remove(idev->report_req_timer);
+ timeout_remove(idev->report_req_timer);
idev->report_req_timer = 0;
}
idev->report_rsp_id = 0;
@@ -588,7 +589,7 @@ static gboolean ctrl_watch_cb(GIOChannel *chan, GIOCondition cond, gpointer data

#define REPORT_REQ_TIMEOUT 3

-static gboolean hidp_report_req_timeout(gpointer data)
+static bool hidp_report_req_timeout(gpointer data)
{
struct input_device *idev = data;
uint8_t pending_req_type;
@@ -669,8 +670,8 @@ static void hidp_send_set_report(struct uhid_event *ev, void *user_data)
if (sent) {
idev->report_req_pending = hdr;
idev->report_req_timer =
- g_timeout_add_seconds(REPORT_REQ_TIMEOUT,
- hidp_report_req_timeout, idev);
+ timeout_add_seconds(REPORT_REQ_TIMEOUT,
+ hidp_report_req_timeout, idev, NULL);
idev->report_rsp_id = ev->u.set_report.id;
} else
uhid_send_set_report_reply(idev, ev->u.set_report.id, EIO);
@@ -712,8 +713,9 @@ static void hidp_send_get_report(struct uhid_event *ev, void *user_data)
if (sent) {
idev->report_req_pending = hdr;
idev->report_req_timer =
- g_timeout_add_seconds(REPORT_REQ_TIMEOUT,
- hidp_report_req_timeout, idev);
+ timeout_add_seconds(REPORT_REQ_TIMEOUT,
+ hidp_report_req_timeout, idev,
+ NULL);
idev->report_rsp_id = ev->u.get_report.id;
} else
uhid_send_get_report_reply(idev, NULL, 0, ev->u.get_report.id,
@@ -1282,7 +1284,7 @@ static int dev_connect(struct input_device *idev)
return -EIO;
}

-static gboolean input_device_auto_reconnect(gpointer user_data)
+static bool input_device_auto_reconnect(gpointer user_data)
{
struct input_device *idev = user_data;

@@ -1352,12 +1354,13 @@ static void input_device_enter_reconnect_mode(struct input_device *idev)
return;

if (idev->reconnect_timer > 0)
- g_source_remove(idev->reconnect_timer);
+ timeout_remove(idev->reconnect_timer);

DBG("registering auto-reconnect");
idev->reconnect_attempt = 0;
- idev->reconnect_timer = g_timeout_add_seconds(30,
- input_device_auto_reconnect, idev);
+ idev->reconnect_timer = timeout_add_seconds(30,
+ input_device_auto_reconnect, idev,
+ NULL);

}

diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index 7e777e29c..f94f1da8a 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -32,6 +32,7 @@
#include "lib/uuid.h"

#include "src/log.h"
+#include "src/shared/timeout.h"
#include "src/shared/util.h"
#include "btio/btio.h"

@@ -54,7 +55,7 @@ struct bnep {
bdaddr_t dst_addr;
char iface[16];
guint attempts;
- guint setup_to;
+ unsigned int setup_to;
guint watch;
bnep_connect_cb conn_cb;
void *conn_data;
@@ -209,7 +210,7 @@ static gboolean bnep_setup_cb(GIOChannel *chan, GIOCondition cond,
return FALSE;

if (session->setup_to > 0) {
- g_source_remove(session->setup_to);
+ timeout_remove(session->setup_to);
session->setup_to = 0;
}

@@ -313,7 +314,7 @@ static int bnep_setup_conn_req(struct bnep *session)
return 0;
}

-static gboolean bnep_conn_req_to(gpointer user_data)
+static bool bnep_conn_req_to(gpointer user_data)
{
struct bnep *session = user_data;

@@ -402,8 +403,9 @@ int bnep_connect(struct bnep *session, bnep_connect_cb conn_cb,
if (err < 0)
return err;

- session->setup_to = g_timeout_add_seconds(CON_SETUP_TO,
- bnep_conn_req_to, session);
+ session->setup_to = timeout_add_seconds(CON_SETUP_TO,
+ bnep_conn_req_to, session,
+ NULL);
return 0;
}

diff --git a/profiles/sap/server.c b/profiles/sap/server.c
index b0a454ced..82365fca9 100644
--- a/profiles/sap/server.c
+++ b/profiles/sap/server.c
@@ -31,6 +31,7 @@
#include "src/log.h"
#include "src/error.h"
#include "src/dbus-common.h"
+#include "src/shared/timeout.h"
#include "src/shared/util.h"

#include "sap.h"
@@ -62,7 +63,7 @@ struct sap_connection {
GIOChannel *io;
uint32_t state;
uint8_t processing_req;
- guint timer_id;
+ unsigned int timer_id;
};

struct sap_server {
@@ -74,7 +75,7 @@ struct sap_server {

static void start_guard_timer(struct sap_server *server, guint interval);
static void stop_guard_timer(struct sap_server *server);
-static gboolean guard_timeout(gpointer data);
+static bool guard_timeout(gpointer data);

static size_t add_result_parameter(uint8_t result,
struct sap_parameter *param)
@@ -554,8 +555,8 @@ static void start_guard_timer(struct sap_server *server, guint interval)
return;

if (!conn->timer_id)
- conn->timer_id = g_timeout_add_seconds(interval, guard_timeout,
- server);
+ conn->timer_id = timeout_add_seconds(interval, guard_timeout,
+ server, NULL);
else
error("Timer is already active.");
}
@@ -565,12 +566,12 @@ static void stop_guard_timer(struct sap_server *server)
struct sap_connection *conn = server->conn;

if (conn && conn->timer_id) {
- g_source_remove(conn->timer_id);
+ timeout_remove(conn->timer_id);
conn->timer_id = 0;
}
}

-static gboolean guard_timeout(gpointer data)
+static bool guard_timeout(gpointer data)
{
struct sap_server *server = data;
struct sap_connection *conn = server->conn;
--
2.18.0

2021-03-16 22:52:57

by Frédéric Danis

[permalink] [raw]
Subject: [PATCH Bluez v4 3/4] plugins: Replace calls to g_timeout_add_seconds by timeout_add_seconds

Replace calls to g_timeout_add_seconds() by the timeout_add_seconds() wrapper
which takes care of 0 delay.
---
plugins/policy.c | 91 ++++++++++++++++++++++++------------------------
1 file changed, 46 insertions(+), 45 deletions(-)

diff --git a/plugins/policy.c b/plugins/policy.c
index ba9e1be02..bf93df096 100644
--- a/plugins/policy.c
+++ b/plugins/policy.c
@@ -31,6 +31,7 @@
#include "src/service.h"
#include "src/profile.h"
#include "src/btd.h"
+#include "src/shared/timeout.h"

#define CONTROL_CONNECT_TIMEOUT 2
#define SOURCE_RETRY_TIMEOUT 2
@@ -46,7 +47,7 @@ struct reconnect_data {
struct btd_device *dev;
bool reconnect;
GSList *services;
- guint timer;
+ unsigned int timer;
bool active;
unsigned int attempt;
bool on_resume;
@@ -77,13 +78,13 @@ static bool auto_enable = false;
struct policy_data {
struct btd_device *dev;

- guint source_timer;
+ unsigned int source_timer;
uint8_t source_retries;
- guint sink_timer;
+ unsigned int sink_timer;
uint8_t sink_retries;
- guint ct_timer;
+ unsigned int ct_timer;
uint8_t ct_retries;
- guint tg_timer;
+ unsigned int tg_timer;
uint8_t tg_retries;
};

@@ -126,7 +127,7 @@ static void policy_disconnect(struct policy_data *data,
btd_service_disconnect(service);
}

-static gboolean policy_connect_ct(gpointer user_data)
+static bool policy_connect_ct(gpointer user_data)
{
struct policy_data *data = user_data;
struct btd_service *service;
@@ -144,10 +145,10 @@ static gboolean policy_connect_ct(gpointer user_data)
static void policy_set_ct_timer(struct policy_data *data, int timeout)
{
if (data->ct_timer > 0)
- g_source_remove(data->ct_timer);
+ timeout_remove(data->ct_timer);

- data->ct_timer = g_timeout_add_seconds(timeout, policy_connect_ct,
- data);
+ data->ct_timer = timeout_add_seconds(timeout, policy_connect_ct,
+ data, NULL);
}

static struct policy_data *find_data(struct btd_device *dev)
@@ -169,16 +170,16 @@ static void policy_remove(void *user_data)
struct policy_data *data = user_data;

if (data->source_timer > 0)
- g_source_remove(data->source_timer);
+ timeout_remove(data->source_timer);

if (data->sink_timer > 0)
- g_source_remove(data->sink_timer);
+ timeout_remove(data->sink_timer);

if (data->ct_timer > 0)
- g_source_remove(data->ct_timer);
+ timeout_remove(data->ct_timer);

if (data->tg_timer > 0)
- g_source_remove(data->tg_timer);
+ timeout_remove(data->tg_timer);

g_free(data);
}
@@ -199,7 +200,7 @@ static struct policy_data *policy_get_data(struct btd_device *dev)
return data;
}

-static gboolean policy_connect_sink(gpointer user_data)
+static bool policy_connect_sink(gpointer user_data)
{
struct policy_data *data = user_data;
struct btd_service *service;
@@ -217,11 +218,11 @@ static gboolean policy_connect_sink(gpointer user_data)
static void policy_set_sink_timer(struct policy_data *data)
{
if (data->sink_timer > 0)
- g_source_remove(data->sink_timer);
+ timeout_remove(data->sink_timer);

- data->sink_timer = g_timeout_add_seconds(SINK_RETRY_TIMEOUT,
+ data->sink_timer = timeout_add_seconds(SINK_RETRY_TIMEOUT,
policy_connect_sink,
- data);
+ data, NULL);
}

static void sink_cb(struct btd_service *service, btd_service_state_t old_state,
@@ -240,7 +241,7 @@ static void sink_cb(struct btd_service *service, btd_service_state_t old_state,
switch (new_state) {
case BTD_SERVICE_STATE_UNAVAILABLE:
if (data->sink_timer > 0) {
- g_source_remove(data->sink_timer);
+ timeout_remove(data->sink_timer);
data->sink_timer = 0;
}
break;
@@ -255,13 +256,13 @@ static void sink_cb(struct btd_service *service, btd_service_state_t old_state,
data->sink_retries = 0;
break;
} else if (data->sink_timer > 0) {
- g_source_remove(data->sink_timer);
+ timeout_remove(data->sink_timer);
data->sink_timer = 0;
}
}

if (data->ct_timer > 0) {
- g_source_remove(data->ct_timer);
+ timeout_remove(data->ct_timer);
data->ct_timer = 0;
} else if (btd_service_get_state(controller) !=
BTD_SERVICE_STATE_DISCONNECTED)
@@ -271,7 +272,7 @@ static void sink_cb(struct btd_service *service, btd_service_state_t old_state,
break;
case BTD_SERVICE_STATE_CONNECTED:
if (data->sink_timer > 0) {
- g_source_remove(data->sink_timer);
+ timeout_remove(data->sink_timer);
data->sink_timer = 0;
}

@@ -325,7 +326,7 @@ static void hs_cb(struct btd_service *service, btd_service_state_t old_state,
}
}

-static gboolean policy_connect_tg(gpointer user_data)
+static bool policy_connect_tg(gpointer user_data)
{
struct policy_data *data = user_data;
struct btd_service *service;
@@ -343,13 +344,13 @@ static gboolean policy_connect_tg(gpointer user_data)
static void policy_set_tg_timer(struct policy_data *data, int timeout)
{
if (data->tg_timer > 0)
- g_source_remove(data->tg_timer);
+ timeout_remove(data->tg_timer);

- data->tg_timer = g_timeout_add_seconds(timeout, policy_connect_tg,
- data);
+ data->tg_timer = timeout_add_seconds(timeout, policy_connect_tg,
+ data, NULL);
}

-static gboolean policy_connect_source(gpointer user_data)
+static bool policy_connect_source(gpointer user_data)
{
struct policy_data *data = user_data;
struct btd_service *service;
@@ -367,11 +368,11 @@ static gboolean policy_connect_source(gpointer user_data)
static void policy_set_source_timer(struct policy_data *data)
{
if (data->source_timer > 0)
- g_source_remove(data->source_timer);
+ timeout_remove(data->source_timer);

- data->source_timer = g_timeout_add_seconds(SOURCE_RETRY_TIMEOUT,
+ data->source_timer = timeout_add_seconds(SOURCE_RETRY_TIMEOUT,
policy_connect_source,
- data);
+ data, NULL);
}

static void source_cb(struct btd_service *service,
@@ -391,7 +392,7 @@ static void source_cb(struct btd_service *service,
switch (new_state) {
case BTD_SERVICE_STATE_UNAVAILABLE:
if (data->source_timer > 0) {
- g_source_remove(data->source_timer);
+ timeout_remove(data->source_timer);
data->source_timer = 0;
}
break;
@@ -406,13 +407,13 @@ static void source_cb(struct btd_service *service,
data->source_retries = 0;
break;
} else if (data->source_timer > 0) {
- g_source_remove(data->source_timer);
+ timeout_remove(data->source_timer);
data->source_timer = 0;
}
}

if (data->tg_timer > 0) {
- g_source_remove(data->tg_timer);
+ timeout_remove(data->tg_timer);
data->tg_timer = 0;
} else if (btd_service_get_state(target) !=
BTD_SERVICE_STATE_DISCONNECTED)
@@ -422,7 +423,7 @@ static void source_cb(struct btd_service *service,
break;
case BTD_SERVICE_STATE_CONNECTED:
if (data->source_timer > 0) {
- g_source_remove(data->source_timer);
+ timeout_remove(data->source_timer);
data->source_timer = 0;
}

@@ -454,7 +455,7 @@ static void controller_cb(struct btd_service *service,
switch (new_state) {
case BTD_SERVICE_STATE_UNAVAILABLE:
if (data->ct_timer > 0) {
- g_source_remove(data->ct_timer);
+ timeout_remove(data->ct_timer);
data->ct_timer = 0;
}
break;
@@ -470,7 +471,7 @@ static void controller_cb(struct btd_service *service,
data->ct_retries = 0;
break;
} else if (data->ct_timer > 0) {
- g_source_remove(data->ct_timer);
+ timeout_remove(data->ct_timer);
data->ct_timer = 0;
}
} else if (old_state == BTD_SERVICE_STATE_CONNECTED) {
@@ -481,7 +482,7 @@ static void controller_cb(struct btd_service *service,
break;
case BTD_SERVICE_STATE_CONNECTED:
if (data->ct_timer > 0) {
- g_source_remove(data->ct_timer);
+ timeout_remove(data->ct_timer);
data->ct_timer = 0;
}
break;
@@ -504,7 +505,7 @@ static void target_cb(struct btd_service *service,
switch (new_state) {
case BTD_SERVICE_STATE_UNAVAILABLE:
if (data->tg_timer > 0) {
- g_source_remove(data->tg_timer);
+ timeout_remove(data->tg_timer);
data->tg_timer = 0;
}
break;
@@ -520,7 +521,7 @@ static void target_cb(struct btd_service *service,
data->tg_retries = 0;
break;
} else if (data->tg_timer > 0) {
- g_source_remove(data->tg_timer);
+ timeout_remove(data->tg_timer);
data->tg_timer = 0;
}
} else if (old_state == BTD_SERVICE_STATE_CONNECTED) {
@@ -531,7 +532,7 @@ static void target_cb(struct btd_service *service,
break;
case BTD_SERVICE_STATE_CONNECTED:
if (data->tg_timer > 0) {
- g_source_remove(data->tg_timer);
+ timeout_remove(data->tg_timer);
data->tg_timer = 0;
}
break;
@@ -546,7 +547,7 @@ static void reconnect_reset(struct reconnect_data *reconnect)
reconnect->active = false;

if (reconnect->timer > 0) {
- g_source_remove(reconnect->timer);
+ timeout_remove(reconnect->timer);
reconnect->timer = 0;
}
}
@@ -592,7 +593,7 @@ static void reconnect_destroy(gpointer data)
struct reconnect_data *reconnect = data;

if (reconnect->timer > 0)
- g_source_remove(reconnect->timer);
+ timeout_remove(reconnect->timer);

g_slist_free_full(reconnect->services,
(GDestroyNotify) btd_service_unref);
@@ -622,7 +623,7 @@ static void reconnect_remove(struct btd_service *service)
reconnects = g_slist_remove(reconnects, reconnect);

if (reconnect->timer > 0)
- g_source_remove(reconnect->timer);
+ timeout_remove(reconnect->timer);

g_free(reconnect);
}
@@ -693,7 +694,7 @@ static void service_cb(struct btd_service *service,
DBG("Added %s reconnect %u", profile->name, reconnect->reconnect);
}

-static gboolean reconnect_timeout(gpointer data)
+static bool reconnect_timeout(gpointer data)
{
struct reconnect_data *reconnect = data;
int err;
@@ -734,8 +735,8 @@ static void reconnect_set_timer(struct reconnect_data *reconnect, int timeout)
DBG("attempt %u/%zu %d seconds", reconnect->attempt + 1,
reconnect_attempts, timeout);

- reconnect->timer = g_timeout_add_seconds(timeout, reconnect_timeout,
- reconnect);
+ reconnect->timer = timeout_add_seconds(timeout, reconnect_timeout,
+ reconnect, NULL);
}

static void disconnect_cb(struct btd_device *dev, uint8_t reason)
--
2.18.0