• 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 #include "inject_thread.h"
17 
18 namespace OHOS {
19 namespace MMI {
20 std::mutex InjectThread::mutex_;
21 std::condition_variable InjectThread::conditionVariable_;
22 std::vector<InjectInputEvent> InjectThread::injectQueue_;
23 
InjectFunc() const24 void InjectThread::InjectFunc() const
25 {
26     std::unique_lock<std::mutex> uniqueLock(mutex_);
27     while (true) {
28         conditionVariable_.wait(uniqueLock);
29         while (injectQueue_.size() > 0) {
30             if (injectQueue_[0].deviceId == TOUCH_SCREEN_DEVICE_ID) {
31                 g_pTouchScreen->EmitEvent(injectQueue_[0].type, injectQueue_[0].code, injectQueue_[0].value);
32             } else if (injectQueue_[0].deviceId == KEYBOARD_DEVICE_ID) {
33                 g_pKeyboard->EmitEvent(injectQueue_[0].type, injectQueue_[0].code, injectQueue_[0].value);
34             }
35             injectQueue_.erase(injectQueue_.begin());
36         }
37     }
38 }
39 
WaitFunc(InjectInputEvent injectInputEvent) const40 void InjectThread::WaitFunc(InjectInputEvent injectInputEvent) const
41 {
42     std::lock_guard<std::mutex> lockGuard(mutex_);
43     injectQueue_.push_back(injectInputEvent);
44     conditionVariable_.notify_one();
45 }
46 } // namespace MMI
47 } // namespace OHOS