blob: 33556313ff15fdbbcf2df8e29b384c1eae934803 [file] [log] [blame]
Cody Schuffelen134ff032019-11-22 00:25:32 -08001#pragma once
2/*
3 * Copyright (C) 2017 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include <memory>
19
20#include "common/vsoc/lib/typed_region_view.h"
21#include "common/vsoc/shm/input_events_layout.h"
22#include "uapi/vsoc_shm.h"
23
24namespace vsoc {
25namespace input_events {
26
27struct InputEvent {
28 uint16_t type;
29 uint16_t code;
30 uint32_t value;
31};
32
33class InputEventsRegionView
34 : public vsoc::TypedRegionView<
35 InputEventsRegionView,
36 vsoc::layout::input_events::InputEventsLayout> {
37 public:
38 static const int kMaxEventsPerPacket;
39 // Generates a touch event, may returns true if successful, false if there was
40 // an error, most likely that the queue is full.
41 bool HandleSingleTouchEvent(bool down, int x, int y);
42 bool HandlePowerButtonEvent(bool down);
43 bool HandleKeyboardEvent(bool down, uint16_t key_code);
44
45 // TODO(jemoreira): HandleMultiTouchEvent()...
46
47 // Read input events from the queue, waits if there are none available.
48 // Returns the number of events read or a negative value in case of an error
49 // (most likely the next packet in the queue is larger than the buffer
50 // provided).
51 intptr_t GetScreenEventsOrWait(InputEvent* buffer, int max_event_count);
52 intptr_t GetKeyboardEventsOrWait(InputEvent* buffer, int max_event_count);
53 intptr_t GetPowerButtonEventsOrWait(InputEvent* buffer, int max_event_count);
54
55};
56} // namespace input_events
57} // namespace vsoc