• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_INJECT_H
17 #define DISTRIBUTED_INPUT_INJECT_H
18 
19 #include <mutex>
20 #include <set>
21 #include <string>
22 
23 #include "constants_dinput.h"
24 #include "distributed_input_handler.h"
25 #include "distributed_input_node_manager.h"
26 #include "i_input_node_listener.h"
27 
28 namespace OHOS {
29 namespace DistributedHardware {
30 namespace DistributedInput {
31 class DistributedInputInject {
32 public:
33     static DistributedInputInject &GetInstance();
34     int32_t RegisterDistributedHardware(const std::string &devId, const std::string &dhId,
35         const std::string &parameters);
36     int32_t UnregisterDistributedHardware(const std::string &devId, const std::string &dhId);
37     int32_t RegisterDistributedEvent(RawEvent *buffer, size_t bufferSize);
38     int32_t StructTransJson(const InputDevice &pBuf, std::string &strDescriptor);
39     void StartInjectThread();
40     void StopInjectThread();
41     std::string GenerateVirtualTouchScreenDHId(const uint64_t sourceWinId, const uint32_t sourceWinWidth,
42         const uint32_t sourceWinHeight);
43     int32_t CreateVirtualTouchScreenNode(const std::string &devId, const std::string &dhId, const uint64_t srcWinId,
44         const uint32_t sourcePhyWidth, const uint32_t sourcePhyHeight);
45     int32_t RemoveVirtualTouchScreenNode(const std::string &dhId);
46     int32_t GetVirtualTouchScreenFd();
47     int32_t RegisterInputNodeListener(sptr<InputNodeListener> listener);
48     int32_t UnregisterInputNodeListener(sptr<InputNodeListener> listener);
49     int32_t GetDhIdsByInputType(const std::string &devId, const uint32_t &inputTypes, std::vector<std::string> &dhIds);
50 
51     void NotifyNodeMgrScanVirNode(const std::string &dhId);
52     void InputDeviceEventInject(const std::shared_ptr<RawEvent> &rawEvent);
53     void SyncNodeOfflineInfo(const std::string &srcDevId, const std::string &sinkDevId, const std::string &sinkNodeId);
54     void SyncNodeOnlineInfo(const std::string &srcDevId, const std::string &sinkDevId, const std::string &sinkNodeId,
55         const std::string &sinkNodeDesc);
56     void GetVirtualKeyboardPathsByDhIds(const std::vector<std::string> &dhIds,
57         std::vector<std::string> &shareDhidsPaths, std::vector<std::string> &shareDhIds);
58 
59 private:
60     DistributedInputInject();
61     ~DistributedInputInject();
62 
63     std::unique_ptr<DistributedInputNodeManager> inputNodeManager_;
64     std::mutex inputNodeManagerMutex_;
65     std::set<sptr<InputNodeListener>> inputNodeListeners_;
66     std::mutex inputNodeListenersMutex_;
67 };
68 } // namespace DistributedInput
69 } // namespace DistributedHardware
70 } // namespace OHOS
71 
72 #endif // DISTRIBUTED_INPUT_INJECT_H