blob: a834a8cf86a9a27694a84f7bfe21e17088c098a6 [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. */
Siarhei Vishniakou1069fa82023-04-19 12:14:39 -070030class Connection {
Garfield Tane84e6f92019-08-29 17:28:41 -070031public:
Siarhei Vishniakouf12f2f72021-11-17 17:49:45 -080032 enum class Status {
Garfield Tane84e6f92019-08-29 17:28:41 -070033 // Everything is peachy.
Siarhei Vishniakouf12f2f72021-11-17 17:49:45 -080034 NORMAL,
Garfield Tane84e6f92019-08-29 17:28:41 -070035 // An unrecoverable communication error has occurred.
Siarhei Vishniakouf12f2f72021-11-17 17:49:45 -080036 BROKEN,
Garfield Tane84e6f92019-08-29 17:28:41 -070037 // The input channel has been unregistered.
Siarhei Vishniakouf12f2f72021-11-17 17:49:45 -080038 ZOMBIE,
39
40 ftl_first = NORMAL,
41 ftl_last = ZOMBIE,
Garfield Tane84e6f92019-08-29 17:28:41 -070042 };
43
44 Status status;
Garfield Tane84e6f92019-08-29 17:28:41 -070045 bool monitor;
46 InputPublisher inputPublisher;
47 InputState inputState;
48
Siarhei Vishniakoud44dddf2020-03-25 16:16:40 -070049 // 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 Tane84e6f92019-08-29 17:28:41 -070053
54 // Queue of events that need to be published to the connection.
Prabir Pradhan8c90d782023-09-15 21:16:44 +000055 std::deque<std::unique_ptr<DispatchEntry>> outboundQueue;
Garfield Tane84e6f92019-08-29 17:28:41 -070056
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 Pradhan8c90d782023-09-15 21:16:44 +000059 std::deque<std::unique_ptr<DispatchEntry>> waitQueue;
Garfield Tane84e6f92019-08-29 17:28:41 -070060
Siarhei Vishniakou7b9f4f52024-02-02 13:07:16 -080061 Connection(std::unique_ptr<InputChannel> inputChannel, bool monitor,
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -050062 const IdGenerator& idGenerator);
Garfield Tane84e6f92019-08-29 17:28:41 -070063
Siarhei Vishniakou10bfdc92024-02-01 11:12:57 -080064 inline const std::string getInputChannelName() const {
Siarhei Vishniakou7b9f4f52024-02-02 13:07:16 -080065 return inputPublisher.getChannel().getName();
Siarhei Vishniakou10bfdc92024-02-01 11:12:57 -080066 }
Garfield Tane84e6f92019-08-29 17:28:41 -070067
Siarhei Vishniakou18cbdb82024-01-31 17:58:13 -080068 sp<IBinder> getToken() const;
Garfield Tane84e6f92019-08-29 17:28:41 -070069};
70
71} // namespace android::inputdispatcher