OSDN Git Service

Cache service class updates during bootup
authorAlok Barsode <alok.barsode@azingo.com>
Wed, 29 Jul 2009 07:41:14 +0000 (13:11 +0530)
committerJohan Hedberg <johan.hedberg@nokia.com>
Fri, 31 Jul 2009 21:41:00 +0000 (00:41 +0300)
adapter->svc_cache is used to cache service class updates during
bluetoothd bringup or when adapter is down.adapter_disable_svc_cache() is
used to switch off the cache, so any successive service class updates are
directly written to the device.

src/adapter.c
src/adapter.h
src/main.c

index 908b6a7..572cf5b 100644 (file)
@@ -127,7 +127,9 @@ struct btd_adapter {
 
        gboolean off_requested;         /* DEVDOWN ioctl was called */
 
-       uint8_t svc_cache;              /* For bluetoothd startup */
+       uint8_t svc_cache;              /* Service Class cache */
+       gboolean cache_enable;
+
        gint ref;
 };
 
@@ -1977,6 +1979,7 @@ static int adapter_up(struct btd_adapter *adapter)
        adapter->pairable_timeout = get_pairable_timeout(srcaddr);
        adapter->state = DISCOVER_TYPE_NONE;
        adapter->mode = MODE_CONNECTABLE;
+       adapter->cache_enable = TRUE;
        scan_mode = SCAN_PAGE;
        powered = TRUE;
 
@@ -2042,9 +2045,6 @@ proceed:
 
        }
 
-       if (adapter->svc_cache)
-               adapter_update(adapter, 0);
-
        if (dev_down) {
                adapter_ops->stop(adapter->dev_id);
                adapter->off_requested = TRUE;
@@ -2054,6 +2054,7 @@ proceed:
                                        ADAPTER_INTERFACE, "Powered",
                                        DBUS_TYPE_BOOLEAN, &powered);
 
+       adapter_disable_svc_cache(adapter);
        return 0;
 }
 
@@ -2250,6 +2251,7 @@ int adapter_stop(struct btd_adapter *adapter)
        adapter->scan_mode = SCAN_DISABLED;
        adapter->mode = MODE_OFF;
        adapter->state = DISCOVER_TYPE_NONE;
+       adapter->cache_enable = TRUE;
 
        info("Adapter %s has been disabled", adapter->path);
 
@@ -2259,30 +2261,39 @@ int adapter_stop(struct btd_adapter *adapter)
 int adapter_update(struct btd_adapter *adapter, uint8_t new_svc)
 {
        struct hci_dev *dev = &adapter->dev;
-       uint8_t svclass;
 
        if (dev->ignore)
                return 0;
 
-       if (!adapter->up) {
-               if (new_svc)
-                       adapter->svc_cache = new_svc;
+       if (adapter->cache_enable) {
+               adapter->svc_cache = new_svc;
                return 0;
        }
 
-       if (new_svc)
-               svclass = new_svc;
-       else
-               svclass = adapter->svc_cache;
-
-       if (svclass)
-               set_service_classes(adapter, svclass);
+       set_service_classes(adapter, new_svc);
 
        update_ext_inquiry_response(adapter);
 
        return 0;
 }
 
+void adapter_disable_svc_cache(struct btd_adapter *adapter)
+{
+       if (!adapter)
+               return;
+
+       if (!adapter->cache_enable)
+               return;
+
+       /* Disable and flush svc cache. All successive service class updates
+          will be written to the device */
+       adapter->cache_enable = FALSE;
+
+       set_service_classes(adapter, adapter->svc_cache);
+
+       update_ext_inquiry_response(adapter);
+}
+
 int adapter_get_class(struct btd_adapter *adapter, uint8_t *cls)
 {
        struct hci_dev *dev = &adapter->dev;
@@ -2297,9 +2308,6 @@ int adapter_set_class(struct btd_adapter *adapter, uint8_t *cls)
        struct hci_dev *dev = &adapter->dev;
        uint32_t class;
 
-       if (adapter->svc_cache)
-               adapter->svc_cache = 0;
-
        if (memcmp(dev->class, cls, 3) == 0)
                return 0;
 
index 5ad9ceb..83f987e 100644 (file)
@@ -91,6 +91,8 @@ struct btd_device *adapter_find_device(struct btd_adapter *adapter, const char *
 
 struct btd_device *adapter_find_connection(struct btd_adapter *adapter, uint16_t handle);
 
+void adapter_disable_svc_cache(struct btd_adapter *adapter);
+
 void adapter_remove_device(DBusConnection *conn, struct btd_adapter *adapter,
                                struct btd_device *device);
 struct btd_device *adapter_create_device(DBusConnection *conn,
index c76678c..655bda3 100644 (file)
@@ -433,8 +433,6 @@ int main(int argc, char *argv[])
 
        rfkill_init();
 
-       manager_update_svc(BDADDR_ANY, 0);
-
        debug("Entering main loop");
 
        g_main_loop_run(event_loop);