blob: 4e6ae4bc6b2a4914ddb5e0e997de024bb1daa525 [file] [log] [blame]
Scott James Remnant4dcd73f2013-07-22 15:00:24 -07001# 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
5import logging
6
7from autotest_lib.client.common_lib import error
8from autotest_lib.client.cros import constants
9from autotest_lib.server import autotest
10
11
12class 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
Scott James Remnanta6442f52013-07-24 15:04:55 -070043 def reset_on(self):
44 """Reset the adapter and settings and power up the adapter.
45
46 @return True on success, False otherwise.
47
48 """
49 return self._proxy.reset_on()
50
51 def reset_off(self):
52 """Reset the adapter and settings, leave the adapter powered off.
53
54 @return True on success, False otherwise.
55
56 """
57 return self._proxy.reset_off()
58
59 def set_powered(self, powered):
60 """Set the adapter power state.
61
62 @param powered adapter power state to set (True or False).
63
64 @return True on success, False otherwise.
65
66 """
67 return self._proxy.set_powered(powered)
68
69 def set_discoverable(self, discoverable):
70 """Set the adapter discoverable state.
71
72 @param powered adapter discoverable state to set (True or False).
73
74 @return True on success, False otherwise.
75
76 """
77 return self._proxy.set_discoverable(discoverable)
78
79 def set_pairable(self, pairable):
80 """Set the adapter pairable state.
81
82 @param powered adapter pairable state to set (True or False).
83
84 @return True on success, False otherwise.
85
86 """
87 return self._proxy.set_pairable(pairable)
88
Scott James Remnant4dcd73f2013-07-22 15:00:24 -070089 def close(self):
90 """Tear down state associated with the client."""
Scott James Remnanta6442f52013-07-24 15:04:55 -070091 # Leave the adapter powered off, but don't do a full reset.
92 self._proxy.set_powered(False)
Scott James Remnant4dcd73f2013-07-22 15:00:24 -070093 # This kills the RPC server.
94 self._host.close()