xref: /aosp_15_r20/frameworks/native/services/inputflinger/dispatcher/Connection.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright (C) 2019 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #pragma once
18*38e8c45fSAndroid Build Coastguard Worker 
19*38e8c45fSAndroid Build Coastguard Worker #include "InputState.h"
20*38e8c45fSAndroid Build Coastguard Worker 
21*38e8c45fSAndroid Build Coastguard Worker #include <input/InputTransport.h>
22*38e8c45fSAndroid Build Coastguard Worker #include <utils/RefBase.h>
23*38e8c45fSAndroid Build Coastguard Worker #include <deque>
24*38e8c45fSAndroid Build Coastguard Worker 
25*38e8c45fSAndroid Build Coastguard Worker namespace android::inputdispatcher {
26*38e8c45fSAndroid Build Coastguard Worker 
27*38e8c45fSAndroid Build Coastguard Worker struct DispatchEntry;
28*38e8c45fSAndroid Build Coastguard Worker 
29*38e8c45fSAndroid Build Coastguard Worker /* Manages the dispatch state associated with a single input channel. */
30*38e8c45fSAndroid Build Coastguard Worker class Connection {
31*38e8c45fSAndroid Build Coastguard Worker public:
32*38e8c45fSAndroid Build Coastguard Worker     enum class Status {
33*38e8c45fSAndroid Build Coastguard Worker         // Everything is peachy.
34*38e8c45fSAndroid Build Coastguard Worker         NORMAL,
35*38e8c45fSAndroid Build Coastguard Worker         // An unrecoverable communication error has occurred.
36*38e8c45fSAndroid Build Coastguard Worker         BROKEN,
37*38e8c45fSAndroid Build Coastguard Worker         // The input channel has been unregistered.
38*38e8c45fSAndroid Build Coastguard Worker         ZOMBIE,
39*38e8c45fSAndroid Build Coastguard Worker 
40*38e8c45fSAndroid Build Coastguard Worker         ftl_first = NORMAL,
41*38e8c45fSAndroid Build Coastguard Worker         ftl_last = ZOMBIE,
42*38e8c45fSAndroid Build Coastguard Worker     };
43*38e8c45fSAndroid Build Coastguard Worker 
44*38e8c45fSAndroid Build Coastguard Worker     Status status;
45*38e8c45fSAndroid Build Coastguard Worker     bool monitor;
46*38e8c45fSAndroid Build Coastguard Worker     InputPublisher inputPublisher;
47*38e8c45fSAndroid Build Coastguard Worker     InputState inputState;
48*38e8c45fSAndroid Build Coastguard Worker 
49*38e8c45fSAndroid Build Coastguard Worker     // True if this connection is responsive.
50*38e8c45fSAndroid Build Coastguard Worker     // If this connection is not responsive, avoid publishing more events to it until the
51*38e8c45fSAndroid Build Coastguard Worker     // application consumes some of the input.
52*38e8c45fSAndroid Build Coastguard Worker     bool responsive = true;
53*38e8c45fSAndroid Build Coastguard Worker 
54*38e8c45fSAndroid Build Coastguard Worker     // Queue of events that need to be published to the connection.
55*38e8c45fSAndroid Build Coastguard Worker     std::deque<std::unique_ptr<DispatchEntry>> outboundQueue;
56*38e8c45fSAndroid Build Coastguard Worker 
57*38e8c45fSAndroid Build Coastguard Worker     // Queue of events that have been published to the connection but that have not
58*38e8c45fSAndroid Build Coastguard Worker     // yet received a "finished" response from the application.
59*38e8c45fSAndroid Build Coastguard Worker     std::deque<std::unique_ptr<DispatchEntry>> waitQueue;
60*38e8c45fSAndroid Build Coastguard Worker 
61*38e8c45fSAndroid Build Coastguard Worker     Connection(std::unique_ptr<InputChannel> inputChannel, bool monitor,
62*38e8c45fSAndroid Build Coastguard Worker                const IdGenerator& idGenerator);
63*38e8c45fSAndroid Build Coastguard Worker 
getInputChannelName()64*38e8c45fSAndroid Build Coastguard Worker     inline const std::string getInputChannelName() const {
65*38e8c45fSAndroid Build Coastguard Worker         return inputPublisher.getChannel().getName();
66*38e8c45fSAndroid Build Coastguard Worker     }
67*38e8c45fSAndroid Build Coastguard Worker 
68*38e8c45fSAndroid Build Coastguard Worker     sp<IBinder> getToken() const;
69*38e8c45fSAndroid Build Coastguard Worker };
70*38e8c45fSAndroid Build Coastguard Worker 
71*38e8c45fSAndroid Build Coastguard Worker } // namespace android::inputdispatcher
72