xref: /openbmc/phosphor-pid-control/sensors/build_utils.cpp (revision 46a755fce8dc0bdd9c0c5ea09d55d3e5494f335f)
1 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: Copyright 2017 Google Inc
3 
4 #include "build_utils.hpp"
5 
6 #include <string>
7 
8 namespace pid_control
9 {
10 
11 static constexpr auto external_sensor =
12     "/xyz/openbmc_project/extsensors/";                         // type/
13 static constexpr auto openbmc_sensor = "/xyz/openbmc_project/"; // type/
14 static constexpr auto sysfs = "/sys/";
15 
getWriteInterfaceType(const std::string & path)16 IOInterfaceType getWriteInterfaceType(const std::string& path)
17 {
18     if (path.empty() || "None" == path)
19     {
20         return IOInterfaceType::NONE;
21     }
22 
23     if (path.find(sysfs) != std::string::npos)
24     {
25         // A sysfs read sensor.
26         return IOInterfaceType::SYSFS;
27     }
28 
29     if (path.find(openbmc_sensor) != std::string::npos)
30     {
31         return IOInterfaceType::DBUSACTIVE;
32     }
33 
34     return IOInterfaceType::UNKNOWN;
35 }
36 
getReadInterfaceType(const std::string & path)37 IOInterfaceType getReadInterfaceType(const std::string& path)
38 {
39     if (path.empty() || "None" == path)
40     {
41         return IOInterfaceType::NONE;
42     }
43 
44     if (path.find(external_sensor) != std::string::npos)
45     {
46         return IOInterfaceType::EXTERNAL;
47     }
48 
49     if (path.find(openbmc_sensor) != std::string::npos)
50     {
51         return IOInterfaceType::DBUSPASSIVE;
52     }
53 
54     if (path.find(sysfs) != std::string::npos)
55     {
56         return IOInterfaceType::SYSFS;
57     }
58 
59     return IOInterfaceType::UNKNOWN;
60 }
61 
62 } // namespace pid_control
63