core: Use timeout_add_seconds
authorFrédéric Danis <frederic.danis@collabora.com>
Tue, 16 Mar 2021 17:18:34 +0000 (18:18 +0100)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:34 +0000 (19:08 +0530)
Replace calls to g_timeout_add_seconds() by the timeout_add_seconds()
wrapper which takes care of 0 delay.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/adapter.c
src/adv_monitor.c
src/advertising.c
src/device.c
src/main.c
src/sdp-client.c

index 8ffefff..689485e 100644 (file)
@@ -45,6 +45,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"
@@ -303,13 +304,15 @@ 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 */
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        guint le_discovery_idle_timeout;        /* timeout between le discovery runs */
 #endif
-       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 */
@@ -346,13 +349,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 */
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
@@ -1130,7 +1133,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;
 
@@ -1144,7 +1147,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;
        }
 
@@ -1153,8 +1156,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,
@@ -1835,7 +1839,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;
@@ -1863,7 +1867,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;
        }
 
@@ -1907,8 +1911,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,
@@ -2011,7 +2016,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;
        }
 }
@@ -2056,7 +2061,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;
        }
 
@@ -2367,7 +2372,7 @@ static gboolean start_le_discovery_timeout(gpointer user_data)
 }
 #endif
 
-static gboolean start_discovery_timeout(gpointer user_data)
+static bool start_discovery_timeout(gpointer user_data)
 {
        struct btd_adapter *adapter = user_data;
 #ifndef TIZEN_FEATURE_BLUEZ_MODIFY
@@ -2523,7 +2528,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;
        }
 
@@ -2536,8 +2541,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);
 }
 
 #ifndef TIZEN_FEATURE_BLUEZ_MODIFY
@@ -2577,7 +2582,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;
        }
 
@@ -2706,7 +2711,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;
                }
 
@@ -8675,7 +8680,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;
 
@@ -8703,7 +8708,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);
@@ -8780,8 +8785,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,
@@ -10279,26 +10285,26 @@ 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);
+               timeout_remove(adapter->auth_idle_id);
 
        g_queue_foreach(adapter->auths, free_service_auth, NULL);
        g_queue_free(adapter->auths);
@@ -11494,7 +11500,7 @@ uint8_t btd_adapter_get_le_address_type(struct btd_adapter * adapter)
 }
 #endif
 
-static gboolean confirm_name_timeout(gpointer user_data)
+static bool confirm_name_timeout(gpointer user_data)
 {
        struct btd_adapter *adapter = user_data;
 
@@ -11522,7 +11528,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);
@@ -11553,7 +11559,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;
        }
 
@@ -11578,8 +11584,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,
@@ -13472,7 +13479,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;
@@ -13499,7 +13506,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;
        }
 
@@ -13586,8 +13593,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;
 }
index a7c1dad..291b3d1 100644 (file)
@@ -30,6 +30,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"
@@ -124,7 +125,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
                                         */
 };
@@ -1384,7 +1385,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;
        }
 
@@ -1467,7 +1468,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;
@@ -1533,7 +1534,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;
        }
 
@@ -1608,7 +1609,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);
        }
 }
index e1157db..88d96a0 100644 (file)
@@ -27,6 +27,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"
 
@@ -106,10 +107,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);
@@ -569,7 +570,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;
 
@@ -588,7 +589,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;
        }
@@ -599,11 +600,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;
 }
@@ -940,7 +942,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;
 
@@ -960,7 +962,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;
        }
@@ -971,11 +973,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;
 }
@@ -1356,7 +1358,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;
        }
index e356295..3e2f6fd 100644 (file)
@@ -40,6 +40,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"
@@ -262,9 +263,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 */
@@ -960,13 +961,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);
@@ -1993,7 +1994,7 @@ static gboolean dev_property_wake_allowed_exist(
 }
 
 
-static gboolean disconnect_all(gpointer user_data)
+static bool disconnect_all(gpointer user_data)
 {
        struct btd_device *device = user_data;
 
@@ -2018,7 +2019,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);
 
@@ -2168,9 +2169,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)
@@ -5404,7 +5405,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;
        }
 
@@ -5450,7 +5451,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;
        }
 
@@ -6889,7 +6890,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;
 
@@ -6919,11 +6920,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
@@ -7213,12 +7214,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;
        }
 
@@ -8791,7 +8792,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;
        }
 
@@ -8844,7 +8845,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;
        }
 
@@ -8856,9 +8857,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;
        }
 
@@ -9185,7 +9186,7 @@ bool device_is_connectable(struct btd_device *device)
 #endif
 }
 
-static gboolean start_discovery(gpointer user_data)
+static bool start_discovery(gpointer user_data)
 {
        struct btd_device *device = user_data;
 
@@ -9359,7 +9360,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;
                }
 
@@ -9376,10 +9377,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);
                }
        }
 }
@@ -9417,14 +9418,20 @@ 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);
+       else if (dev->discov_timer >0) {
+               timeout_remove(dev->discov_timer);
+               dev->discov_timer = timeout_add_seconds(
+                                               0,
+                                               start_discovery,
+                                               dev, NULL);
        }
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        else if (!dev->browse) {
                DBG("Service is not going on. Start discovery");
-               dev->discov_timer = g_idle_add(start_discovery, dev);
+               dev->discov_timer = timeout_add_seconds(
+                                               0,
+                                               start_discovery,
+                                               dev, NULL);
        } else
                DBG("Wait for service discovery");
 #endif
index fcb3dba..877c935 100755 (executable)
@@ -40,6 +40,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"
@@ -889,7 +890,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;
@@ -904,8 +905,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();
index 55f5bc3..71d3d9e 100755 (executable)
@@ -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);