150a07fd2Sopenharmony_ci/*
250a07fd2Sopenharmony_ci * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
350a07fd2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
450a07fd2Sopenharmony_ci * you may not use this file except in compliance with the License.
550a07fd2Sopenharmony_ci * You may obtain a copy of the License at
650a07fd2Sopenharmony_ci *
750a07fd2Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
850a07fd2Sopenharmony_ci *
950a07fd2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1050a07fd2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1150a07fd2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1250a07fd2Sopenharmony_ci * See the License for the specific language governing permissions and
1350a07fd2Sopenharmony_ci * limitations under the License.
1450a07fd2Sopenharmony_ci */
1550a07fd2Sopenharmony_ci
1650a07fd2Sopenharmony_ci#ifndef OHOS_DAUDIO_HDI_HANDLER_H
1750a07fd2Sopenharmony_ci#define OHOS_DAUDIO_HDI_HANDLER_H
1850a07fd2Sopenharmony_ci
1950a07fd2Sopenharmony_ci#include <map>
2050a07fd2Sopenharmony_ci#include <mutex>
2150a07fd2Sopenharmony_ci#include <set>
2250a07fd2Sopenharmony_ci
2350a07fd2Sopenharmony_ci#include <v2_0/id_audio_callback.h>
2450a07fd2Sopenharmony_ci#include <v2_0/id_audio_manager.h>
2550a07fd2Sopenharmony_ci#include "iremote_object.h"
2650a07fd2Sopenharmony_ci
2750a07fd2Sopenharmony_ci#include "audio_event.h"
2850a07fd2Sopenharmony_ci#include "daudio_manager_callback.h"
2950a07fd2Sopenharmony_ci#include "idaudio_hdi_callback.h"
3050a07fd2Sopenharmony_ci#include "single_instance.h"
3150a07fd2Sopenharmony_ci
3250a07fd2Sopenharmony_cinamespace OHOS {
3350a07fd2Sopenharmony_cinamespace DistributedHardware {
3450a07fd2Sopenharmony_ciusing OHOS::HDI::DistributedAudio::Audioext::V2_0::DAudioEvent;
3550a07fd2Sopenharmony_ciusing OHOS::HDI::DistributedAudio::Audioext::V2_0::IDAudioCallback;
3650a07fd2Sopenharmony_ciusing OHOS::HDI::DistributedAudio::Audioext::V2_0::IDAudioManager;
3750a07fd2Sopenharmony_ciclass DAudioHdiHandler {
3850a07fd2Sopenharmony_ci    DECLARE_SINGLE_INSTANCE_BASE(DAudioHdiHandler);
3950a07fd2Sopenharmony_ci
4050a07fd2Sopenharmony_cipublic:
4150a07fd2Sopenharmony_ci    int32_t InitHdiHandler();
4250a07fd2Sopenharmony_ci
4350a07fd2Sopenharmony_ci    int32_t UninitHdiHandler();
4450a07fd2Sopenharmony_ci
4550a07fd2Sopenharmony_ci    int32_t RegisterAudioDevice(const std::string &devId, const int32_t dhId, const std::string &capability,
4650a07fd2Sopenharmony_ci        const std::shared_ptr<IDAudioHdiCallback> &callbackObjParam);
4750a07fd2Sopenharmony_ci
4850a07fd2Sopenharmony_ci    int32_t UnRegisterAudioDevice(const std::string &devId, const int32_t dhId);
4950a07fd2Sopenharmony_ci
5050a07fd2Sopenharmony_ci    int32_t NotifyEvent(const std::string &devId, const int32_t dhId,
5150a07fd2Sopenharmony_ci        const int32_t streamId, const AudioEvent &audioEvent);
5250a07fd2Sopenharmony_ci
5350a07fd2Sopenharmony_ciprivate:
5450a07fd2Sopenharmony_ci    DAudioHdiHandler();
5550a07fd2Sopenharmony_ci    ~DAudioHdiHandler();
5650a07fd2Sopenharmony_ci    void ProcessEventMsg(const AudioEvent &audioEvent, DAudioEvent &newEvent);
5750a07fd2Sopenharmony_ci
5850a07fd2Sopenharmony_ci    class AudioHdiRecipient : public IRemoteObject::DeathRecipient {
5950a07fd2Sopenharmony_ci    public:
6050a07fd2Sopenharmony_ci        void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
6150a07fd2Sopenharmony_ci    };
6250a07fd2Sopenharmony_ci    sptr<AudioHdiRecipient> audioHdiRecipient_;
6350a07fd2Sopenharmony_ci
6450a07fd2Sopenharmony_ci    const std::string HDF_AUDIO_SERVICE_NAME = "daudio_ext_service";
6550a07fd2Sopenharmony_ci    std::mutex devMapMtx_;
6650a07fd2Sopenharmony_ci    sptr<IDAudioManager> audioSrvHdf_;
6750a07fd2Sopenharmony_ci    std::map<std::string, sptr<DAudioManagerCallback>> mapAudioMgrCallback_;
6850a07fd2Sopenharmony_ci    std::map<std::string, std::set<int32_t>> mapAudioMgrDhIds_;
6950a07fd2Sopenharmony_ci    sptr<IRemoteObject> remote_;
7050a07fd2Sopenharmony_ci};
7150a07fd2Sopenharmony_ci} // DistributedHardware
7250a07fd2Sopenharmony_ci} // OHOS
7350a07fd2Sopenharmony_ci#endif // OHOS_DAUDIO_HDI_HANDLER_H
74