Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: device/bluetooth/dbus/bluez_dbus_manager.h

Issue 1347193004: Refactor DBusThreadManager to split away BT clients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef DEVICE_BLUETOOTH_DBUS_BLUEZ_DBUS_MANAGER_H_
6 #define DEVICE_BLUETOOTH_DBUS_BLUEZ_DBUS_MANAGER_H_
7
8 #include <string>
9
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "device/bluetooth/bluetooth_export.h"
14 #include "device/bluetooth/dbus/bluetooth_dbus_client_bundle.h"
15
16 namespace base {
17 class Thread;
18 } // namespace base
19
20 namespace dbus {
21 class Bus;
22 class ObjectPath;
23 } // namespace dbus
24
25 namespace bluez {
26
27 // Style Note: Clients are sorted by names.
28 class BluetoothAdapterClient;
29 class BluetoothAgentManagerClient;
30 class BluetoothDeviceClient;
31 class BluetoothGattCharacteristicClient;
32 class BluetoothGattDescriptorClient;
33 class BluetoothGattManagerClient;
34 class BluetoothGattServiceClient;
35 class BluetoothInputClient;
36 class BluetoothLEAdvertisingManagerClient;
37 class BluetoothMediaClient;
38 class BluetoothMediaTransportClient;
39 class BluetoothProfileManagerClient;
40 class BluezDBusManagerSetter;
41
42 // BluezDBusManager manages manages D-Bus connections and D-Bus clients, which
43 // depend on the D-Bus thread to ensure the right order of shutdowns for
44 // the D-Bus thread, the D-Bus connections, and the D-Bus clients.
45 //
46 // CALLBACKS IN D-BUS CLIENTS:
47 //
48 // D-Bus clients managed by BluezDBusManagerSetter are guaranteed to be deleted
49 // after the D-Bus thread so the clients don't need to worry if new
50 // incoming messages arrive from the D-Bus thread during shutdown of the
51 // clients. The UI message loop is not running during the shutdown hence
52 // the UI message loop won't post tasks to D-BUS clients during the
53 // shutdown. However, to be extra cautious, clients should use
54 // WeakPtrFactory when creating callbacks that run on UI thread. See
55 // session_manager_client.cc for examples.
56 //
57 class DEVICE_BLUETOOTH_EXPORT BluezDBusManager {
58 public:
59 // Sets the global instance. Must be called before any calls to Get().
60 // We explicitly initialize and shut down the global object, rather than
61 // making it a Singleton, to ensure clean startup and shutdown.
62 // This will initialize real or stub DBusClients depending on command-line
63 // arguments and whether this process runs in a ChromeOS environment.
64 static void Initialize(dbus::Bus* bus, bool use_dbus_stub);
65
66 // Returns a BluezDBusManagerSetter instance that allows tests to
67 // replace individual D-Bus clients with their own implementations.
68 // Also initializes the main BluezDBusManager for testing if necessary.
69 static scoped_ptr<BluezDBusManagerSetter> GetSetterForTesting();
70
71 // Returns true if BluezDBusManager has been initialized. Call this to
72 // avoid initializing + shutting down BluezDBusManager more than once.
73 static bool IsInitialized();
74
75 // Destroys the global instance.
76 static void Shutdown();
77
78 // Gets the global instance. Initialize() must be called first.
79 static BluezDBusManager* Get();
80
81 // Returns true if |client| is stubbed.
82 bool IsUsingStub() { return client_bundle_->IsUsingStub(); }
83
84 // Returns various D-Bus bus instances, owned by BluezDBusManager.
85 dbus::Bus* GetSystemBus();
86
87 // All returned objects are owned by BluezDBusManager. Do not use these
88 // pointers after BluezDBusManager has been shut down.
89 BluetoothAdapterClient* GetBluetoothAdapterClient();
90 BluetoothLEAdvertisingManagerClient* GetBluetoothLEAdvertisingManagerClient();
91 BluetoothAgentManagerClient* GetBluetoothAgentManagerClient();
92 BluetoothDeviceClient* GetBluetoothDeviceClient();
93 BluetoothGattCharacteristicClient* GetBluetoothGattCharacteristicClient();
94 BluetoothGattDescriptorClient* GetBluetoothGattDescriptorClient();
95 BluetoothGattManagerClient* GetBluetoothGattManagerClient();
96 BluetoothGattServiceClient* GetBluetoothGattServiceClient();
97 BluetoothInputClient* GetBluetoothInputClient();
98 BluetoothMediaClient* GetBluetoothMediaClient();
99 BluetoothMediaTransportClient* GetBluetoothMediaTransportClient();
100 BluetoothProfileManagerClient* GetBluetoothProfileManagerClient();
101
102 private:
103 friend class BluezDBusManagerSetter;
104
105 // Creates a new BluezDBusManager using the DBusClients set in
106 // |client_bundle|.
107 explicit BluezDBusManager(
108 dbus::Bus* bus,
109 scoped_ptr<BluetoothDBusClientBundle> client_bundle);
110 ~BluezDBusManager();
111
112 // Creates a global instance of BluezDBusManager. Cannot be called more than
113 // once.
114 static void CreateGlobalInstance(dbus::Bus* bus, bool use_stubs);
115
116 // Initializes all currently stored DBusClients with the system bus and
117 // performs additional setup.
118 void InitializeClients();
119
120 dbus::Bus* bus_;
121 scoped_ptr<BluetoothDBusClientBundle> client_bundle_;
122
123 DISALLOW_COPY_AND_ASSIGN(BluezDBusManager);
124 };
125
126 class DEVICE_BLUETOOTH_EXPORT BluezDBusManagerSetter {
127 public:
128 ~BluezDBusManagerSetter();
129
130 void SetBluetoothAdapterClient(scoped_ptr<BluetoothAdapterClient> client);
131 void SetBluetoothLEAdvertisingManagerClient(
132 scoped_ptr<BluetoothLEAdvertisingManagerClient> client);
133 void SetBluetoothAgentManagerClient(
134 scoped_ptr<BluetoothAgentManagerClient> client);
135 void SetBluetoothDeviceClient(scoped_ptr<BluetoothDeviceClient> client);
136 void SetBluetoothGattCharacteristicClient(
137 scoped_ptr<BluetoothGattCharacteristicClient> client);
138 void SetBluetoothGattDescriptorClient(
139 scoped_ptr<BluetoothGattDescriptorClient> client);
140 void SetBluetoothGattManagerClient(
141 scoped_ptr<BluetoothGattManagerClient> client);
142 void SetBluetoothGattServiceClient(
143 scoped_ptr<BluetoothGattServiceClient> client);
144 void SetBluetoothInputClient(scoped_ptr<BluetoothInputClient> client);
145 void SetBluetoothMediaClient(scoped_ptr<BluetoothMediaClient> client);
146 void SetBluetoothMediaTransportClient(
147 scoped_ptr<BluetoothMediaTransportClient> client);
148 void SetBluetoothProfileManagerClient(
149 scoped_ptr<BluetoothProfileManagerClient> client);
150
151 private:
152 friend class BluezDBusManager;
153
154 BluezDBusManagerSetter();
155
156 DISALLOW_COPY_AND_ASSIGN(BluezDBusManagerSetter);
157 };
158
159 } // namespace bluez
160
161 #endif // DEVICE_BLUETOOTH_DBUS_BLUEZ_DBUS_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698