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