• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_STATE_BASE_H
17 #define DISTRIBUTED_INPUT_STATE_BASE_H
18 
19 #include <map>
20 #include <mutex>
21 #include <string>
22 #include <linux/input.h>
23 
24 namespace OHOS {
25 namespace DistributedHardware {
26 namespace DistributedInput {
27 /*
28  * This enumeration class represents the two states of the peropheral:
29  * THROUGH_IN : The state indicates the peripheral takes effect on the local device.
30  * THROUGH_OUT : The state indicates that the peripheral takes effect at the remote device.
31 */
32 enum class DhidState {
33     THROUGH_IN = 0,
34     THROUGH_OUT,
35 };
36 
37 class DInputState {
38 public:
GetInstance()39     static DInputState &GetInstance()
40     {
41         static DInputState instance;
42         return instance;
43     };
44 
45     int32_t Init();
46     int32_t Release();
47     int32_t RecordDhids(const std::vector<std::string> &dhids, DhidState state, const int32_t &sessionId);
48     int32_t RemoveDhids(const std::vector<std::string> &dhids);
49     DhidState GetStateByDhid(std::string &dhid);
50 
51 private:
52     ~DInputState();
53 
54     void CreateSpecialEventInjectThread(const int32_t &sessionId, const std::vector<std::string> &dhids);
55     void CheckKeyboardState(std::string &dhid, std::string &keyboardNodePath,
56         std::vector<uint32_t> &keyboardPressedKeys, int &fd);
57     void SpecEventInject(const int32_t &sessionId, std::vector<std::string> dhids);
58     void RecordEventLog(const input_event &event);
59     void WriteEventToDev(int &fd, const input_event &event);
60     void CheckMouseKeyState(const int32_t &sessionId, const std::string &mouseNodePath,
61         const std::string &mouseNodeDhId);
62 
63 private:
64     std::mutex operationMutex_;
65     std::map<std::string, DhidState> dhidStateMap_;
66 };
67 } // namespace DistributedInput
68 } // namespace DistributedHardware
69 } // namespace OHOS
70 #endif // DISTRIBUTED_INPUT_STATE_BASE_H