• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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 OHOS_DAUDIO_MANAGER_INTERDFACE_IMPL_H
17 #define OHOS_DAUDIO_MANAGER_INTERDFACE_IMPL_H
18 
19 #include <mutex>
20 
21 #include <v2_1/id_audio_manager.h>
22 
23 #include "audio_manager_interface_impl.h"
24 
25 namespace OHOS {
26 namespace HDI {
27 namespace DistributedAudio {
28 namespace Audioext {
29 namespace V2_1 {
30 using OHOS::HDI::DistributedAudio::Audioext::V2_1::DAudioEvent;
31 
32 class DAudioManagerInterfaceImpl : public IDAudioManager {
33 public:
GetDAudioManager()34     static DAudioManagerInterfaceImpl *GetDAudioManager()
35     {
36         if (dAudioMgr_ == nullptr) {
37             std::unique_lock<std::mutex> mgr_mutex(mgrMtx_);
38             if (dAudioMgr_ == nullptr) {
39                 dAudioMgr_ = new DAudioManagerInterfaceImpl();
40             }
41         }
42         return dAudioMgr_;
43     }
44 
45     ~DAudioManagerInterfaceImpl() override;
46 
47     int32_t RegisterAudioDevice(const std::string &adpName, int32_t devId, const std::string &capability,
48         const sptr<IDAudioCallback> &callbackObj) override;
49 
50     int32_t UnRegisterAudioDevice(const std::string &adpName, int32_t devId) override;
51 
52     int32_t NotifyEvent(const std::string &adpName, int32_t devId, int32_t streamId, const DAudioEvent &event) override;
53 
54     int32_t RegisterAudioHdfListener(const std::string &serviceName,
55         const sptr<IDAudioHdfCallback> &callbackObj) override;
56 
57     int32_t UnRegisterAudioHdfListener(const std::string &serviceName) override;
58 
59 private:
60     DAudioManagerInterfaceImpl();
61 
62     DAudioManagerInterfaceImpl(const DAudioManagerInterfaceImpl &);
63 
64     DAudioManagerInterfaceImpl &operator = (const DAudioManagerInterfaceImpl &);
65 
66 private:
67     class Deletor {
68     public:
~Deletor()69         ~Deletor()
70         {
71             if (DAudioManagerInterfaceImpl::dAudioMgr_ != nullptr) {
72                 delete DAudioManagerInterfaceImpl::dAudioMgr_;
73             }
74         };
75     };
76     static Deletor deletor;
77 
78 private:
79     OHOS::HDI::DistributedAudio::Audio::V1_0::AudioManagerInterfaceImpl *audioMgr_;
80     static DAudioManagerInterfaceImpl *dAudioMgr_;
81     static std::mutex mgrMtx_;
82 };
83 } // V2_1
84 } // AudioExt
85 } // Distributedaudio
86 } // HDI
87 } // OHOS
88 #endif // OHOS_DAUDIO_MANAGER_INTERDFACE_IMPL_H
89