blob: 6040e9b078373852e0f2df42f7fcc8ff8aacb632 [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
Prabir Pradhan48108662022-09-09 21:22:04 +000017#pragma once
Garfield Tane84e6f92019-08-29 17:28:41 -070018
19#include "InputState.h"
20
21#include <input/InputTransport.h>
Siarhei Vishniakou18050092021-09-01 13:32:49 -070022#include <utils/RefBase.h>
Garfield Tane84e6f92019-08-29 17:28:41 -070023#include <deque>
24
25namespace android::inputdispatcher {
26
27struct DispatchEntry;
28
29/* Manages the dispatch state associated with a single input channel. */
30class Connection : public RefBase {
31protected:
32 virtual ~Connection();
33
34public:
Siarhei Vishniakouf12f2f72021-11-17 17:49:45 -080035 enum class Status {
Garfield Tane84e6f92019-08-29 17:28:41 -070036 // Everything is peachy.
Siarhei Vishniakouf12f2f72021-11-17 17:49:45 -080037 NORMAL,
Garfield Tane84e6f92019-08-29 17:28:41 -070038 // An unrecoverable communication error has occurred.
Siarhei Vishniakouf12f2f72021-11-17 17:49:45 -080039 BROKEN,
Garfield Tane84e6f92019-08-29 17:28:41 -070040 // The input channel has been unregistered.
Siarhei Vishniakouf12f2f72021-11-17 17:49:45 -080041 ZOMBIE,
42
43 ftl_first = NORMAL,
44 ftl_last = ZOMBIE,
Garfield Tane84e6f92019-08-29 17:28:41 -070045 };
46
47 Status status;
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -050048 std::shared_ptr<InputChannel> inputChannel; // never null
Garfield Tane84e6f92019-08-29 17:28:41 -070049 bool monitor;
50 InputPublisher inputPublisher;
51 InputState inputState;
52
Siarhei Vishniakoud44dddf2020-03-25 16:16:40 -070053 // True if this connection is responsive.
54 // If this connection is not responsive, avoid publishing more events to it until the
55 // application consumes some of the input.
56 bool responsive = true;
Garfield Tane84e6f92019-08-29 17:28:41 -070057
58 // Queue of events that need to be published to the connection.
59 std::deque<DispatchEntry*> outboundQueue;
60
61 // Queue of events that have been published to the connection but that have not
62 // yet received a "finished" response from the application.
63 std::deque<DispatchEntry*> waitQueue;
64
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -050065 Connection(const std::shared_ptr<InputChannel>& inputChannel, bool monitor,
66 const IdGenerator& idGenerator);
Garfield Tane84e6f92019-08-29 17:28:41 -070067
68 inline const std::string getInputChannelName() const { return inputChannel->getName(); }
69
70 const std::string getWindowName() const;
Garfield Tane84e6f92019-08-29 17:28:41 -070071
72 std::deque<DispatchEntry*>::iterator findWaitQueueEntry(uint32_t seq);
73};
74
75} // namespace android::inputdispatcher