• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 OH_INPUT_INTERCEPTOR_H
17 #define OH_INPUT_INTERCEPTOR_H
18 
19 #include <mutex>
20 
21 #include "i_input_event_consumer.h"
22 
23 namespace OHOS {
24 namespace MMI {
25 typedef enum {
26     INTERCEPTOR_TYPE_KEY,
27     INTERCEPTOR_TYPE_POINTER
28 } OHInterceptorType;
29 
30 class OHInputInterceptor final : public IInputEventConsumer, public std::enable_shared_from_this<OHInputInterceptor> {
31 public:
32     OHInputInterceptor() = default;
33     DISALLOW_COPY_AND_MOVE(OHInputInterceptor);
34     ~OHInputInterceptor() override = default;
35 
36     int32_t Start(OHInterceptorType type);
37     int32_t Stop(OHInterceptorType type);
38     void SetCallback(std::function<void(std::shared_ptr<PointerEvent>)> callback);
39     void SetCallback(std::function<void(std::shared_ptr<KeyEvent>)> callback);
40     void OnInputEvent(std::shared_ptr<KeyEvent> keyEvent) const override;
41     void OnInputEvent(std::shared_ptr<PointerEvent> pointerEvent) const override;
42     void OnInputEvent(std::shared_ptr<AxisEvent> axisEvent) const override;
43 
44 private:
45     std::function<void(std::shared_ptr<KeyEvent>)> keyCallback_;
46     std::function<void(std::shared_ptr<PointerEvent>)> pointerCallback_;
47     int32_t keyInterceptorId_ { -1 };
48     int32_t pointerInterceptorId_ { -1 };
49     mutable std::mutex mutex_;
50 };
51 }
52 }
53 #endif