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 #ifndef BRILLO_AUDIO_AUDIOSERVICE_BRILLO_AUDIO_SERVICE_IMPL_H_ 17 #define BRILLO_AUDIO_AUDIOSERVICE_BRILLO_AUDIO_SERVICE_IMPL_H_ 18 19 // Server side implementation of brillo audio service. 20 21 #include "brillo_audio_service.h" 22 23 namespace brillo { 24 25 class BrilloAudioServiceImpl : public BrilloAudioService { 26 public: 27 ~BrilloAudioServiceImpl() = default; 28 29 // From AIDL. 30 Status GetDevices(int flag, std::vector<int>* _aidl_return) override; 31 Status SetDevice(int usage, int config) override; 32 Status GetMaxVolumeSteps(int stream, int* _aidl_return) override; 33 Status SetMaxVolumeSteps(int stream, int max_steps) override; 34 Status SetVolumeIndex(int stream, int device, int index) override; 35 Status GetVolumeIndex(int stream, int device, int* _aidl_return) override; 36 Status GetVolumeControlStream(int* _aidl_return) override; 37 Status SetVolumeControlStream(int stream) override; 38 Status IncrementVolume() override; 39 Status DecrementVolume() override; 40 Status RegisterServiceCallback( 41 const android::sp<IAudioServiceCallback>& callback) override; 42 Status UnregisterServiceCallback( 43 const android::sp<IAudioServiceCallback>& callback) override; 44 45 // Register daemon handlers. 46 // 47 // |audio_device_handler| is a weak pointer to an audio device handler object. 48 // |audio_volume_handler| is a weak pointer to an audio volume handler object. 49 void RegisterHandlers( 50 std::weak_ptr<AudioDeviceHandler> audio_device_handler, 51 std::weak_ptr<AudioVolumeHandler> audio_volume_handler) override; 52 53 // Callback to be called when a device is connected. 54 // 55 // |devices| is a vector of ints representing the audio_devices_t. 56 void OnDevicesConnected(const std::vector<int>& device) override; 57 58 // Callback to be called when a device is disconnected. 59 // 60 // |devices| is a vector of ints representing the audio_devices_t. 61 void OnDevicesDisconnected(const std::vector<int>& device) override; 62 63 // Callback to be called when volume is changed. 64 // 65 // |stream| is an int representing the stream. 66 // |previous_index| is the volume index before the key press. 67 // |current_index| is the volume index after the key press. 68 void OnVolumeChanged(audio_stream_type_t stream, 69 int previous_index, 70 int current_index) override; 71 72 private: 73 // A weak pointer to the audio device handler. 74 std::weak_ptr<AudioDeviceHandler> audio_device_handler_; 75 // A weak pointer to the audio volume handler. 76 std::weak_ptr<AudioVolumeHandler> audio_volume_handler_; 77 // List of all callbacks objects registered with the service. 78 std::set<android::sp<IAudioServiceCallback> > callbacks_set_; 79 }; 80 81 } // namespace brillo 82 83 #endif // BRILLO_AUDIO_AUDIOSERVICE_BRILLO_AUDIO_SERVICE_IMPL_H_ 84