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_DISTRIBUTER_H
1762b8cbc9Sopenharmony_ci#define GRAPHIC_LITE_INPUT_EVENT_DISTRIBUTER_H
1862b8cbc9Sopenharmony_ci
1962b8cbc9Sopenharmony_ci#include <set>
2062b8cbc9Sopenharmony_ci#include "gfx_utils/input_event_info.h"
2162b8cbc9Sopenharmony_ci
2262b8cbc9Sopenharmony_cinamespace OHOS {
2362b8cbc9Sopenharmony_ci/**
2462b8cbc9Sopenharmony_ci * @brief Distributer distribute all input events to specific window.
2562b8cbc9Sopenharmony_ci */
2662b8cbc9Sopenharmony_ciclass InputEventDistributer {
2762b8cbc9Sopenharmony_cipublic:
2862b8cbc9Sopenharmony_ci    InputEventDistributer() {}
2962b8cbc9Sopenharmony_ci    ~InputEventDistributer() {}
3062b8cbc9Sopenharmony_ci
3162b8cbc9Sopenharmony_ci    /**
3262b8cbc9Sopenharmony_ci     * @brief Distribute input events.
3362b8cbc9Sopenharmony_ci     *
3462b8cbc9Sopenharmony_ci     * @param [in] events events waiting for distribution.
3562b8cbc9Sopenharmony_ci     * @param [in] size total size of events.
3662b8cbc9Sopenharmony_ci     *
3762b8cbc9Sopenharmony_ci     */
3862b8cbc9Sopenharmony_ci    void Distribute(const RawEvent* events, int32_t size);
3962b8cbc9Sopenharmony_ci
4062b8cbc9Sopenharmony_ci    /**
4162b8cbc9Sopenharmony_ci     * @brief Listener of raw event.
4262b8cbc9Sopenharmony_ci    */
4362b8cbc9Sopenharmony_ci    class RawEventListener {
4462b8cbc9Sopenharmony_ci    public:
4562b8cbc9Sopenharmony_ci        virtual void OnRawEvent(const RawEvent& event) = 0;
4662b8cbc9Sopenharmony_ci    };
4762b8cbc9Sopenharmony_ci
4862b8cbc9Sopenharmony_ci    /**
4962b8cbc9Sopenharmony_ci     * @brief Add a raw event listener.
5062b8cbc9Sopenharmony_ci     *
5162b8cbc9Sopenharmony_ci     * @param listener raw event listener.
5262b8cbc9Sopenharmony_ci     */
5362b8cbc9Sopenharmony_ci    void AddRawEventListener(RawEventListener* listener)
5462b8cbc9Sopenharmony_ci    {
5562b8cbc9Sopenharmony_ci        if (listener == nullptr) {
5662b8cbc9Sopenharmony_ci            return;
5762b8cbc9Sopenharmony_ci        }
5862b8cbc9Sopenharmony_ci        rawEventListeners_.insert(listener);
5962b8cbc9Sopenharmony_ci    }
6062b8cbc9Sopenharmony_ci
6162b8cbc9Sopenharmony_ci    /**
6262b8cbc9Sopenharmony_ci     * @brief Remove a raw event listener.
6362b8cbc9Sopenharmony_ci     *
6462b8cbc9Sopenharmony_ci     * @param listener raw event listener.
6562b8cbc9Sopenharmony_ci     */
6662b8cbc9Sopenharmony_ci    void RemoveRawEventListener(RawEventListener* listener)
6762b8cbc9Sopenharmony_ci    {
6862b8cbc9Sopenharmony_ci        if (listener == nullptr) {
6962b8cbc9Sopenharmony_ci            return;
7062b8cbc9Sopenharmony_ci        }
7162b8cbc9Sopenharmony_ci        rawEventListeners_.erase(listener);
7262b8cbc9Sopenharmony_ci    }
7362b8cbc9Sopenharmony_ciprivate:
7462b8cbc9Sopenharmony_ci    std::set<RawEventListener*> rawEventListeners_;
7562b8cbc9Sopenharmony_ci};
7662b8cbc9Sopenharmony_ci} // namespace OHOS
7762b8cbc9Sopenharmony_ci#endif // GRAPHIC_LITE_INPUT_EVENT_DISTRIBUTER_H