• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 DISTRIBUTED_INPUT_ADAPTER_H
17 #define DISTRIBUTED_INPUT_ADAPTER_H
18 
19 #include <functional>
20 #include <map>
21 
22 #include <string>
23 #include <vector>
24 
25 #include "distributed_input_kit.h"
26 #include "i_start_stop_d_inputs_call_back.h"
27 #include "nocopyable.h"
28 #include "prepare_d_input_call_back_stub.h"
29 #include "simulation_event_listener_stub.h"
30 #include "singleton.h"
31 #include "start_d_input_call_back_stub.h"
32 #include "start_stop_d_inputs_call_back_stub.h"
33 #include "start_stop_result_call_back_stub.h"
34 #include "stop_d_input_call_back_stub.h"
35 #include "unprepare_d_input_call_back_stub.h"
36 
37 namespace OHOS {
38 namespace Msdp {
39 namespace DeviceStatus {
40 class DistributedInputAdapter final {
41     DECLARE_DELAYED_SINGLETON(DistributedInputAdapter);
42 public:
43     using DInputCallback = std::function<void(bool)>;
44     using SimulateEventCallback = std::function<void(uint32_t type, uint32_t code, int32_t value)>;
45     DISALLOW_COPY_AND_MOVE(DistributedInputAdapter);
46 
47     bool IsNeedFilterOut(const std::string &deviceId,
48                          const DistributedHardware::DistributedInput::BusinessEvent &event);
49 
50     int32_t StartRemoteInput(const std::string &remoteNetworkId, const std::string &originNetworkId,
51                              const std::vector<std::string> &inputDeviceDhids, DInputCallback callback);
52     int32_t StopRemoteInput(const std::string &remoteNetworkId, const std::string &originNetworkId,
53                             const std::vector<std::string> &inputDeviceDhids, DInputCallback callback);
54 
55     int32_t StopRemoteInput(const std::string &originNetworkId,
56                             const std::vector<std::string> &inputDeviceDhids, DInputCallback callback);
57 
58     int32_t PrepareRemoteInput(const std::string &remoteNetworkId, const std::string &originNetworkId,
59                                DInputCallback callback);
60     int32_t UnPrepareRemoteInput(const std::string &remoteNetworkId, const std::string &originNetworkId,
61                                  DInputCallback callback);
62 
63     int32_t PrepareRemoteInput(const std::string &deviceId, DInputCallback callback);
64     int32_t UnPrepareRemoteInput(const std::string &deviceId, DInputCallback callback);
65 
66 private:
67     enum class CallbackType {
68         StartDInputCallback,
69         StartDInputCallbackDHIds,
70         StartDInputCallbackSink,
71         StopDInputCallback,
72         StopDInputCallbackDHIds,
73         StopDInputCallbackSink,
74         PrepareStartDInputCallback,
75         UnPrepareStopDInputCallback,
76         PrepareStartDInputCallbackSink,
77         UnPrepareStopDInputCallbackSink
78     };
79 
80     struct TimerInfo {
81         int32_t times { 0 };
82         int32_t timerId { 0 };
83     };
84 
85     class StartDInputCallback final : public DistributedHardware::DistributedInput::StartDInputCallbackStub {
86     public:
87         void OnResult(const std::string &devId, const uint32_t &inputTypes, const int32_t &status) override;
88     };
89 
90     class StopDInputCallback final : public DistributedHardware::DistributedInput::StopDInputCallbackStub {
91     public:
92         void OnResult(const std::string &devId, const uint32_t &inputTypes, const int32_t &status) override;
93     };
94 
95     class StartDInputCallbackDHIds final :
96         public DistributedHardware::DistributedInput::StartStopDInputsCallbackStub {
97     public:
98         void OnResultDhids(const std::string &devId, const int32_t &status) override;
99     };
100 
101     class StopDInputCallbackDHIds final :
102         public DistributedHardware::DistributedInput::StartStopDInputsCallbackStub {
103     public:
104         void OnResultDhids(const std::string &devId, const int32_t &status) override;
105     };
106 
107     class StartDInputCallbackSink final :
108         public DistributedHardware::DistributedInput::StartStopDInputsCallbackStub {
109     public:
110         void OnResultDhids(const std::string &devId, const int32_t &status) override;
111     };
112 
113     class StopDInputCallbackSink final :
114         public DistributedHardware::DistributedInput::StartStopDInputsCallbackStub {
115     public:
116         void OnResultDhids(const std::string &devId, const int32_t &status) override;
117     };
118 
119     class PrepareStartDInputCallback final :
120         public DistributedHardware::DistributedInput::PrepareDInputCallbackStub {
121     public:
122         void OnResult(const std::string &devId, const int32_t &status) override;
123     };
124 
125     class UnPrepareStopDInputCallback final :
126         public DistributedHardware::DistributedInput::UnprepareDInputCallbackStub {
127     public:
128         void OnResult(const std::string &devId, const int32_t &status) override;
129     };
130 
131     class PrepareStartDInputCallbackSink final :
132         public DistributedHardware::DistributedInput::PrepareDInputCallbackStub {
133     public:
134         void OnResult(const std::string &devId, const int32_t &status) override;
135     };
136 
137     class UnPrepareStopDInputCallbackSink final :
138         public DistributedHardware::DistributedInput::UnprepareDInputCallbackStub {
139     public:
140         void OnResult(const std::string &devId, const int32_t &status) override;
141     };
142 
143     void SaveCallback(CallbackType type, DInputCallback callback);
144     void AddTimer(const CallbackType &type);
145     void RemoveTimer(const CallbackType &type);
146     void ProcessDInputCallback(CallbackType type, int32_t status);
147     std::map<CallbackType, TimerInfo> watchingMap_;
148     std::map<CallbackType, DInputCallback> callbackMap_;
149     std::mutex adapterLock_;
150 };
151 
152 #define D_INPUT_ADAPTER OHOS::DelayedSingleton<DistributedInputAdapter>::GetInstance()
153 } // namespace DeviceStatus
154 } // namespace Msdp
155 } // namespace OHOS
156 
157 #endif // DISTRIBUTED_INPUT_ADAPTER_H
158