1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <memory> 20 #include <vector> 21 22 #include "common/libs/utils/result.h" 23 24 namespace cuttlefish { 25 26 struct MultitouchSlot { 27 int32_t id; 28 int32_t x; 29 int32_t y; 30 }; 31 32 // The InputConnector encapsulates the components required to interact with the 33 // Android VM. In order to send input events to the guest an EventSink must be 34 // instantiated. The event sink should be destroyed when it is known no more 35 // events will be delivered through it. Multiple event sinks can exist at the 36 // same time and used concurrently. 37 class InputConnector { 38 public: 39 class EventSink { 40 public: 41 virtual ~EventSink() = default; 42 virtual Result<void> SendTouchEvent(const std::string& display, int x, 43 int y, bool down) = 0; 44 virtual Result<void> SendMultiTouchEvent( 45 const std::string& device_label, 46 const std::vector<MultitouchSlot>& slots, bool down) = 0; 47 virtual Result<void> SendKeyboardEvent(uint16_t code, bool down) = 0; 48 virtual Result<void> SendRotaryEvent(int pixels) = 0; 49 virtual Result<void> SendSwitchesEvent(uint16_t code, bool state) = 0; 50 }; 51 52 virtual ~InputConnector() = default; 53 54 virtual std::unique_ptr<EventSink> CreateSink() = 0; 55 }; 56 57 } // namespace cuttlefish 58