• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 INJECT_THREAD_H
17 #define INJECT_THREAD_H
18 
19 #include "virtual_keyboard.h"
20 #include "virtual_touch_screen.h"
21 
22 #include <condition_variable>
23 #include <mutex>
24 #include <vector>
25 
26 namespace OHOS {
27 namespace MMIS {
28 extern std::unique_ptr<VirtualTouchScreen> g_pTouchScreen;
29 extern std::unique_ptr<VirtualKeyboard> g_pKeyboard;
30 
31 struct InjectInputEvent {
32     int32_t deviceId;
33     int32_t type;
34     int32_t code;
35     int32_t value;
36 };
37 
38 class InjectThread {
39 public:
40     InjectThread() = default;
41     virtual ~InjectThread() = default;
42     void InjectFunc() const;
43     void WaitFunc(InjectInputEvent injectInputEvent) const;
44     static constexpr int32_t TOUCH_SCREEN_DEVICE_ID = 1;
45     static constexpr int32_t KEYBOARD_DEVICE_ID = 2;
46 
47 private:
48     static std::mutex mutex_;
49     static std::condition_variable conditionVariable_;
50     static std::vector<InjectInputEvent> injectQueue_;
51 };
52 } // namespace MMIS
53 } // namespace OHOS
54 
55 #endif  // INJECT_THREAD_H