• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python2
2
3# Copyright 2015 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7import logging
8import logging.handlers
9
10import common
11from autotest_lib.client.cros import constants
12from autotest_lib.client.cros import dark_resume_listener
13from autotest_lib.client.cros import xmlrpc_server
14from autotest_lib.client.cros.power import sys_power
15from autotest_lib.client.cros.power import power_utils
16
17
18class DarkResumeXmlRpcDelegate(xmlrpc_server.XmlRpcDelegate):
19    """Exposes methods called remotely during dark resume autotests.
20
21    All instance methods of this object without a preceding '_' are exposed via
22    an XMLRPC server.  This is not a stateless handler object, which means that
23    if you store state inside the delegate, that state will remain around for
24    future calls.
25
26    """
27
28    def __init__(self):
29        super(DarkResumeXmlRpcDelegate, self).__init__()
30        self._listener = dark_resume_listener.DarkResumeListener()
31
32    @xmlrpc_server.dbus_safe(None)
33    def suspend_bg(self, suspend_for_secs):
34        """
35        Suspends the system for dark resume.
36        @param suspend_for_secs : Sets a rtc alarm to
37            wake the system after|suspend_for_secs| secs.
38        """
39        sys_power.suspend_bg_for_dark_resume(suspend_for_secs)
40
41    @xmlrpc_server.dbus_safe(None)
42    def set_stop_resuspend(self, stop_resuspend):
43        """
44        Stops resuspend on seeing a dark resume.
45        @param stop_resuspend: Stops resuspend of the device on seeing a
46            a dark resume if |stop_resuspend| is true.
47        """
48        self._listener.stop_resuspend(stop_resuspend)
49
50    @xmlrpc_server.dbus_safe(0)
51    def get_dark_resume_count(self):
52        """Gets the number of dark resumes that have occurred since
53        this listener was created."""
54        return self._listener.count
55
56    @xmlrpc_server.dbus_safe(False)
57    def has_lid(self):
58        """
59        Checks whether the DUT has lid.
60
61        @return: Returns True if the device has a lid, False otherwise.
62        """
63
64        return power_utils.has_lid()
65
66
67if __name__ == '__main__':
68    logging.basicConfig(level=logging.DEBUG)
69    handler = logging.handlers.SysLogHandler(address='/dev/log')
70    formatter = logging.Formatter(
71        'dark_resume_xmlrpc_server: [%(levelname)s] %(message)s')
72    handler.setFormatter(formatter)
73    logging.getLogger().addHandler(handler)
74    logging.debug('dark_resume_xmlrpc_server main...')
75    server = xmlrpc_server.XmlRpcServer(
76        'localhost', constants.DARK_RESUME_XMLRPC_SERVER_PORT)
77    server.register_delegate(DarkResumeXmlRpcDelegate())
78    server.run()
79