| 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 import logging | 5 import logging |
| 6 import os | 6 import os |
| 7 import re | 7 import re |
| 8 import sys | 8 import sys |
| 9 import threading | 9 import threading |
| 10 import time | 10 import time |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 assert build_type in ('Release', 'Debug') | 46 assert build_type in ('Release', 'Debug') |
| 47 self._adb = adb | 47 self._adb = adb |
| 48 self._host_to_device_port_map = dict() | 48 self._host_to_device_port_map = dict() |
| 49 self._device_initialized = False | 49 self._device_initialized = False |
| 50 self._host_adb_control_port = 0 | 50 self._host_adb_control_port = 0 |
| 51 self._lock = threading.Lock() | 51 self._lock = threading.Lock() |
| 52 self._host_forwarder_path = _MakeBinaryPath(build_type, 'host_forwarder') | 52 self._host_forwarder_path = _MakeBinaryPath(build_type, 'host_forwarder') |
| 53 self._device_forwarder_path_on_host = os.path.join( | 53 self._device_forwarder_path_on_host = os.path.join( |
| 54 cmd_helper.OutDirectory.get(), build_type, 'forwarder_dist') | 54 cmd_helper.OutDirectory.get(), build_type, 'forwarder_dist') |
| 55 | 55 |
| 56 def Run(self, port_pairs, tool, host_name): | 56 def Run(self, port_pairs, tool): |
| 57 """Runs the forwarder. | 57 """Runs the forwarder. |
| 58 | 58 |
| 59 Args: | 59 Args: |
| 60 port_pairs: A list of tuples (device_port, host_port) to forward. Note | 60 port_pairs: A list of tuples (device_port, host_port) to forward. Note |
| 61 that you can specify 0 as a device_port, in which case a | 61 that you can specify 0 as a device_port, in which case a |
| 62 port will by dynamically assigned on the device. You can | 62 port will by dynamically assigned on the device. You can |
| 63 get the number of the assigned port using the | 63 get the number of the assigned port using the |
| 64 DevicePortForHostPort method. | 64 DevicePortForHostPort method. |
| 65 tool: Tool class to use to get wrapper, if necessary, for executing the | 65 tool: Tool class to use to get wrapper, if necessary, for executing the |
| 66 forwarder (see valgrind_tools.py). | 66 forwarder (see valgrind_tools.py). |
| 67 host_name: Address to forward to, must be addressable from the | |
| 68 host machine. Usually use loopback '127.0.0.1'. | |
| 69 | 67 |
| 70 Raises: | 68 Raises: |
| 71 Exception on failure to forward the port. | 69 Exception on failure to forward the port. |
| 72 """ | 70 """ |
| 73 with self._lock: | 71 with self._lock: |
| 74 self._InitDeviceLocked(tool) | 72 self._InitDeviceLocked(tool) |
| 75 self._InitHostLocked() | 73 self._InitHostLocked() |
| 74 host_name = '127.0.0.1' |
| 76 redirection_commands = [ | 75 redirection_commands = [ |
| 77 '%d:%d:%d:%s' % (self._host_adb_control_port, device, host, | 76 '%d:%d:%d:%s' % (self._host_adb_control_port, device, host, |
| 78 host_name) for device, host in port_pairs] | 77 host_name) for device, host in port_pairs] |
| 79 logging.info('Command format: <ADB port>:<Device port>' + | 78 logging.info('Command format: <ADB port>:<Device port>' + |
| 80 '[:<Forward to port>:<Forward to address>]') | 79 '[:<Forward to port>:<Forward to address>]') |
| 81 logging.info('Forwarding using commands: %s', redirection_commands) | 80 logging.info('Forwarding using commands: %s', redirection_commands) |
| 82 | 81 |
| 83 for redirection_command in redirection_commands: | 82 for redirection_command in redirection_commands: |
| 84 try: | 83 try: |
| 85 (exit_code, output) = cmd_helper.GetCmdStatusAndOutput( | 84 (exit_code, output) = cmd_helper.GetCmdStatusAndOutput( |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 def DevicePortForHostPort(self, host_port): | 193 def DevicePortForHostPort(self, host_port): |
| 195 """Returns the device port that corresponds to a given host port.""" | 194 """Returns the device port that corresponds to a given host port.""" |
| 196 with self._lock: | 195 with self._lock: |
| 197 return self._host_to_device_port_map.get(host_port) | 196 return self._host_to_device_port_map.get(host_port) |
| 198 | 197 |
| 199 # Deprecated. | 198 # Deprecated. |
| 200 def Close(self): | 199 def Close(self): |
| 201 """Terminates the forwarder process.""" | 200 """Terminates the forwarder process.""" |
| 202 # TODO(pliard): Remove references in client code. | 201 # TODO(pliard): Remove references in client code. |
| 203 pass | 202 pass |
| OLD | NEW |