1/*
2 * Copyright (c) 2020-2021 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 GRAPHIC_LITE_INPUT_DEVICE_H
17#define GRAPHIC_LITE_INPUT_DEVICE_H
18
19#include "gfx_utils/input_event_info.h"
20#include "gfx_utils/heap_base.h"
21
22namespace OHOS {
23/**
24 * @brief Input device base class.
25 */
26class InputDevice : public HeapBase {
27public:
28    InputDevice() : rawDataState_(STATE_RELEASE) {}
29    virtual ~InputDevice() {}
30
31    /**
32     * @brief Process event from input device driver.
33     */
34    void ProcessEvent();
35
36    /**
37     * @brief Read data from hardware.User should override this to set data
38     *
39     * @param [out] input device data.
40     *
41     * @returns no more data to read if true.
42     */
43    virtual bool Read(DeviceData& data) = 0;
44
45    constexpr static uint8_t STATE_RELEASE = 0;
46    constexpr static uint8_t STATE_PRESS = 1;
47
48    virtual void OnViewLifeEvent() {}
49
50protected:
51    uint16_t rawDataState_;
52
53    /**
54     * @brief Dispatch event to ui component.
55     * @param [in] data data received from hardware
56     */
57    virtual void DispatchEvent(const DeviceData& data) = 0;
58};
59} // namespace OHOS
60#endif // GRAPHIC_LITE_INPUT_DEVICE_H
61