blob: c3d5a380f14e0758b3bb824e74828627986abe5c [file] [log] [blame]
Gilad Arnold1ebd8132012-03-05 10:19:29 -08001// 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#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_GPIO_HANDLER_H__
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_GPIO_HANDLER_H__
7
8#include <libudev.h>
9
10#include <string>
11
12#include <base/basictypes.h>
13
14namespace chromeos_update_engine {
15
16// Handles GPIO signals, which are used for indicating a lab test environment.
17// This class detects, reads and decides whether a test scenario is in effect,
18// which can be used by client code to trigger test-specific behavior. This
19// class has only static members/methods and cannot be instantiated.
20class GpioHandler {
21 public:
22 // Returns true iff GPIOs have been signaled to indicate an automated test
23 // case. This triggers a discovery and reading of the dutflaga/b GPIOs.
24 static bool IsGpioSignalingTest();
25
26 private:
27 // This class cannot be instantiated.
28 GpioHandler() {}
29
30 // Enumerator for dutflag GPIOs.
31 enum DutflagGpioId {
32 kDutflagaGpio,
33 kDutflagbGpio,
34 };
35
36 // Gets the fully qualified sysfs name of a dutflag device. |udev| is a live
37 // libudev instance; |gpio_dutflag_str| is the identifier for the requested
38 // dutflag GPIO. The output is stored in the string pointed to by
39 // |dutflag_dev_name_p|. Returns true upon success, false otherwise.
40 static bool GetDutflagGpioDevName(struct udev* udev,
41 const std::string& gpio_dutflag_str,
42 const char** dutflag_dev_name_p);
43
44 // Gets the dut_flaga/b GPIO device names and copies them into the two string
45 // arguments, respectively. A string pointer may be null, in which case
46 // discovery will not be attempted for the corresponding device. The function
47 // caches these strings, which are assumed to be hardware constants. Returns
48 // true upon success, false otherwise.
49 static bool GetDutflagGpioDevNames(std::string* dutflaga_dev_name_p,
50 std::string* dutflagb_dev_name_p);
51
52 // Writes the dut_flaga GPIO status into its argument, where true/false stand
53 // for "on"/"off", respectively. Returns true upon success, false otherwise
54 // (in which case no value is written to |status|).
55 static bool GetDutflagaGpio(bool* status);
56
57 // Reads the value of a dut_flag GPIO |id| and stores it in |status_p|.
58 // Returns true upon success, false otherwise (which also means that the GPIO
59 // value was not stored and should not be used).
60 static bool GetDutflagGpioStatus(DutflagGpioId id, bool* status_p);
61
62 // Dutflaga/b GPIO device names.
63 static const char* dutflaga_dev_name_;
64 static const char* dutflagb_dev_name_;
65
66 DISALLOW_COPY_AND_ASSIGN(GpioHandler);
67};
68
69} // namespace chromeos_update_engine
70
71#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_GPIO_HANDLER_H__