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/RunLoop.h> 20 #include <https/WebSocketHandler.h> 21 22 #include <memory> 23 24 namespace cuttlefish { 25 namespace webrtc_streaming { 26 27 struct AdbHandler : public std::enable_shared_from_this<AdbHandler> { 28 explicit AdbHandler( 29 std::shared_ptr<RunLoop> runLoop, const std::string &adb_host_and_port, 30 std::function<void(const uint8_t *, size_t)> send_to_client); 31 32 ~AdbHandler(); 33 34 void run(); 35 36 void handleMessage(const uint8_t *msg, size_t len); 37 38 private: 39 struct AdbConnection; 40 41 std::shared_ptr<RunLoop> mRunLoop; 42 std::shared_ptr<AdbConnection> mAdbConnection; 43 44 int mSocket; 45 46 std::function<void(const uint8_t *, size_t)> send_to_client_; 47 48 int setupSocket(const std::string &adb_host_and_port); 49 }; 50 51 } // namespace webrtc_streaming 52 } // namespace cuttlefish 53