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_SOURCE_HANDLER_H
17 #define OHOS_DAUDIO_SOURCE_HANDLER_H
18 
19 #include "daudio_ipc_callback.h"
20 #include "idaudio_source.h"
21 #include "idistributed_hardware_source.h"
22 #include "single_instance.h"
23 
24 namespace OHOS {
25 namespace DistributedHardware {
26 class DAudioSourceHandler : public IDistributedHardwareSource {
27 DECLARE_SINGLE_INSTANCE_BASE(DAudioSourceHandler);
28 
29 public:
30     int32_t InitSource(const std::string &params) override;
31     int32_t ReleaseSource() override;
32     int32_t RegisterDistributedHardware(const std::string &devId, const std::string &dhId, const EnableParam &param,
33         std::shared_ptr<RegisterCallback> callback) override;
34     int32_t UnregisterDistributedHardware(const std::string &devId, const std::string &dhId,
35         std::shared_ptr<UnregisterCallback> callback) override;
36     int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId, const std::string &key,
37         const std::string &value) override;
38     void RegisterDistributedHardwareStateListener(std::shared_ptr<DistributedHardwareStateListener> listener) override;
39     void UnregisterDistributedHardwareStateListener() override;
40     void RegisterDataSyncTriggerListener(std::shared_ptr<DataSyncTriggerListener> listener) override;
41     void UnregisterDataSyncTriggerListener() override;
42     void OnRemoteSourceSvrDied(const wptr<IRemoteObject> &remote);
43     void FinishStartSA(const std::string &param, const sptr<IRemoteObject> &remoteObject);
44 
45 private:
46     class DAudioSourceSvrRecipient : public IRemoteObject::DeathRecipient {
47     public:
48         void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
49     };
50 
51     DAudioSourceHandler();
52     ~DAudioSourceHandler();
53 
54     std::mutex sourceProxyMutex_;
55     std::condition_variable sourceProxyConVar_;
56     sptr<IDAudioSource> dAudioSourceProxy_ = nullptr;
57     sptr<DAudioIpcCallback> dAudioIpcCallback_ = nullptr;
58     sptr<DAudioSourceSvrRecipient> sourceSvrRecipient_ = nullptr;
59 };
60 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 __attribute__((visibility("default"))) IDistributedHardwareSource *GetSourceHardwareHandler();
65 #ifdef __cplusplus
66 }
67 #endif
68 } // namespace DistributedHardware
69 } // namespace OHOS
70 #endif // OHOS_DAUDIO_SOURCE_HANDLER_H