1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
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 I_AUDIO_DEVICE_MANAGER_H
17 #define I_AUDIO_DEVICE_MANAGER_H
18 
19 #include <map>
20 #include <mutex>
21 
22 #include <v1_0/iaudio_manager.h>
23 
24 #include "i_audio_device_adapter.h"
25 
26 using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioAdapterDescriptor;
27 
28 namespace OHOS {
29 namespace AudioStandard {
30 class IAudioDeviceManager {
31 public:
32     IAudioDeviceManager() = default;
33     virtual ~IAudioDeviceManager() = default;
34 
35     virtual int32_t GetAllAdapters() = 0;
36     virtual struct AudioAdapterDescriptor *GetTargetAdapterDesc(const std::string &adapterName, bool isMmap) = 0;
37     virtual std::shared_ptr<IAudioDeviceAdapter> LoadAdapters(const std::string &adapterName, bool isMmap) = 0;
38     virtual int32_t UnloadAdapter(const std::string &adapterName) = 0;
39     virtual int32_t Release() = 0;
40 };
41 
42 class AudioDeviceManagerFactory {
43 public:
44     static AudioDeviceManagerFactory &GetInstance();
45     std::shared_ptr<IAudioDeviceManager> CreatDeviceManager(const AudioDeviceManagerType audioMgrType);
46     int32_t DestoryDeviceManager(const AudioDeviceManagerType audioMgrType);
47 
48 private:
49     AudioDeviceManagerFactory() = default;
50     ~AudioDeviceManagerFactory() = default;
51 
52     AudioDeviceManagerFactory(const AudioDeviceManagerFactory &) = delete;
53     AudioDeviceManagerFactory &operator=(const AudioDeviceManagerFactory &) = delete;
54     AudioDeviceManagerFactory(AudioDeviceManagerFactory &&) = delete;
55     AudioDeviceManagerFactory &operator=(AudioDeviceManagerFactory &&) = delete;
56 
57     std::shared_ptr<IAudioDeviceManager> InitLocalAudioMgr();
58     std::shared_ptr<IAudioDeviceManager> InitRemoteAudioMgr();
59     std::shared_ptr<IAudioDeviceManager> InitBluetoothAudioMgr();
60 
61 private:
62     std::mutex devMgrFactoryMtx_;
63     std::map<AudioDeviceManagerType, std::shared_ptr<IAudioDeviceManager>> allHdiDevMgr_;
64 };
65 }  // namespace AudioStandard
66 }  // namespace OHOS
67 #endif // I_AUDIO_DEVICE_MANAGER_H