ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / device / bluetooth / bluetooth_audio_sink_chromeos.h
blob58d1fb2fee932852dbe410e65ee2e2cd2598ed1a
1 // Copyright 2015 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.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_AUDIO_SINK_CHROMEOS_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_AUDIO_SINK_CHROMEOS_H_
8 #include <stdint.h>
9 #include <string>
10 #include <vector>
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/observer_list.h"
15 #include "chromeos/dbus/bluetooth_media_client.h"
16 #include "chromeos/dbus/bluetooth_media_endpoint_service_provider.h"
17 #include "chromeos/dbus/bluetooth_media_transport_client.h"
18 #include "dbus/file_descriptor.h"
19 #include "dbus/object_path.h"
20 #include "device/bluetooth/bluetooth_adapter.h"
21 #include "device/bluetooth/bluetooth_audio_sink.h"
22 #include "device/bluetooth/bluetooth_export.h"
24 namespace chromeos {
26 class BluetoothAudioSinkChromeOSTest;
28 class DEVICE_BLUETOOTH_EXPORT BluetoothAudioSinkChromeOS
29 : public device::BluetoothAudioSink,
30 public device::BluetoothAdapter::Observer,
31 public BluetoothMediaClient::Observer,
32 public BluetoothMediaTransportClient::Observer,
33 public BluetoothMediaEndpointServiceProvider::Delegate {
34 public:
35 explicit BluetoothAudioSinkChromeOS(
36 scoped_refptr<device::BluetoothAdapter> adapter);
38 // device::BluetoothAudioSink overrides.
39 // Unregisters a BluetoothAudioSink. |callback| should handle
40 // the clean-up after the audio sink is deleted successfully, otherwise
41 // |error_callback| will be called.
42 void Unregister(
43 const base::Closure& callback,
44 const device::BluetoothAudioSink::ErrorCallback& error_callback) override;
45 void AddObserver(BluetoothAudioSink::Observer* observer) override;
46 void RemoveObserver(BluetoothAudioSink::Observer* observer) override;
47 device::BluetoothAudioSink::State GetState() const override;
48 uint16_t GetVolume() const override;
50 // device::BluetoothAdapter::Observer overrides.
51 void AdapterPresentChanged(device::BluetoothAdapter* adapter,
52 bool present) override;
53 void AdapterPoweredChanged(device::BluetoothAdapter* adapter,
54 bool powered) override;
56 // BluetoothMediaClient::Observer overrides.
57 void MediaRemoved(const dbus::ObjectPath& object_path) override;
59 // BluetoothMediaTransportClient::Observer overrides.
60 void MediaTransportRemoved(const dbus::ObjectPath& object_path) override;
61 void MediaTransportPropertyChanged(const dbus::ObjectPath& object_path,
62 const std::string& property_name) override;
64 // BluetoothMediaEndpointServiceProvider::Delegate overrides.
65 void SetConfiguration(const dbus::ObjectPath& transport_path,
66 const TransportProperties& properties) override;
67 void SelectConfiguration(
68 const std::vector<uint8_t>& capabilities,
69 const SelectConfigurationCallback& callback) override;
70 void ClearConfiguration(const dbus::ObjectPath& transport_path) override;
71 void Released() override;
73 // Registers a BluetoothAudioSink. User applications can use |options| to
74 // configure the audio sink. |callback| will be executed if the audio sink is
75 // successfully registered, otherwise |error_callback| will be called. Called
76 // by BluetoothAdapterChromeOS.
77 void Register(
78 const device::BluetoothAudioSink::Options& options,
79 const base::Closure& callback,
80 const device::BluetoothAudioSink::ErrorCallback& error_callback);
82 // Returns a pointer to the media endpoint object. This function should be
83 // used for testing purpose only.
84 BluetoothMediaEndpointServiceProvider* GetEndpointServiceProvider();
86 private:
87 ~BluetoothAudioSinkChromeOS() override;
89 // Called when the state property of BluetoothMediaTransport has been updated.
90 void StateChanged(device::BluetoothAudioSink::State state);
92 // Called when the volume property of BluetoothMediaTransport has been
93 // updated.
94 void VolumeChanged(uint16_t volume);
96 // Called when the registration of Media Endpoint has succeeded.
97 void OnRegisterSucceeded(const base::Closure& callback);
99 // Called when the registration of Media Endpoint failed.
100 void OnRegisterFailed(
101 const device::BluetoothAudioSink::ErrorCallback& error_callback,
102 const std::string& error_name,
103 const std::string& error_message);
105 // Called when the unregistration of Media Endpoint has succeeded. The
106 // clean-up of media, media transport and media endpoint will be handled here.
107 void OnUnregisterSucceeded(const base::Closure& callback);
109 // Called when the unregistration of Media Endpoint failed.
110 void OnUnregisterFailed(
111 const device::BluetoothAudioSink::ErrorCallback& error_callback,
112 const std::string& error_name,
113 const std::string& error_message);
115 // Reads from the file descriptor acquired via Media Transport object and
116 // notify |observer_| while the audio data is available.
117 void ReadFromFD();
119 // Helper functions to clean up media, media transport and media endpoint.
120 // Called when the |state_| changes to either STATE_INVALID or
121 // STATE_DISCONNECTED.
122 void ResetMedia();
123 void ResetTransport();
124 void ResetEndpoint();
126 // The connection state between the BluetoothAudioSinkChromeOS and the remote
127 // device.
128 device::BluetoothAudioSink::State state_;
130 // The volume control by the remote device during the streaming. The valid
131 // range of volume is 0-127, and 128 is used to represent invalid volume.
132 uint16_t volume_;
134 // Read MTU of the file descriptor acquired via Media Transport object.
135 scoped_ptr<uint16_t> read_mtu_;
137 // Write MTU of the file descriptor acquired via Media Transport object.
138 scoped_ptr<uint16_t> write_mtu_;
140 // File descriptor acquired via Media Transport object.
141 dbus::FileDescriptor fd_;
143 // Object path of the media object being used.
144 dbus::ObjectPath media_path_;
146 // Object path of the transport object being used.
147 dbus::ObjectPath transport_path_;
149 // Object path of the media endpoint object being used.
150 dbus::ObjectPath endpoint_path_;
152 // BT adapter which the audio sink binds to. |adapter_| should outlive
153 // a BluetoothAudioSinkChromeOS object.
154 scoped_refptr<device::BluetoothAdapter> adapter_;
156 // Options used to initiate Media Endpoint and select configuration for the
157 // transport.
158 device::BluetoothAudioSink::Options options_;
160 // Media Endpoint object owned by the audio sink object.
161 scoped_ptr<BluetoothMediaEndpointServiceProvider> media_endpoint_;
163 // List of observers interested in event notifications from us. Objects in
164 // |observers_| are expected to outlive a BluetoothAudioSinkChromeOS object.
165 ObserverList<BluetoothAudioSink::Observer> observers_;
167 // Note: This should remain the last member so it'll be destroyed and
168 // invalidate its weak pointers before any other members are destroyed.
169 base::WeakPtrFactory<BluetoothAudioSinkChromeOS> weak_ptr_factory_;
171 DISALLOW_COPY_AND_ASSIGN(BluetoothAudioSinkChromeOS);
174 } // namespace chromeos
176 #endif // DEVICE_BLUETOOTH_BLUETOOTH_AUDIO_SINK_CHROMEOS_H_