162b8cbc9Sopenharmony_ci/*
262b8cbc9Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
362b8cbc9Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
462b8cbc9Sopenharmony_ci * you may not use this file except in compliance with the License.
562b8cbc9Sopenharmony_ci * You may obtain a copy of the License at
662b8cbc9Sopenharmony_ci *
762b8cbc9Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
862b8cbc9Sopenharmony_ci *
962b8cbc9Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1062b8cbc9Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1162b8cbc9Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1262b8cbc9Sopenharmony_ci * See the License for the specific language governing permissions and
1362b8cbc9Sopenharmony_ci * limitations under the License.
1462b8cbc9Sopenharmony_ci */
1562b8cbc9Sopenharmony_ci
1662b8cbc9Sopenharmony_ci#ifndef GRAPHIC_LITE_INPUT_EVENT_HUB_H
1762b8cbc9Sopenharmony_ci#define GRAPHIC_LITE_INPUT_EVENT_HUB_H
1862b8cbc9Sopenharmony_ci
1962b8cbc9Sopenharmony_ci#include <map>
2062b8cbc9Sopenharmony_ci#include "gfx_utils/input_event_info.h"
2162b8cbc9Sopenharmony_ci#include "input-event-codes.h"
2262b8cbc9Sopenharmony_ci#include "input_manager.h"
2362b8cbc9Sopenharmony_ci#include "securec.h"
2462b8cbc9Sopenharmony_ci
2562b8cbc9Sopenharmony_cinamespace OHOS {
2662b8cbc9Sopenharmony_ci/**
2762b8cbc9Sopenharmony_ci * @brief Hub of input event.
2862b8cbc9Sopenharmony_ci */
2962b8cbc9Sopenharmony_ciclass InputEventHub {
3062b8cbc9Sopenharmony_ciusing ReadCallback = void (*)(const RawEvent*);
3162b8cbc9Sopenharmony_cipublic:
3262b8cbc9Sopenharmony_ci    static InputEventHub* GetInstance();
3362b8cbc9Sopenharmony_ci
3462b8cbc9Sopenharmony_ci    /**
3562b8cbc9Sopenharmony_ci     * @brief SetUp hub. This operation will open all input devices.
3662b8cbc9Sopenharmony_ci     *
3762b8cbc9Sopenharmony_ci     */
3862b8cbc9Sopenharmony_ci    void SetUp();
3962b8cbc9Sopenharmony_ci
4062b8cbc9Sopenharmony_ci    /**
4162b8cbc9Sopenharmony_ci     * @brief TearDown hub. This operation will close all input devices.
4262b8cbc9Sopenharmony_ci     *
4362b8cbc9Sopenharmony_ci     */
4462b8cbc9Sopenharmony_ci    void TearDown();
4562b8cbc9Sopenharmony_ci
4662b8cbc9Sopenharmony_ci    /**
4762b8cbc9Sopenharmony_ci     * @brief Registration read callback.
4862b8cbc9Sopenharmony_ci     *
4962b8cbc9Sopenharmony_ci     * @param [in] callback callback of read callback.
5062b8cbc9Sopenharmony_ci     *
5162b8cbc9Sopenharmony_ci     * @returns return -1: register callback failed; return 0: register success.
5262b8cbc9Sopenharmony_ci     */
5362b8cbc9Sopenharmony_ci    static int32_t RegisterReadCallback(const ReadCallback &callback)
5462b8cbc9Sopenharmony_ci    {
5562b8cbc9Sopenharmony_ci        if (callback == nullptr) {
5662b8cbc9Sopenharmony_ci            return -1;
5762b8cbc9Sopenharmony_ci        }
5862b8cbc9Sopenharmony_ci        readCallback_ = callback;
5962b8cbc9Sopenharmony_ci        return 0;
6062b8cbc9Sopenharmony_ci    }
6162b8cbc9Sopenharmony_ci
6262b8cbc9Sopenharmony_ciprivate:
6362b8cbc9Sopenharmony_ci    static InputDevType GetDeviceType(uint32_t devIndex);
6462b8cbc9Sopenharmony_ci    static void EventCallback(const InputEventPackage **pkgs, uint32_t count, uint32_t devIndex);
6562b8cbc9Sopenharmony_ci    uint8_t ScanInputDevice();
6662b8cbc9Sopenharmony_ci    InputEventHub();
6762b8cbc9Sopenharmony_ci    ~InputEventHub() {}
6862b8cbc9Sopenharmony_ci
6962b8cbc9Sopenharmony_ci    InputEventHub(const InputEventHub&) = delete;
7062b8cbc9Sopenharmony_ci    InputEventHub& operator=(const InputEventHub&) = delete;
7162b8cbc9Sopenharmony_ci    InputEventHub(InputEventHub&&) = delete;
7262b8cbc9Sopenharmony_ci    InputEventHub& operator=(InputEventHub&&) = delete;
7362b8cbc9Sopenharmony_ci
7462b8cbc9Sopenharmony_ci    uint32_t mountDevIndex_[MAX_INPUT_DEVICE_NUM];
7562b8cbc9Sopenharmony_ci    uint32_t openDev_;
7662b8cbc9Sopenharmony_ci    RawEvent data_;
7762b8cbc9Sopenharmony_ci
7862b8cbc9Sopenharmony_ci    static IInputInterface* inputInterface_;
7962b8cbc9Sopenharmony_ci    static InputEventCb callback_;
8062b8cbc9Sopenharmony_ci    static ReadCallback readCallback_;
8162b8cbc9Sopenharmony_ci};
8262b8cbc9Sopenharmony_ci} // namespace OHOS
8362b8cbc9Sopenharmony_ci#endif
84