OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/android/forwarder2/host_controller.h" | 5 #include "tools/android/forwarder2/host_controller.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 forwarder->Start(); | 61 forwarder->Start(); |
62 } | 62 } |
63 | 63 |
64 bool HostController::Connect() { | 64 bool HostController::Connect() { |
65 if (!adb_control_socket_.ConnectTcp("", adb_port_)) { | 65 if (!adb_control_socket_.ConnectTcp("", adb_port_)) { |
66 LOG(ERROR) << "Could not Connect HostController socket on port: " | 66 LOG(ERROR) << "Could not Connect HostController socket on port: " |
67 << adb_port_; | 67 << adb_port_; |
68 return false; | 68 return false; |
69 } | 69 } |
70 // Send the command to the device start listening to the "device_forward_port" | 70 // Send the command to the device start listening to the "device_forward_port" |
71 bool send_command_success = SendCommand( | 71 SendCommand(command::LISTEN, device_port_, &adb_control_socket_); |
72 command::LISTEN, device_port_, &adb_control_socket_); | |
73 CHECK(send_command_success); | |
74 int device_port_allocated; | 72 int device_port_allocated; |
75 command::Type command; | 73 command::Type command; |
76 if (!ReadCommand(&adb_control_socket_, &device_port_allocated, &command) || | 74 if (!ReadCommand(&adb_control_socket_, &device_port_allocated, &command) || |
77 command != command::BIND_SUCCESS) { | 75 command != command::BIND_SUCCESS) { |
78 LOG(ERROR) << "Device binding error using port " << device_port_; | 76 LOG(ERROR) << "Device binding error using port " << device_port_; |
79 adb_control_socket_.Close(); | 77 adb_control_socket_.Close(); |
80 return false; | 78 return false; |
81 } | 79 } |
82 // When doing dynamically allocation of port, we get the port from the | 80 // When doing dynamically allocation of port, we get the port from the |
83 // BIND_SUCCESS command we received above. | 81 // BIND_SUCCESS command we received above. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 } | 114 } |
117 SendCommand(command::HOST_SERVER_SUCCESS, | 115 SendCommand(command::HOST_SERVER_SUCCESS, |
118 device_port_, | 116 device_port_, |
119 &adb_control_socket_); | 117 &adb_control_socket_); |
120 StartForwarder(host_server_data_socket.Pass()); | 118 StartForwarder(host_server_data_socket.Pass()); |
121 } | 119 } |
122 adb_control_socket_.Close(); | 120 adb_control_socket_.Close(); |
123 } | 121 } |
124 | 122 |
125 } // namespace forwarder2 | 123 } // namespace forwarder2 |
OLD | NEW |