• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  #pragma once
18  
19  #include <https/WebSocketHandler.h>
20  #include <https/RunLoop.h>
21  
22  #include <memory>
23  
24  struct AdbWebSocketHandler
25      : public WebSocketHandler,
26        public std::enable_shared_from_this<AdbWebSocketHandler> {
27  
28      explicit AdbWebSocketHandler(
29              std::shared_ptr<RunLoop> runLoop,
30              const std::string &adb_host_and_port);
31  
32      ~AdbWebSocketHandler() override;
33  
34      void run();
35  
36      int handleMessage(
37              uint8_t headerByte, const uint8_t *msg, size_t len) override;
38  
39  private:
40      struct AdbConnection;
41  
42      std::shared_ptr<RunLoop> mRunLoop;
43      std::shared_ptr<AdbConnection> mAdbConnection;
44  
45      int mSocket;
46  
47      int setupSocket(const std::string &adb_host_and_port);
48  };
49  
50