blob: dc6a081ff69ab3163d78205f3e44481772a5b3ae [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:
Siarhei Vishniakouf12f2f72021-11-17 17:49:45 -080036 enum class Status {
Garfield Tane84e6f92019-08-29 17:28:41 -070037 // Everything is peachy.
Siarhei Vishniakouf12f2f72021-11-17 17:49:45 -080038 NORMAL,
Garfield Tane84e6f92019-08-29 17:28:41 -070039 // An unrecoverable communication error has occurred.
Siarhei Vishniakouf12f2f72021-11-17 17:49:45 -080040 BROKEN,
Garfield Tane84e6f92019-08-29 17:28:41 -070041 // The input channel has been unregistered.
Siarhei Vishniakouf12f2f72021-11-17 17:49:45 -080042 ZOMBIE,
43
44 ftl_first = NORMAL,
45 ftl_last = ZOMBIE,
Garfield Tane84e6f92019-08-29 17:28:41 -070046 };
47
48 Status status;
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -050049 std::shared_ptr<InputChannel> inputChannel; // never null
Garfield Tane84e6f92019-08-29 17:28:41 -070050 bool monitor;
51 InputPublisher inputPublisher;
52 InputState inputState;
53
Siarhei Vishniakoud44dddf2020-03-25 16:16:40 -070054 // 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 Tane84e6f92019-08-29 17:28:41 -070058
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 Vishniakouce5ab082020-07-09 17:03:21 -050066 Connection(const std::shared_ptr<InputChannel>& inputChannel, bool monitor,
67 const IdGenerator& idGenerator);
Garfield Tane84e6f92019-08-29 17:28:41 -070068
69 inline const std::string getInputChannelName() const { return inputChannel->getName(); }
70
71 const std::string getWindowName() const;
Garfield Tane84e6f92019-08-29 17:28:41 -070072
73 std::deque<DispatchEntry*>::iterator findWaitQueueEntry(uint32_t seq);
74};
75
76} // namespace android::inputdispatcher
77
78#endif // _UI_INPUT_INPUTDISPATCHER_CONNECTION_H