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 <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 CHECK(send_command_success); | 41 CHECK(send_command_success); |
42 int device_port_allocated; | 42 int device_port_allocated; |
43 command::Type command; | 43 command::Type command; |
44 if (!ReadCommand( | 44 if (!ReadCommand( |
45 adb_control_socket.get(), &device_port_allocated, &command) || | 45 adb_control_socket.get(), &device_port_allocated, &command) || |
46 command != command::BIND_SUCCESS) { | 46 command != command::BIND_SUCCESS) { |
47 LOG(ERROR) << "Device binding error using port " << device_port; | 47 LOG(ERROR) << "Device binding error using port " << device_port; |
48 return host_controller; | 48 return host_controller; |
49 } | 49 } |
50 host_controller.reset(new HostController( | 50 host_controller.reset(new HostController( |
51 device_port_allocated, host_port, adb_port, exit_notifier_fd, | 51 device_port_allocated, host_port, adb_port, error_callback, |
52 error_callback, std::move(adb_control_socket), | 52 std::move(adb_control_socket), std::move(delete_controller_notifier))); |
53 std::move(delete_controller_notifier))); | |
54 return host_controller; | 53 return host_controller; |
55 } | 54 } |
56 | 55 |
57 HostController::~HostController() { | 56 HostController::~HostController() { |
58 DCHECK(deletion_task_runner_->RunsTasksOnCurrentThread()); | 57 DCHECK(deletion_task_runner_->RunsTasksOnCurrentThread()); |
59 delete_controller_notifier_->Notify(); | 58 delete_controller_notifier_->Notify(); |
60 } | 59 } |
61 | 60 |
62 void HostController::Start() { | 61 void HostController::Start() { |
63 thread_.Start(); | 62 thread_.Start(); |
64 ReadNextCommandSoon(); | 63 ReadNextCommandSoon(); |
65 } | 64 } |
66 | 65 |
67 HostController::HostController( | 66 HostController::HostController( |
68 int device_port, | 67 int device_port, |
69 int host_port, | 68 int host_port, |
70 int adb_port, | 69 int adb_port, |
71 int exit_notifier_fd, | |
72 const ErrorCallback& error_callback, | 70 const ErrorCallback& error_callback, |
73 std::unique_ptr<Socket> adb_control_socket, | 71 std::unique_ptr<Socket> adb_control_socket, |
74 std::unique_ptr<PipeNotifier> delete_controller_notifier) | 72 std::unique_ptr<PipeNotifier> delete_controller_notifier) |
75 : self_deleter_helper_(this, error_callback), | 73 : self_deleter_helper_(this, error_callback), |
76 device_port_(device_port), | 74 device_port_(device_port), |
77 host_port_(host_port), | 75 host_port_(host_port), |
78 adb_port_(adb_port), | 76 adb_port_(adb_port), |
79 global_exit_notifier_fd_(exit_notifier_fd), | |
80 adb_control_socket_(std::move(adb_control_socket)), | 77 adb_control_socket_(std::move(adb_control_socket)), |
81 delete_controller_notifier_(std::move(delete_controller_notifier)), | 78 delete_controller_notifier_(std::move(delete_controller_notifier)), |
82 deletion_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 79 deletion_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
83 thread_("HostControllerThread") {} | 80 thread_("HostControllerThread") {} |
84 | 81 |
85 void HostController::ReadNextCommandSoon() { | 82 void HostController::ReadNextCommandSoon() { |
86 thread_.task_runner()->PostTask( | 83 thread_.task_runner()->PostTask( |
87 FROM_HERE, | 84 FROM_HERE, |
88 base::Bind(&HostController::ReadCommandOnInternalThread, | 85 base::Bind(&HostController::ReadCommandOnInternalThread, |
89 base::Unretained(this))); | 86 base::Unretained(this))); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 LOG(ERROR) << "Could not send unmap command for port " << device_port_; | 157 LOG(ERROR) << "Could not send unmap command for port " << device_port_; |
161 return; | 158 return; |
162 } | 159 } |
163 if (!ReceivedCommand(command::UNLISTEN_SUCCESS, &socket)) { | 160 if (!ReceivedCommand(command::UNLISTEN_SUCCESS, &socket)) { |
164 LOG(ERROR) << "Unamp command failed for port " << device_port_; | 161 LOG(ERROR) << "Unamp command failed for port " << device_port_; |
165 return; | 162 return; |
166 } | 163 } |
167 } | 164 } |
168 | 165 |
169 } // namespace forwarder2 | 166 } // namespace forwarder2 |
OLD | NEW |