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 | |
Prabir Pradhan | 4810866 | 2022-09-09 21:22:04 +0000 | [diff] [blame] | 17 | #pragma once |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 18 | |
| 19 | #include "InputState.h" |
| 20 | |
| 21 | #include <input/InputTransport.h> |
Siarhei Vishniakou | 1805009 | 2021-09-01 13:32:49 -0700 | [diff] [blame] | 22 | #include <utils/RefBase.h> |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 23 | #include <deque> |
| 24 | |
| 25 | namespace android::inputdispatcher { |
| 26 | |
| 27 | struct DispatchEntry; |
| 28 | |
| 29 | /* Manages the dispatch state associated with a single input channel. */ |
Siarhei Vishniakou | 1069fa8 | 2023-04-19 12:14:39 -0700 | [diff] [blame] | 30 | class Connection { |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 31 | public: |
Siarhei Vishniakou | f12f2f7 | 2021-11-17 17:49:45 -0800 | [diff] [blame] | 32 | enum class Status { |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 33 | // Everything is peachy. |
Siarhei Vishniakou | f12f2f7 | 2021-11-17 17:49:45 -0800 | [diff] [blame] | 34 | NORMAL, |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 35 | // An unrecoverable communication error has occurred. |
Siarhei Vishniakou | f12f2f7 | 2021-11-17 17:49:45 -0800 | [diff] [blame] | 36 | BROKEN, |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 37 | // The input channel has been unregistered. |
Siarhei Vishniakou | f12f2f7 | 2021-11-17 17:49:45 -0800 | [diff] [blame] | 38 | ZOMBIE, |
| 39 | |
| 40 | ftl_first = NORMAL, |
| 41 | ftl_last = ZOMBIE, |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | Status status; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 45 | bool monitor; |
| 46 | InputPublisher inputPublisher; |
| 47 | InputState inputState; |
| 48 | |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 49 | // True if this connection is responsive. |
| 50 | // If this connection is not responsive, avoid publishing more events to it until the |
| 51 | // application consumes some of the input. |
| 52 | bool responsive = true; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 53 | |
| 54 | // Queue of events that need to be published to the connection. |
Prabir Pradhan | 8c90d78 | 2023-09-15 21:16:44 +0000 | [diff] [blame] | 55 | std::deque<std::unique_ptr<DispatchEntry>> outboundQueue; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 56 | |
| 57 | // Queue of events that have been published to the connection but that have not |
| 58 | // yet received a "finished" response from the application. |
Prabir Pradhan | 8c90d78 | 2023-09-15 21:16:44 +0000 | [diff] [blame] | 59 | std::deque<std::unique_ptr<DispatchEntry>> waitQueue; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 60 | |
Siarhei Vishniakou | 7b9f4f5 | 2024-02-02 13:07:16 -0800 | [diff] [blame] | 61 | Connection(std::unique_ptr<InputChannel> inputChannel, bool monitor, |
Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 62 | const IdGenerator& idGenerator); |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 63 | |
Siarhei Vishniakou | 10bfdc9 | 2024-02-01 11:12:57 -0800 | [diff] [blame] | 64 | inline const std::string getInputChannelName() const { |
Siarhei Vishniakou | 7b9f4f5 | 2024-02-02 13:07:16 -0800 | [diff] [blame] | 65 | return inputPublisher.getChannel().getName(); |
Siarhei Vishniakou | 10bfdc9 | 2024-02-01 11:12:57 -0800 | [diff] [blame] | 66 | } |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 67 | |
Siarhei Vishniakou | 18cbdb8 | 2024-01-31 17:58:13 -0800 | [diff] [blame] | 68 | sp<IBinder> getToken() const; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | } // namespace android::inputdispatcher |