1 // Copyright 2016 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 
16 // Callback object to be passed to brilloaudioservice.
17 
18 #ifndef BRILLO_AUDIO_AUDIOSERVICE_AUDIO_SERVICE_CALLBACK_H_
19 #define BRILLO_AUDIO_AUDIOSERVICE_AUDIO_SERVICE_CALLBACK_H_
20 
21 #include <vector>
22 
23 #include <base/callback.h>
24 #include <binder/Status.h>
25 
26 #include "android/brillo/brilloaudioservice/BnAudioServiceCallback.h"
27 #include "include/brillo_audio_manager.h"
28 
29 using android::binder::Status;
30 using android::brillo::brilloaudioservice::BnAudioServiceCallback;
31 
32 namespace brillo {
33 
34 class AudioServiceCallback : public BnAudioServiceCallback {
35  public:
36   // Constructor for AudioServiceCallback.
37   //
38   // |callback| is an object of type BAudioCallback.
39   // |user_data| is an object to be passed to the callbacks.
40   AudioServiceCallback(const BAudioCallback* callback, void* user_data);
41 
42   // Callback function triggered when a device is connected.
43   //
44   // |devices| is a vector of audio_devices_t.
45   Status OnAudioDevicesConnected(const std::vector<int>& devices);
46 
47   // Callback function triggered when a device is disconnected.
48   //
49   // |devices| is a vector of audio_devices_t.
50   Status OnAudioDevicesDisconnected(const std::vector<int>& devices);
51 
52   // Callback function triggered when volume is changed.
53   //
54   // |stream| is an int representing the stream.
55   // |previous_index| is the volume index before the key press.
56   // |current_index| is the volume index after the key press.
57   Status OnVolumeChanged(int stream, int previous_index, int current_index);
58 
59   // Method to compare two AudioServiceCallback objects.
60   //
61   // |callback| is a ref counted pointer to a AudioServiceCallback object to be
62   // compared with this.
63   //
64   // Returns true if |callback| equals this.
65   bool Equals(const android::sp<AudioServiceCallback>& callback);
66 
67  private:
68   // Callback when devices are connected.
69   base::Callback<void(const BAudioDeviceInfo*, void*)> connected_callback_;
70   // Callback when devices are disconnected.
71   base::Callback<void(const BAudioDeviceInfo*, void*)> disconnected_callback_;
72   // Callback when the volume button is pressed.
73   base::Callback<void(BAudioUsage, int, int, void*)> volume_callback_;
74   // User data passed to the callbacks.
75   void* user_data_;
76 };
77 
78 }  // namespace brillo
79 
80 #endif  // BRILLO_AUDIO_AUDIOSERVICE_AUDIO_SERVICE_CALLBACK_H_
81