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 INJECT_THREAD_H
17 #define INJECT_THREAD_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <mutex>
22 #include <thread>
23 #include <vector>
24 
25 #include "v1_0/hid_ddk_types.h"
26 #include "virtual_device.h"
27 
28 namespace OHOS {
29 namespace ExternalDeviceManager {
30 using namespace OHOS::HDI::Input::Ddk::V1_0;
31 class InjectThread {
32 public:
33     InjectThread(std::shared_ptr<VirtualDevice> virtualDevice);
34     virtual ~InjectThread();
35     void WaitFunc(const std::vector<Hid_EmitItem> &items);
36     void Start();
37     void Stop();
38 
39 private:
40     static void RunThread(void *param);
41     void InjectFunc();
42 
43 private:
44     std::mutex mutex_;
45     std::condition_variable conditionVariable_;
46     bool threadRun_;
47     std::vector<Hid_EmitItem> injectQueue_;
48     std::thread thread_;
49     std::shared_ptr<VirtualDevice> virtualDevice_;
50 };
51 } // namespace ExternalDeviceManager
52 } // namespace OHOS
53 #endif // INJECT_THREAD_H