Home | History | Annotate | Download | only in state_machines
      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 # Setup wardmodem package root and other autotest paths.
      6 import common
      7 
      8 import state_machine
      9 
     10 class LevelIndicatorsMachine(state_machine.StateMachine):
     11     """
     12     Machine that maintains the information about different indications that are
     13     usually shown by the phone on UI.
     14 
     15     """
     16     def __init__(self, state, transceiver, modem_conf):
     17         """
     18         @param state: The GlobalState object shared by all state machines.
     19 
     20         @param transceiver: The ATTransceiver object to interact with.
     21 
     22         @param modem_conf: A modem configuration object that contains
     23                 configuration data for different state machines.
     24 
     25         @raises: SetupException if we attempt to create an instance of a machine
     26         that has not been completely specified (see get_well_known_name).
     27 
     28         """
     29         super(LevelIndicatorsMachine, self).__init__(state, transceiver,
     30                                                      modem_conf)
     31 
     32         # Add all wardmodem response functions used by this machine.
     33         self._add_response_function('wm_response_level_indicators')
     34 
     35         # Load configuration for this machine and initialize relevant
     36         # GlobalState components.
     37         self._supported_indicators = []
     38         for item in self._modem_conf.level_indicators_items:
     39             self._supported_indicators.append('level_' + item)
     40 
     41         items = self._supported_indicators
     42         defaults = self._modem_conf.level_indicators_defaults
     43         if len(items) != len(defaults):
     44             self._raise_setup_error(
     45                     'Indicator list and its defaults must be of the same '
     46                     'length: Items:|%s|, Defaults:|%s|' % (str(items),
     47                                                            str(defaults)))
     48         for index in range(len(items)):
     49             self._state[items[index]] = defaults[index]
     50 
     51 
     52     def get_well_known_name(self):
     53         """ Returns the well known name for this machine. """
     54         return 'level_indicators_machine'
     55 
     56 
     57     # ##########################################################################
     58     # State machine API functions.
     59     def get_current_levels(self):
     60         levels = []
     61         for indicator in self._supported_indicators:
     62             levels.append(str(self._state[indicator]))
     63         self._respond(self.wm_response_level_indicators, 0, *levels)
     64         self._respond_ok()
     65