150a07fd2Sopenharmony_ci/*
250a07fd2Sopenharmony_ci * Copyright (c) 2022 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_HDF_OPERATE_H
1750a07fd2Sopenharmony_ci#define OHOS_DAUDIO_HDF_OPERATE_H
1850a07fd2Sopenharmony_ci
1950a07fd2Sopenharmony_ci#include <atomic>
2050a07fd2Sopenharmony_ci#include <condition_variable>
2150a07fd2Sopenharmony_ci#include <mutex>
2250a07fd2Sopenharmony_ci
2350a07fd2Sopenharmony_ci#include "iservstat_listener_hdi.h"
2450a07fd2Sopenharmony_ci#include "idevmgr_hdi.h"
2550a07fd2Sopenharmony_ci#include "iservmgr_hdi.h"
2650a07fd2Sopenharmony_ci#include "single_instance.h"
2750a07fd2Sopenharmony_ci
2850a07fd2Sopenharmony_ciconst std::string AUDIO_SERVICE_NAME = "daudio_primary_service";
2950a07fd2Sopenharmony_ciconst std::string AUDIOEXT_SERVICE_NAME = "daudio_ext_service";
3050a07fd2Sopenharmony_ciconstexpr uint16_t INVALID_VALUE = 0xffff;
3150a07fd2Sopenharmony_ciconstexpr int32_t WAIT_TIME = 5000;
3250a07fd2Sopenharmony_ci
3350a07fd2Sopenharmony_cinamespace OHOS {
3450a07fd2Sopenharmony_cinamespace DistributedHardware {
3550a07fd2Sopenharmony_ciusing OHOS::HDI::DeviceManager::V1_0::IDeviceManager;
3650a07fd2Sopenharmony_ciusing OHOS::HDI::ServiceManager::V1_0::IServiceManager;
3750a07fd2Sopenharmony_ciusing OHOS::HDI::ServiceManager::V1_0::IServStatListener;
3850a07fd2Sopenharmony_ciusing OHOS::HDI::ServiceManager::V1_0::ServiceStatus;
3950a07fd2Sopenharmony_ciusing OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub;
4050a07fd2Sopenharmony_ci
4150a07fd2Sopenharmony_ciclass DaudioHdfOperate {
4250a07fd2Sopenharmony_ciDECLARE_SINGLE_INSTANCE(DaudioHdfOperate);
4350a07fd2Sopenharmony_ci
4450a07fd2Sopenharmony_cipublic:
4550a07fd2Sopenharmony_ci    int32_t LoadDaudioHDFImpl();
4650a07fd2Sopenharmony_ci    int32_t UnLoadDaudioHDFImpl();
4750a07fd2Sopenharmony_ci
4850a07fd2Sopenharmony_ciprivate:
4950a07fd2Sopenharmony_ci    int32_t WaitLoadService(const std::string& servName);
5050a07fd2Sopenharmony_ci
5150a07fd2Sopenharmony_ciprivate:
5250a07fd2Sopenharmony_ci    OHOS::sptr<IDeviceManager> devmgr_;
5350a07fd2Sopenharmony_ci    OHOS::sptr<IServiceManager> servMgr_;
5450a07fd2Sopenharmony_ci    std::atomic<uint16_t> audioServStatus_ = INVALID_VALUE;
5550a07fd2Sopenharmony_ci    std::atomic<uint16_t> audioextServStatus_ = INVALID_VALUE;
5650a07fd2Sopenharmony_ci    std::condition_variable hdfOperateCon_;
5750a07fd2Sopenharmony_ci    std::mutex hdfOperateMutex_;
5850a07fd2Sopenharmony_ci};
5950a07fd2Sopenharmony_ci
6050a07fd2Sopenharmony_ciclass DAudioHdfServStatListener : public OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub {
6150a07fd2Sopenharmony_cipublic:
6250a07fd2Sopenharmony_ci    using StatusCallback = std::function<void(const ServiceStatus &)>;
6350a07fd2Sopenharmony_ci    explicit DAudioHdfServStatListener(StatusCallback callback) : callback_(std::move(callback))
6450a07fd2Sopenharmony_ci    {
6550a07fd2Sopenharmony_ci    }
6650a07fd2Sopenharmony_ci    ~DAudioHdfServStatListener() override = default;
6750a07fd2Sopenharmony_ci    void OnReceive(const ServiceStatus& status) override;
6850a07fd2Sopenharmony_ci
6950a07fd2Sopenharmony_ciprivate:
7050a07fd2Sopenharmony_ci    StatusCallback callback_;
7150a07fd2Sopenharmony_ci};
7250a07fd2Sopenharmony_ci} // namespace DistributedHardware
7350a07fd2Sopenharmony_ci} // namespace OHOS
7450a07fd2Sopenharmony_ci#endif // OHOS_DAUDIO_HDF_OPERATE_H