1 /*
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 #include "Queue.h"
22 
23 #include <input/InputTransport.h>
24 #include <deque>
25 
26 namespace android::inputdispatcher {
27 
28 struct DispatchEntry;
29 
30 /* Manages the dispatch state associated with a single input channel. */
31 class Connection : public RefBase {
32 protected:
33     virtual ~Connection();
34 
35 public:
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;
46     sp<InputChannel> inputChannel; // never null
47     bool monitor;
48     InputPublisher inputPublisher;
49     InputState inputState;
50 
51     // True if the socket is full and no further events can be published until
52     // the application consumes some of the input.
53     bool inputPublisherBlocked;
54 
55     // Queue of events that need to be published to the connection.
56     Queue<DispatchEntry> outboundQueue;
57 
58     // Queue of events that have been published to the connection but that have not
59     // yet received a "finished" response from the application.
60     Queue<DispatchEntry> waitQueue;
61 
62     explicit Connection(const sp<InputChannel>& inputChannel, bool monitor);
63 
getInputChannelName()64     inline const std::string getInputChannelName() const { return inputChannel->getName(); }
65 
66     const std::string getWindowName() const;
67     const char* getStatusLabel() const;
68 
69     DispatchEntry* findWaitQueueEntry(uint32_t seq);
70 };
71 
72 } // namespace android::inputdispatcher
73 
74 #endif // _UI_INPUT_INPUTDISPATCHER_CONNECTION_H
75