• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2017 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"""An interface to access the local input facade."""
6
7
8import json
9import logging
10
11from autotest_lib.client.bin.input import input_event_recorder
12from autotest_lib.client.common_lib import error
13
14
15class InputFacadeNativeError(Exception):
16    """Error in InputFacadeNative."""
17    pass
18
19
20class InputFacadeNative(object):
21    """Facade to access the record input events."""
22
23    def __init__(self):
24        """Initializes the input facade."""
25        self.recorder = None
26
27
28    def initialize_input_recorder(self, device_name):
29        """Initialize an input event recorder object.
30
31        @param device_name: the name of the input device to record.
32
33        """
34        self.recorder = input_event_recorder.InputEventRecorder(device_name)
35        logging.info('input event device: %s (%s)',
36                     self.recorder.device_name, self.recorder.device_node)
37
38
39    def clear_input_events(self):
40        """Clear the event list."""
41        if self.recorder is None:
42            raise error.TestError('input facade: input device name not given')
43        self.recorder.clear_events()
44
45
46    def start_input_recorder(self):
47        """Start the recording thread."""
48        if self.recorder is None:
49            raise error.TestError('input facade: input device name not given')
50        self.recorder.start()
51
52
53    def stop_input_recorder(self):
54        """Stop the recording thread."""
55        if self.recorder is None:
56            raise error.TestError('input facade: input device name not given')
57        self.recorder.stop()
58
59
60    def get_input_events(self):
61        """Get the bluetooth device input events.
62
63        @returns: the recorded input events.
64
65        """
66        if self.recorder is None:
67            raise error.TestError('input facade: input device name not given')
68        events = self.recorder.get_events()
69        return json.dumps(events)
70