1/*
2 * Copyright (c) 2023 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#include "touchpad_event_fragment.h"
17
18namespace OHOS {
19namespace DistributedHardware {
20namespace DistributedInput {
21namespace {
22    constexpr size_t MIN_EVENT_FRAG_SIZE = 2;
23}
24bool TouchPadEventFragment::IsShouldDrop()
25{
26    return events.size() == MIN_EVENT_FRAG_SIZE;
27}
28
29bool TouchPadEventFragment::IsTouchPadOptFinish() const
30{
31    bool isFinish = false;
32    for (const auto &ev : events) {
33        if (ev.type == EV_KEY && ev.code == BTN_TOUCH && ev.value == KEY_UP_STATE) {
34            isFinish = true;
35            break;
36        }
37    }
38
39    return isFinish;
40}
41
42bool TouchPadEventFragment::IsTouchPadOptStart() const
43{
44    bool isStart = false;
45    for (const auto &ev : events) {
46        if (ev.type == EV_KEY && ev.code == BTN_TOUCH && ev.value == KEY_DOWN_STATE) {
47            isStart = true;
48            break;
49        }
50    }
51
52    return isStart;
53}
54
55void TouchPadEventFragment::PushEvent(const RawEvent &event)
56{
57    this->events.push_back(event);
58}
59
60std::vector<RawEvent> TouchPadEventFragment::GetEvents()
61{
62    return this->events;
63}
64} // namespace DistributedInput
65} // namespace DistributedHardware
66} // namespace OHOS