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