Scott James Remnant | 4dcd73f | 2013-07-22 15:00:24 -0700 | [diff] [blame^] | 1 | # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | import logging |
| 6 | |
| 7 | from autotest_lib.client.common_lib import error |
| 8 | from autotest_lib.client.cros import constants |
| 9 | from autotest_lib.server import autotest |
| 10 | |
| 11 | |
| 12 | class BluetoothClient(object): |
| 13 | """BluetoothClient is a thin layer of logic over a remote DUT.""" |
| 14 | |
| 15 | XMLRPC_BRINGUP_TIMEOUT_SECONDS = 60 |
| 16 | |
| 17 | @property |
| 18 | def host(self): |
| 19 | """@return host object representing the remote DUT.""" |
| 20 | return self._host |
| 21 | |
| 22 | def __init__(self, client_host): |
| 23 | """Construct a BluetoothClient. |
| 24 | |
| 25 | @param client_host host object representing a remote host. |
| 26 | |
| 27 | """ |
| 28 | self._host = client_host |
| 29 | # Make sure the client library is on the device so that the proxy code |
| 30 | # is there when we try to call it. |
| 31 | client_at = autotest.Autotest(self.host) |
| 32 | client_at.install() |
| 33 | # Start up the XML-RPC proxy on the client. |
| 34 | self._proxy = self.host.xmlrpc_connect( |
| 35 | constants.BLUETOOTH_CLIENT_XMLRPC_SERVER_COMMAND, |
| 36 | constants.BLUETOOTH_CLIENT_XMLRPC_SERVER_PORT, |
| 37 | command_name= |
| 38 | constants.BLUETOOTH_CLIENT_XMLRPC_SERVER_CLEANUP_PATTERN, |
| 39 | ready_test_name= |
| 40 | constants.BLUETOOTH_CLIENT_XMLRPC_SERVER_READY_METHOD, |
| 41 | timeout_seconds=self.XMLRPC_BRINGUP_TIMEOUT_SECONDS) |
| 42 | |
| 43 | def close(self): |
| 44 | """Tear down state associated with the client.""" |
| 45 | # This kills the RPC server. |
| 46 | self._host.close() |