1#!/usr/bin/python 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 sys_power 14from autotest_lib.client.cros import xmlrpc_server 15 16 17class DarkResumeXmlRpcDelegate(xmlrpc_server.XmlRpcDelegate): 18 """Exposes methods called remotely during dark resume autotests. 19 20 All instance methods of this object without a preceding '_' are exposed via 21 an XMLRPC server. This is not a stateless handler object, which means that 22 if you store state inside the delegate, that state will remain around for 23 future calls. 24 25 """ 26 27 def __init__(self): 28 super(DarkResumeXmlRpcDelegate, self).__init__() 29 self._listener = dark_resume_listener.DarkResumeListener() 30 31 32 @xmlrpc_server.dbus_safe(None) 33 def suspend_bg_for_dark_resume(self): 34 """Suspends this system indefinitely for dark resume.""" 35 sys_power.suspend_bg_for_dark_resume() 36 37 38 @xmlrpc_server.dbus_safe(0) 39 def get_dark_resume_count(self): 40 """Gets the number of dark resumes that have occurred since 41 this listener was created.""" 42 return self._listener.count 43 44 45if __name__ == '__main__': 46 logging.basicConfig(level=logging.DEBUG) 47 handler = logging.handlers.SysLogHandler(address = '/dev/log') 48 formatter = logging.Formatter( 49 'dark_resume_xmlrpc_server: [%(levelname)s] %(message)s') 50 handler.setFormatter(formatter) 51 logging.getLogger().addHandler(handler) 52 logging.debug('dark_resume_xmlrpc_server main...') 53 server = xmlrpc_server.XmlRpcServer( 54 'localhost', constants.DARK_RESUME_XMLRPC_SERVER_PORT) 55 server.register_delegate(DarkResumeXmlRpcDelegate()) 56 server.run() 57