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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 121 |
122 def _UnmapDevicePortInternalLocked(self, device_port): | 122 def _UnmapDevicePortInternalLocked(self, device_port): |
123 if not device_port in self._device_to_host_port_map: | 123 if not device_port in self._device_to_host_port_map: |
124 return | 124 return |
125 redirection_command = [ | 125 redirection_command = [ |
126 '--serial-id=' + self._adb.Adb().GetSerialNumber(), '--unmap', | 126 '--serial-id=' + self._adb.Adb().GetSerialNumber(), '--unmap', |
127 str(device_port)] | 127 str(device_port)] |
128 (exit_code, output) = cmd_helper.GetCmdStatusAndOutput( | 128 (exit_code, output) = cmd_helper.GetCmdStatusAndOutput( |
129 [self._host_forwarder_path] + redirection_command) | 129 [self._host_forwarder_path] + redirection_command) |
130 if exit_code != 0: | 130 if exit_code != 0: |
131 raise Exception('%s exited with %d:\n%s' % ( | 131 logging.error('%s exited with %d:\n%s' % ( |
132 self._host_forwarder_path, exit_code, '\n'.join(output))) | 132 self._host_forwarder_path, exit_code, '\n'.join(output))) |
133 host_port = self._device_to_host_port_map[device_port] | 133 host_port = self._device_to_host_port_map[device_port] |
134 del self._device_to_host_port_map[device_port] | 134 del self._device_to_host_port_map[device_port] |
135 del self._host_to_device_port_map[host_port] | 135 del self._host_to_device_port_map[host_port] |
136 | 136 |
137 @staticmethod | 137 @staticmethod |
138 def KillHost(build_type='Debug'): | 138 def KillHost(build_type='Debug'): |
139 """Kills the forwarder process running on the host. | 139 """Kills the forwarder process running on the host. |
140 | 140 |
141 Args: | 141 Args: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 def DevicePortForHostPort(self, host_port): | 184 def DevicePortForHostPort(self, host_port): |
185 """Returns the device port that corresponds to a given host port.""" | 185 """Returns the device port that corresponds to a given host port.""" |
186 with self._lock: | 186 with self._lock: |
187 return self._host_to_device_port_map.get(host_port) | 187 return self._host_to_device_port_map.get(host_port) |
188 | 188 |
189 def Close(self): | 189 def Close(self): |
190 """Releases the previously forwarded ports.""" | 190 """Releases the previously forwarded ports.""" |
191 with self._lock: | 191 with self._lock: |
192 for device_port in self._device_to_host_port_map.copy(): | 192 for device_port in self._device_to_host_port_map.copy(): |
193 self._UnmapDevicePortInternalLocked(device_port) | 193 self._UnmapDevicePortInternalLocked(device_port) |
OLD | NEW |