1 /* 2 * Copyright (c) 2022 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_HDI_HANDLER_H 17 #define OHOS_DAUDIO_HDI_HANDLER_H 18 19 #include <map> 20 #include <mutex> 21 #include <set> 22 23 #include <v1_0/id_audio_callback.h> 24 #include <v1_0/id_audio_manager.h> 25 #include "iremote_object.h" 26 27 #include "audio_event.h" 28 #include "daudio_manager_callback.h" 29 #include "idaudio_hdi_callback.h" 30 #include "single_instance.h" 31 32 namespace OHOS { 33 namespace DistributedHardware { 34 using OHOS::HDI::DistributedAudio::Audioext::V1_0::DAudioEvent; 35 using OHOS::HDI::DistributedAudio::Audioext::V1_0::IDAudioCallback; 36 using OHOS::HDI::DistributedAudio::Audioext::V1_0::IDAudioManager; 37 class DAudioHdiHandler { 38 DECLARE_SINGLE_INSTANCE_BASE(DAudioHdiHandler); 39 40 public: 41 int32_t InitHdiHandler(); 42 43 int32_t UninitHdiHandler(); 44 45 int32_t RegisterAudioDevice(const std::string &devId, const int32_t dhId, const std::string &capability, 46 const std::shared_ptr<IDAudioHdiCallback> &callbackObjParam); 47 48 int32_t UnRegisterAudioDevice(const std::string &devId, const int32_t dhId); 49 50 int32_t NotifyEvent(const std::string &devId, const int32_t dhId, const AudioEvent &audioEvent); 51 52 private: 53 DAudioHdiHandler(); 54 ~DAudioHdiHandler(); 55 void ProcessEventMsg(const AudioEvent &audioEvent, DAudioEvent &newEvent); 56 57 class AudioHdiRecipient : public IRemoteObject::DeathRecipient { 58 public: 59 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 60 }; 61 sptr<AudioHdiRecipient> audioHdiRecipient_; 62 63 const std::string HDF_AUDIO_SERVICE_NAME = "daudio_ext_service"; 64 std::mutex devMapMtx_; 65 sptr<IDAudioManager> audioSrvHdf_; 66 std::map<std::string, sptr<DAudioManagerCallback>> mapAudioMgrCallback_; 67 std::map<std::string, std::set<int32_t>> mapAudioMgrDhIds_; 68 sptr<IRemoteObject> remote_; 69 }; 70 } // DistributedHardware 71 } // OHOS 72 #endif // OHOS_DAUDIO_HDI_HANDLER_H 73