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