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

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, 2 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
« no previous file with comments | « device/bluetooth/dbus/bluez_dbus_client.h ('k') | device/bluetooth/dbus/bluez_dbus_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 dbus {
17 class Bus;
18 class ObjectPath;
19 } // namespace dbus
20
21 namespace bluez {
22
23 // Style Note: Clients are sorted by names.
24 class BluetoothAdapterClient;
25 class BluetoothAgentManagerClient;
26 class BluetoothDeviceClient;
27 class BluetoothGattCharacteristicClient;
28 class BluetoothGattDescriptorClient;
29 class BluetoothGattManagerClient;
30 class BluetoothGattServiceClient;
31 class BluetoothInputClient;
32 class BluetoothLEAdvertisingManagerClient;
33 class BluetoothMediaClient;
34 class BluetoothMediaTransportClient;
35 class BluetoothProfileManagerClient;
36 class BluezDBusManagerSetter;
37
38 // BluezDBusManager manages manages D-Bus connections and D-Bus clients, which
39 // depend on the D-Bus thread to ensure the right order of shutdowns for
40 // the D-Bus thread, the D-Bus connections, and the D-Bus clients.
41 //
42 // CALLBACKS IN D-BUS CLIENTS:
43 //
44 // D-Bus clients managed by BluezDBusManagerSetter are guaranteed to be deleted
45 // after the D-Bus thread so the clients don't need to worry if new
46 // incoming messages arrive from the D-Bus thread during shutdown of the
47 // clients. The UI message loop is not running during the shutdown hence
48 // the UI message loop won't post tasks to D-BUS clients during the
49 // shutdown. However, to be extra cautious, clients should use
50 // WeakPtrFactory when creating callbacks that run on UI thread. See
51 // session_manager_client.cc for examples.
52 //
53 class DEVICE_BLUETOOTH_EXPORT BluezDBusManager {
54 public:
55 // Sets the global instance. Must be called before any calls to Get().
56 // We explicitly initialize and shut down the global object, rather than
57 // making it a Singleton, to ensure clean startup and shutdown.
58 // This will initialize real or stub DBusClients depending on command-line
59 // arguments and whether this process runs in a ChromeOS environment.
60 static void Initialize(dbus::Bus* bus, bool use_dbus_stub);
61
62 // Returns a BluezDBusManagerSetter instance that allows tests to
63 // replace individual D-Bus clients with their own implementations.
64 // Also initializes the main BluezDBusManager for testing if necessary.
65 static scoped_ptr<BluezDBusManagerSetter> GetSetterForTesting();
66
67 // Returns true if BluezDBusManager has been initialized. Call this to
68 // avoid initializing + shutting down BluezDBusManager more than once.
69 static bool IsInitialized();
70
71 // Destroys the global instance.
72 static void Shutdown();
73
74 // Gets the global instance. Initialize() must be called first.
75 static BluezDBusManager* Get();
76
77 // Returns true if |client| is stubbed.
78 bool IsUsingStub() { return client_bundle_->IsUsingStub(); }
79
80 // Returns various D-Bus bus instances, owned by BluezDBusManager.
81 dbus::Bus* GetSystemBus();
82
83 // All returned objects are owned by BluezDBusManager. Do not use these
84 // pointers after BluezDBusManager has been shut down.
85 BluetoothAdapterClient* GetBluetoothAdapterClient();
86 BluetoothLEAdvertisingManagerClient* GetBluetoothLEAdvertisingManagerClient();
87 BluetoothAgentManagerClient* GetBluetoothAgentManagerClient();
88 BluetoothDeviceClient* GetBluetoothDeviceClient();
89 BluetoothGattCharacteristicClient* GetBluetoothGattCharacteristicClient();
90 BluetoothGattDescriptorClient* GetBluetoothGattDescriptorClient();
91 BluetoothGattManagerClient* GetBluetoothGattManagerClient();
92 BluetoothGattServiceClient* GetBluetoothGattServiceClient();
93 BluetoothInputClient* GetBluetoothInputClient();
94 BluetoothMediaClient* GetBluetoothMediaClient();
95 BluetoothMediaTransportClient* GetBluetoothMediaTransportClient();
96 BluetoothProfileManagerClient* GetBluetoothProfileManagerClient();
97
98 private:
99 friend class BluezDBusManagerSetter;
100
101 // Creates a new BluezDBusManager using the DBusClients set in
102 // |client_bundle|.
103 explicit BluezDBusManager(
104 dbus::Bus* bus,
105 scoped_ptr<BluetoothDBusClientBundle> client_bundle);
106 ~BluezDBusManager();
107
108 // Creates a global instance of BluezDBusManager. Cannot be called more than
109 // once.
110 static void CreateGlobalInstance(dbus::Bus* bus, bool use_stubs);
111
112 // Initializes all currently stored DBusClients with the system bus and
113 // performs additional setup.
114 void InitializeClients();
115
116 dbus::Bus* bus_;
117 scoped_ptr<BluetoothDBusClientBundle> client_bundle_;
118
119 DISALLOW_COPY_AND_ASSIGN(BluezDBusManager);
120 };
121
122 class DEVICE_BLUETOOTH_EXPORT BluezDBusManagerSetter {
123 public:
124 ~BluezDBusManagerSetter();
125
126 void SetBluetoothAdapterClient(scoped_ptr<BluetoothAdapterClient> client);
127 void SetBluetoothLEAdvertisingManagerClient(
128 scoped_ptr<BluetoothLEAdvertisingManagerClient> client);
129 void SetBluetoothAgentManagerClient(
130 scoped_ptr<BluetoothAgentManagerClient> client);
131 void SetBluetoothDeviceClient(scoped_ptr<BluetoothDeviceClient> client);
132 void SetBluetoothGattCharacteristicClient(
133 scoped_ptr<BluetoothGattCharacteristicClient> client);
134 void SetBluetoothGattDescriptorClient(
135 scoped_ptr<BluetoothGattDescriptorClient> client);
136 void SetBluetoothGattManagerClient(
137 scoped_ptr<BluetoothGattManagerClient> client);
138 void SetBluetoothGattServiceClient(
139 scoped_ptr<BluetoothGattServiceClient> client);
140 void SetBluetoothInputClient(scoped_ptr<BluetoothInputClient> client);
141 void SetBluetoothMediaClient(scoped_ptr<BluetoothMediaClient> client);
142 void SetBluetoothMediaTransportClient(
143 scoped_ptr<BluetoothMediaTransportClient> client);
144 void SetBluetoothProfileManagerClient(
145 scoped_ptr<BluetoothProfileManagerClient> client);
146
147 private:
148 friend class BluezDBusManager;
149
150 BluezDBusManagerSetter();
151
152 DISALLOW_COPY_AND_ASSIGN(BluezDBusManagerSetter);
153 };
154
155 } // namespace bluez
156
157 #endif // DEVICE_BLUETOOTH_DBUS_BLUEZ_DBUS_MANAGER_H_
OLDNEW
« no previous file with comments | « device/bluetooth/dbus/bluez_dbus_client.h ('k') | device/bluetooth/dbus/bluez_dbus_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698