| 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 #ifndef TOOLS_ANDROID_FORWARDER2_HOST_CONTROLLER_H_ | 5 #ifndef TOOLS_ANDROID_FORWARDER2_HOST_CONTROLLER_H_ |
| 6 #define TOOLS_ANDROID_FORWARDER2_HOST_CONTROLLER_H_ | 6 #define TOOLS_ANDROID_FORWARDER2_HOST_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 // owner to delete the instance. | 32 // owner to delete the instance. |
| 33 class HostController { | 33 class HostController { |
| 34 public: | 34 public: |
| 35 // Callback used for self-deletion when an error happens so that the client | 35 // Callback used for self-deletion when an error happens so that the client |
| 36 // can perform some cleanup work before deleting the HostController instance. | 36 // can perform some cleanup work before deleting the HostController instance. |
| 37 typedef base::Callback<void(std::unique_ptr<HostController>)> ErrorCallback; | 37 typedef base::Callback<void(std::unique_ptr<HostController>)> ErrorCallback; |
| 38 | 38 |
| 39 // If |device_port| is zero then a dynamic port is allocated (and retrievable | 39 // If |device_port| is zero then a dynamic port is allocated (and retrievable |
| 40 // through device_port() below). | 40 // through device_port() below). |
| 41 static std::unique_ptr<HostController> Create( | 41 static std::unique_ptr<HostController> Create( |
| 42 const std::string& device_serial, |
| 42 int device_port, | 43 int device_port, |
| 43 int host_port, | 44 int host_port, |
| 44 int adb_port, | 45 int adb_port, |
| 45 int exit_notifier_fd, | 46 int exit_notifier_fd, |
| 46 const ErrorCallback& error_callback); | 47 const ErrorCallback& error_callback); |
| 47 | 48 |
| 48 ~HostController(); | 49 ~HostController(); |
| 49 | 50 |
| 50 // Starts the internal controller thread. | 51 // Starts the internal controller thread. |
| 51 void Start(); | 52 void Start(); |
| 52 | 53 |
| 53 int adb_port() const { return adb_port_; } | 54 int adb_port() const { return adb_port_; } |
| 54 | 55 |
| 55 int device_port() const { return device_port_; } | 56 int device_port() const { return device_port_; } |
| 56 | 57 |
| 57 private: | 58 private: |
| 58 HostController(int device_port, | 59 HostController(const std::string& device_serial, |
| 60 int device_port, |
| 59 int host_port, | 61 int host_port, |
| 60 int adb_port, | 62 int adb_port, |
| 61 const ErrorCallback& error_callback, | 63 const ErrorCallback& error_callback, |
| 62 std::unique_ptr<Socket> adb_control_socket, | 64 std::unique_ptr<Socket> adb_control_socket, |
| 63 std::unique_ptr<PipeNotifier> delete_controller_notifier); | 65 std::unique_ptr<PipeNotifier> delete_controller_notifier); |
| 64 | 66 |
| 65 void ReadNextCommandSoon(); | 67 void ReadNextCommandSoon(); |
| 66 void ReadCommandOnInternalThread(); | 68 void ReadCommandOnInternalThread(); |
| 67 | 69 |
| 68 void StartForwarder(std::unique_ptr<Socket> host_server_data_socket); | 70 void StartForwarder(std::unique_ptr<Socket> host_server_data_socket); |
| 69 | 71 |
| 70 // Note that this gets also called when ~HostController() is invoked. | 72 // Note that this gets also called when ~HostController() is invoked. |
| 71 void OnInternalThreadError(); | 73 void OnInternalThreadError(); |
| 72 | 74 |
| 73 void UnmapPortOnDevice(); | 75 void UnmapPortOnDevice(); |
| 74 | 76 |
| 75 SelfDeleterHelper<HostController> self_deleter_helper_; | 77 SelfDeleterHelper<HostController> self_deleter_helper_; |
| 78 const std::string device_serial_; |
| 76 const int device_port_; | 79 const int device_port_; |
| 77 const int host_port_; | 80 const int host_port_; |
| 78 const int adb_port_; | 81 const int adb_port_; |
| 79 std::unique_ptr<Socket> adb_control_socket_; | 82 std::unique_ptr<Socket> adb_control_socket_; |
| 80 // Used to cancel the pending blocking IO operations when the host controller | 83 // Used to cancel the pending blocking IO operations when the host controller |
| 81 // instance is deleted. | 84 // instance is deleted. |
| 82 std::unique_ptr<PipeNotifier> delete_controller_notifier_; | 85 std::unique_ptr<PipeNotifier> delete_controller_notifier_; |
| 83 // Task runner used for deletion set at deletion time (i.e. the object is | 86 // Task runner used for deletion set at deletion time (i.e. the object is |
| 84 // deleted on the same thread it is created on). | 87 // deleted on the same thread it is created on). |
| 85 const scoped_refptr<base::SingleThreadTaskRunner> deletion_task_runner_; | 88 const scoped_refptr<base::SingleThreadTaskRunner> deletion_task_runner_; |
| 86 base::Thread thread_; | 89 base::Thread thread_; |
| 87 ForwardersManager forwarders_manager_; | 90 ForwardersManager forwarders_manager_; |
| 88 | 91 |
| 89 DISALLOW_COPY_AND_ASSIGN(HostController); | 92 DISALLOW_COPY_AND_ASSIGN(HostController); |
| 90 }; | 93 }; |
| 91 | 94 |
| 92 } // namespace forwarder2 | 95 } // namespace forwarder2 |
| 93 | 96 |
| 94 #endif // TOOLS_ANDROID_FORWARDER2_HOST_CONTROLLER_H_ | 97 #endif // TOOLS_ANDROID_FORWARDER2_HOST_CONTROLLER_H_ |
| OLD | NEW |