Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 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> |
Siarhei Vishniakou | 1805009 | 2021-09-01 13:32:49 -0700 | [diff] [blame] | 23 | #include <utils/RefBase.h> |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 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: |
Siarhei Vishniakou | f12f2f7 | 2021-11-17 17:49:45 -0800 | [diff] [blame^] | 36 | enum class Status { |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 37 | // Everything is peachy. |
Siarhei Vishniakou | f12f2f7 | 2021-11-17 17:49:45 -0800 | [diff] [blame^] | 38 | NORMAL, |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 39 | // An unrecoverable communication error has occurred. |
Siarhei Vishniakou | f12f2f7 | 2021-11-17 17:49:45 -0800 | [diff] [blame^] | 40 | BROKEN, |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 41 | // The input channel has been unregistered. |
Siarhei Vishniakou | f12f2f7 | 2021-11-17 17:49:45 -0800 | [diff] [blame^] | 42 | ZOMBIE, |
| 43 | |
| 44 | ftl_first = NORMAL, |
| 45 | ftl_last = ZOMBIE, |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | Status status; |
Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 49 | std::shared_ptr<InputChannel> inputChannel; // never null |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 50 | bool monitor; |
| 51 | InputPublisher inputPublisher; |
| 52 | InputState inputState; |
| 53 | |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 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; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 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 | |
Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 66 | Connection(const std::shared_ptr<InputChannel>& inputChannel, bool monitor, |
| 67 | const IdGenerator& idGenerator); |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 68 | |
| 69 | inline const std::string getInputChannelName() const { return inputChannel->getName(); } |
| 70 | |
| 71 | const std::string getWindowName() const; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 72 | |
| 73 | std::deque<DispatchEntry*>::iterator findWaitQueueEntry(uint32_t seq); |
| 74 | }; |
| 75 | |
| 76 | } // namespace android::inputdispatcher |
| 77 | |
| 78 | #endif // _UI_INPUT_INPUTDISPATCHER_CONNECTION_H |