1 /* 2 * Copyright (C) 2019 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 #ifndef _UI_INPUT_INPUTDISPATCHER_CONNECTION_H 18 #define _UI_INPUT_INPUTDISPATCHER_CONNECTION_H 19 20 #include "InputState.h" 21 22 #include <input/InputTransport.h> 23 #include <utils/RefBase.h> 24 #include <deque> 25 26 namespace android::inputdispatcher { 27 28 struct DispatchEntry; 29 30 /* Manages the dispatch state associated with a single input channel. */ 31 class Connection : public RefBase { 32 protected: 33 virtual ~Connection(); 34 35 public: 36 enum class Status { 37 // Everything is peachy. 38 NORMAL, 39 // An unrecoverable communication error has occurred. 40 BROKEN, 41 // The input channel has been unregistered. 42 ZOMBIE, 43 44 ftl_first = NORMAL, 45 ftl_last = ZOMBIE, 46 }; 47 48 Status status; 49 std::shared_ptr<InputChannel> inputChannel; // never null 50 bool monitor; 51 InputPublisher inputPublisher; 52 InputState inputState; 53 54 // True if this connection is responsive. 55 // If this connection is not responsive, avoid publishing more events to it until the 56 // application consumes some of the input. 57 bool responsive = true; 58 59 // Queue of events that need to be published to the connection. 60 std::deque<DispatchEntry*> outboundQueue; 61 62 // Queue of events that have been published to the connection but that have not 63 // yet received a "finished" response from the application. 64 std::deque<DispatchEntry*> waitQueue; 65 66 Connection(const std::shared_ptr<InputChannel>& inputChannel, bool monitor, 67 const IdGenerator& idGenerator); 68 getInputChannelName()69 inline const std::string getInputChannelName() const { return inputChannel->getName(); } 70 71 const std::string getWindowName() const; 72 73 std::deque<DispatchEntry*>::iterator findWaitQueueEntry(uint32_t seq); 74 }; 75 76 } // namespace android::inputdispatcher 77 78 #endif // _UI_INPUT_INPUTDISPATCHER_CONNECTION_H 79