1 /*
2  * Copyright (c) 2022-2024 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_DSCREEN_SOURCE_HANDLER_H
17 #define OHOS_DSCREEN_SOURCE_HANDLER_H
18 
19 #include <condition_variable>
20 #include <cstdint>
21 #include <memory>
22 #include <mutex>
23 
24 #include "iremote_object.h"
25 #include "refbase.h"
26 
27 #include "dscreen_source_callback.h"
28 #include "idscreen_source.h"
29 #include "idistributed_hardware_source.h"
30 #include "single_instance.h"
31 
32 namespace OHOS {
33 namespace DistributedHardware {
34 class DScreenSourceHandler : public IDistributedHardwareSource {
35 DECLARE_SINGLE_INSTANCE_BASE(DScreenSourceHandler);
36 public:
37     int32_t InitSource(const std::string &params) override;
38     int32_t ReleaseSource() override;
39     int32_t RegisterDistributedHardware(const std::string &devId, const std::string &dhId,
40         const EnableParam &param, std::shared_ptr<RegisterCallback> callback) override;
41     int32_t UnregisterDistributedHardware(const std::string &devId, const std::string &dhId,
42         std::shared_ptr<UnregisterCallback> callback) override;
43     int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId,
44         const std::string &key, const std::string &value) override;
45     void RegisterDistributedHardwareStateListener(std::shared_ptr<DistributedHardwareStateListener> listener) override;
46     void UnregisterDistributedHardwareStateListener() override;
47     void RegisterDataSyncTriggerListener(std::shared_ptr<DataSyncTriggerListener> listener) override;
48     void UnregisterDataSyncTriggerListener() override;
49     void OnRemoteSourceSvrDied(const wptr<IRemoteObject> &remote);
50     void FinishStartSA(const std::string &params, const sptr<IRemoteObject> &remoteObject);
51 private:
52     class DScreenSourceSvrRecipient : public IRemoteObject::DeathRecipient {
53     public:
54         void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
55     };
56 
57     DScreenSourceHandler();
58     ~DScreenSourceHandler() = default;
59     std::mutex proxyMutex_;
60     std::condition_variable proxyConVar_;
61     sptr<IDScreenSource> dScreenSourceProxy_ = nullptr;
62     sptr<DScreenSourceCallback> dScreenSourceCallback_ = nullptr;
63     sptr<DScreenSourceSvrRecipient> sourceSvrRecipient_ = nullptr;
64 };
65 
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69 __attribute__((visibility("default"))) IDistributedHardwareSource *GetSourceHardwareHandler();
70 #ifdef __cplusplus
71 }
72 #endif
73 }  // namespace DistributedHardware
74 }  // namespace OHOS
75 #endif