1 // Copyright (C) 2020 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 #define LOG_TAG "audio_proxy_client"
16 
17 #include <utils/Log.h>
18 
19 #include "AudioProxyManager.h"
20 #include "public/audio_proxy.h"
21 
22 namespace {
23 class AudioProxyImpl {
24  public:
25   static AudioProxyImpl* getInstance();
26 
27   bool registerDevice(audio_proxy_device_t* device);
28 
29  private:
30   AudioProxyImpl();
31   ~AudioProxyImpl() = default;
32 
33   std::unique_ptr<audio_proxy::AudioProxyManager> mManager;
34 };
35 
AudioProxyImpl()36 AudioProxyImpl::AudioProxyImpl() {
37   mManager = audio_proxy::V5_0::createAudioProxyManager();
38   ALOGE_IF(!mManager, "Failed to create audio proxy manager");
39 }
40 
registerDevice(audio_proxy_device_t * device)41 bool AudioProxyImpl::registerDevice(audio_proxy_device_t* device) {
42   return mManager && mManager->registerDevice(device);
43 }
44 
45 // static
getInstance()46 AudioProxyImpl* AudioProxyImpl::getInstance() {
47   static AudioProxyImpl instance;
48   return &instance;
49 }
50 
51 }  // namespace
52 
audio_proxy_register_device(audio_proxy_device_t * device)53 extern "C" int audio_proxy_register_device(audio_proxy_device_t* device) {
54   return AudioProxyImpl::getInstance()->registerDevice(device) ? 0 : -1;
55 }
56