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 #include <android-base/logging.h>
16 
17 #include "AudioProxyManager.h"
18 #include "public/audio_proxy.h"
19 
20 namespace {
21 class AudioProxyImpl {
22  public:
23   static AudioProxyImpl* getInstance();
24 
25   bool registerDevice(audio_proxy_device_t* device);
26 
27  private:
28   AudioProxyImpl();
29   ~AudioProxyImpl() = default;
30 
31   std::unique_ptr<audio_proxy::AudioProxyManager> mManager;
32 };
33 
AudioProxyImpl()34 AudioProxyImpl::AudioProxyImpl()
35     : mManager(audio_proxy::createAudioProxyManager()) {
36   DCHECK(mManager);
37 }
38 
registerDevice(audio_proxy_device_t * device)39 bool AudioProxyImpl::registerDevice(audio_proxy_device_t* device) {
40   return mManager->registerDevice(device);
41 }
42 
43 // static
getInstance()44 AudioProxyImpl* AudioProxyImpl::getInstance() {
45   static AudioProxyImpl instance;
46   return &instance;
47 }
48 
49 }  // namespace
50 
audio_proxy_register_device(audio_proxy_device_t * device)51 extern "C" int audio_proxy_register_device(audio_proxy_device_t* device) {
52   return AudioProxyImpl::getInstance()->registerDevice(device) ? 0 : -1;
53 }