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