| 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> | 
 | 23 | #include <deque> | 
 | 24 |  | 
 | 25 | namespace android::inputdispatcher { | 
 | 26 |  | 
 | 27 | struct DispatchEntry; | 
 | 28 |  | 
 | 29 | /* Manages the dispatch state associated with a single input channel. */ | 
 | 30 | class Connection : public RefBase { | 
 | 31 | protected: | 
 | 32 |     virtual ~Connection(); | 
 | 33 |  | 
 | 34 | public: | 
 | 35 |     enum Status { | 
 | 36 |         // Everything is peachy. | 
 | 37 |         STATUS_NORMAL, | 
 | 38 |         // An unrecoverable communication error has occurred. | 
 | 39 |         STATUS_BROKEN, | 
 | 40 |         // The input channel has been unregistered. | 
 | 41 |         STATUS_ZOMBIE | 
 | 42 |     }; | 
 | 43 |  | 
 | 44 |     Status status; | 
| Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 45 |     std::shared_ptr<InputChannel> inputChannel; // never null | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 46 |     bool monitor; | 
 | 47 |     InputPublisher inputPublisher; | 
 | 48 |     InputState inputState; | 
 | 49 |  | 
| Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 50 |     // True if this connection is responsive. | 
 | 51 |     // If this connection is not responsive, avoid publishing more events to it until the | 
 | 52 |     // application consumes some of the input. | 
 | 53 |     bool responsive = true; | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 54 |  | 
 | 55 |     // Queue of events that need to be published to the connection. | 
 | 56 |     std::deque<DispatchEntry*> outboundQueue; | 
 | 57 |  | 
 | 58 |     // Queue of events that have been published to the connection but that have not | 
 | 59 |     // yet received a "finished" response from the application. | 
 | 60 |     std::deque<DispatchEntry*> waitQueue; | 
 | 61 |  | 
| Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 62 |     Connection(const std::shared_ptr<InputChannel>& inputChannel, bool monitor, | 
 | 63 |                const IdGenerator& idGenerator); | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 64 |  | 
 | 65 |     inline const std::string getInputChannelName() const { return inputChannel->getName(); } | 
 | 66 |  | 
 | 67 |     const std::string getWindowName() const; | 
 | 68 |     const char* getStatusLabel() const; | 
 | 69 |  | 
 | 70 |     std::deque<DispatchEntry*>::iterator findWaitQueueEntry(uint32_t seq); | 
 | 71 | }; | 
 | 72 |  | 
 | 73 | } // namespace android::inputdispatcher | 
 | 74 |  | 
 | 75 | #endif // _UI_INPUT_INPUTDISPATCHER_CONNECTION_H |