Chromium Code Reviews| Index: device/bluetooth/dbus/bluez_dbus_manager.h |
| diff --git a/device/bluetooth/dbus/bluez_dbus_manager.h b/device/bluetooth/dbus/bluez_dbus_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..518a807d58c90091937e3492ae283dfa1f0725d1 |
| --- /dev/null |
| +++ b/device/bluetooth/dbus/bluez_dbus_manager.h |
| @@ -0,0 +1,176 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef DEVICE_BLUETOOTH_DBUS_BLUEZ_DBUS_MANAGER_H_ |
| +#define DEVICE_BLUETOOTH_DBUS_BLUEZ_DBUS_MANAGER_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/callback.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "chromeos/chromeos_export.h" |
|
stevenjb
2015/09/17 21:48:01
Use DEVICE_BLUETOOTH_EXPORT
rkc
2015/09/21 18:54:23
Done.
|
| +#include "device/bluetooth/dbus/bluetooth_dbus_client_bundle.h" |
| + |
| +namespace base { |
| +class Thread; |
| +} // namespace base |
| + |
| +namespace dbus { |
| +class Bus; |
| +class ObjectPath; |
| +} // namespace dbus |
| + |
| +namespace bluez { |
| + |
| +// Style Note: Clients are sorted by names. |
| +class BluetoothAdapterClient; |
| +class BluetoothAgentManagerClient; |
| +class BluetoothDeviceClient; |
| +class BluetoothGattCharacteristicClient; |
| +class BluetoothGattDescriptorClient; |
| +class BluetoothGattManagerClient; |
| +class BluetoothGattServiceClient; |
| +class BluetoothInputClient; |
| +class BluetoothLEAdvertisingManagerClient; |
| +class BluetoothMediaClient; |
| +class BluetoothMediaTransportClient; |
| +class BluetoothProfileManagerClient; |
| +class BluezDBusManagerSetter; |
| + |
| +// BluezDBusManagerSetter manages the D-Bus thread, the thread dedicated to |
| +// handling asynchronous D-Bus operations. |
| +// |
| +// This class also manages D-Bus connections and D-Bus clients, which |
| +// depend on the D-Bus thread to ensure the right order of shutdowns for |
| +// the D-Bus thread, the D-Bus connections, and the D-Bus clients. |
| +// |
| +// CALLBACKS IN D-BUS CLIENTS: |
| +// |
| +// D-Bus clients managed by BluezDBusManagerSetter are guaranteed to be deleted |
| +// after the D-Bus thread so the clients don't need to worry if new |
| +// incoming messages arrive from the D-Bus thread during shutdown of the |
| +// clients. The UI message loop is not running during the shutdown hence |
| +// the UI message loop won't post tasks to D-BUS clients during the |
| +// shutdown. However, to be extra cautious, clients should use |
| +// WeakPtrFactory when creating callbacks that run on UI thread. See |
| +// session_manager_client.cc for examples. |
| +// |
| +class CHROMEOS_EXPORT BluezDBusManager { |
| + public: |
| + // Sets the global instance. Must be called before any calls to Get(). |
| + // We explicitly initialize and shut down the global object, rather than |
| + // making it a Singleton, to ensure clean startup and shutdown. |
| + // This will initialize real or stub DBusClients depending on command-line |
| + // arguments and whether this process runs in a ChromeOS environment. |
| + static void Initialize(); |
| + |
| + // Returns a DBusThreadManagerSetter instance that allows tests to |
| + // replace individual D-Bus clients with their own implementations. |
| + // Also initializes the main BluezDBusManager for testing if necessary. |
| + static scoped_ptr<BluezDBusManagerSetter> GetSetterForTesting(); |
| + |
| + // Returns true if BluezDBusManager has been initialized. Call this to |
| + // avoid initializing + shutting down BluezDBusManager more than once. |
| + static bool IsInitialized(); |
| + |
| + // Destroys the global instance. |
| + static void Shutdown(); |
| + |
| + // Gets the global instance. Initialize() must be called first. |
| + static BluezDBusManager* Get(); |
| + |
| + // Returns true if |client| is stubbed. |
| + bool IsUsingStub() { return client_bundle_->IsUsingStub(); } |
| + |
| + // Returns various D-Bus bus instances, owned by BluezDBusManager. |
| + dbus::Bus* GetSystemBus(); |
| + |
| + // All returned objects are owned by BluezDBusManager. Do not use these |
| + // pointers after BluezDBusManager has been shut down. |
| + BluetoothAdapterClient* GetBluetoothAdapterClient(); |
| + BluetoothLEAdvertisingManagerClient* GetBluetoothLEAdvertisingManagerClient(); |
| + BluetoothAgentManagerClient* GetBluetoothAgentManagerClient(); |
| + BluetoothDeviceClient* GetBluetoothDeviceClient(); |
| + BluetoothGattCharacteristicClient* GetBluetoothGattCharacteristicClient(); |
| + BluetoothGattDescriptorClient* GetBluetoothGattDescriptorClient(); |
| + BluetoothGattManagerClient* GetBluetoothGattManagerClient(); |
| + BluetoothGattServiceClient* GetBluetoothGattServiceClient(); |
| + BluetoothInputClient* GetBluetoothInputClient(); |
| + BluetoothMediaClient* GetBluetoothMediaClient(); |
| + BluetoothMediaTransportClient* GetBluetoothMediaTransportClient(); |
| + BluetoothProfileManagerClient* GetBluetoothProfileManagerClient(); |
| + |
| + private: |
| + friend class BluezDBusManagerSetter; |
| + |
| + // Creates a new BluezDBusManager using the DBusClients set in |
| + // |client_bundle|. |
| + explicit BluezDBusManager( |
| + scoped_ptr<BluetoothDBusClientBundle> client_bundle); |
| + ~BluezDBusManager(); |
| + |
| + // Creates a global instance of BluezDBusManager with the real |
| + // implementations for all clients that are listed in |unstub_client_mask| and |
| + // stub implementations for all clients that are not included. Cannot be |
| + // called more than once. |
| + static void CreateGlobalInstance(bool use_stubs); |
| + |
| + // Initialize global thread manager instance with all real dbus client |
| + // implementations. |
| + static void InitializeWithRealClients(); |
| + |
| + // Initialize global thread manager instance with stubbed-out dbus clients |
| + // implementation. |
| + static void InitializeWithStubs(); |
| + |
| + // Initialize with stub implementations for only certain clients that are |
| + // not included in the comma-separated |unstub_clients| list. |
| + static void InitializeWithPartialStub(const std::string& unstub_clients); |
| + |
| + // Initializes all currently stored DBusClients with the system bus and |
| + // performs additional setup. |
| + void InitializeClients(); |
| + |
| + scoped_ptr<BluetoothDBusClientBundle> client_bundle_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BluezDBusManager); |
| +}; |
| + |
| +class CHROMEOS_EXPORT BluezDBusManagerSetter { |
| + public: |
| + ~BluezDBusManagerSetter(); |
| + |
| + void SetBluetoothAdapterClient(scoped_ptr<BluetoothAdapterClient> client); |
| + void SetBluetoothLEAdvertisingManagerClient( |
| + scoped_ptr<BluetoothLEAdvertisingManagerClient> client); |
| + void SetBluetoothAgentManagerClient( |
| + scoped_ptr<BluetoothAgentManagerClient> client); |
| + void SetBluetoothDeviceClient(scoped_ptr<BluetoothDeviceClient> client); |
| + void SetBluetoothGattCharacteristicClient( |
| + scoped_ptr<BluetoothGattCharacteristicClient> client); |
| + void SetBluetoothGattDescriptorClient( |
| + scoped_ptr<BluetoothGattDescriptorClient> client); |
| + void SetBluetoothGattManagerClient( |
| + scoped_ptr<BluetoothGattManagerClient> client); |
| + void SetBluetoothGattServiceClient( |
| + scoped_ptr<BluetoothGattServiceClient> client); |
| + void SetBluetoothInputClient(scoped_ptr<BluetoothInputClient> client); |
| + void SetBluetoothMediaClient(scoped_ptr<BluetoothMediaClient> client); |
| + void SetBluetoothMediaTransportClient( |
| + scoped_ptr<BluetoothMediaTransportClient> client); |
| + void SetBluetoothProfileManagerClient( |
| + scoped_ptr<BluetoothProfileManagerClient> client); |
| + |
| + private: |
| + friend class BluezDBusManager; |
| + |
| + BluezDBusManagerSetter(); |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BluezDBusManagerSetter); |
| +}; |
| + |
| +} // namespace bluez |
| + |
| +#endif // DEVICE_BLUETOOTH_DBUS_BLUEZ_DBUS_MANAGER_H_ |