Simran Basi | af9b8e7 | 2012-10-12 15:02:36 -0700 | [diff] [blame] | 1 | # Copyright (c) 2012 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 | class _SiteAbstractDrone(object): |
| 6 | """ |
| 7 | This is a site subclass of _BaseAbstractDrone in drones.py. Any methods |
| 8 | here automatically overload _BaseAbstractDrone and are used to create |
| 9 | _AbstractDrone for consumers. |
| 10 | """ |
| 11 | |
| 12 | |
Prashanth B | cf731e3 | 2014-08-10 18:03:57 -0700 | [diff] [blame] | 13 | def __init__(self, timestamp_remote_calls=True): |
Simran Basi | af9b8e7 | 2012-10-12 15:02:36 -0700 | [diff] [blame] | 14 | """ |
| 15 | Add a new private variable _processes_to_kill to _AbstractDrone |
Prashanth B | cf731e3 | 2014-08-10 18:03:57 -0700 | [diff] [blame] | 16 | |
| 17 | @param timestamp_remote_calls: If true, drone_utility is invoked with |
| 18 | the --call_time option and the current time. Currently this is only |
| 19 | used for testing. |
Simran Basi | af9b8e7 | 2012-10-12 15:02:36 -0700 | [diff] [blame] | 20 | """ |
Prashanth B | cf731e3 | 2014-08-10 18:03:57 -0700 | [diff] [blame] | 21 | super(_SiteAbstractDrone, self).__init__( |
| 22 | timestamp_remote_calls=timestamp_remote_calls) |
Simran Basi | af9b8e7 | 2012-10-12 15:02:36 -0700 | [diff] [blame] | 23 | self._processes_to_kill = [] |
| 24 | |
| 25 | |
| 26 | def queue_kill_process(self, process): |
| 27 | """Queue a process to kill/abort. |
| 28 | |
| 29 | @param process: Process to kill/abort. |
| 30 | """ |
| 31 | self._processes_to_kill.append(process) |
| 32 | |
| 33 | |
| 34 | def clear_processes_to_kill(self): |
| 35 | """Reset the list of processes to kill for this tick.""" |
| 36 | self._processes_to_kill = [] |
| 37 | |
| 38 | |
| 39 | def execute_queued_calls(self): |
| 40 | """Overloads execute_queued_calls(). |
| 41 | |
| 42 | If there are any processes queued to kill, kill them then process the |
| 43 | remaining queued up calls. |
| 44 | """ |
| 45 | if self._processes_to_kill: |
| 46 | self.queue_call('kill_processes', self._processes_to_kill) |
| 47 | self.clear_processes_to_kill() |
Prashanth B | 340fd1e | 2014-06-22 12:44:10 -0700 | [diff] [blame] | 48 | return super(_SiteAbstractDrone, self).execute_queued_calls() |