xref: /openbmc/phosphor-pid-control/sensors/build_utils.cpp (revision cdd61349509778161dc12139e60f4dfc1953b634)
1*cdd61349SPatrick Venture /**
2*cdd61349SPatrick Venture  * Copyright 2017 Google Inc.
3*cdd61349SPatrick Venture  *
4*cdd61349SPatrick Venture  * Licensed under the Apache License, Version 2.0 (the "License");
5*cdd61349SPatrick Venture  * you may not use this file except in compliance with the License.
6*cdd61349SPatrick Venture  * You may obtain a copy of the License at
7*cdd61349SPatrick Venture  *
8*cdd61349SPatrick Venture  *     http://www.apache.org/licenses/LICENSE-2.0
9*cdd61349SPatrick Venture  *
10*cdd61349SPatrick Venture  * Unless required by applicable law or agreed to in writing, software
11*cdd61349SPatrick Venture  * distributed under the License is distributed on an "AS IS" BASIS,
12*cdd61349SPatrick Venture  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*cdd61349SPatrick Venture  * See the License for the specific language governing permissions and
14*cdd61349SPatrick Venture  * limitations under the License.
15*cdd61349SPatrick Venture  */
16*cdd61349SPatrick Venture 
17*cdd61349SPatrick Venture #include "build_utils.hpp"
18*cdd61349SPatrick Venture 
19*cdd61349SPatrick Venture namespace pid_control
20*cdd61349SPatrick Venture {
21*cdd61349SPatrick Venture 
22*cdd61349SPatrick Venture static constexpr auto external_sensor =
23*cdd61349SPatrick Venture     "/xyz/openbmc_project/extsensors/";                         // type/
24*cdd61349SPatrick Venture static constexpr auto openbmc_sensor = "/xyz/openbmc_project/"; // type/
25*cdd61349SPatrick Venture static constexpr auto sysfs = "/sys/";
26*cdd61349SPatrick Venture 
getWriteInterfaceType(const std::string & path)27*cdd61349SPatrick Venture IOInterfaceType getWriteInterfaceType(const std::string& path)
28*cdd61349SPatrick Venture {
29*cdd61349SPatrick Venture     if (path.empty() || "None" == path)
30*cdd61349SPatrick Venture     {
31*cdd61349SPatrick Venture         return IOInterfaceType::NONE;
32*cdd61349SPatrick Venture     }
33*cdd61349SPatrick Venture 
34*cdd61349SPatrick Venture     if (path.find(sysfs) != std::string::npos)
35*cdd61349SPatrick Venture     {
36*cdd61349SPatrick Venture         // A sysfs read sensor.
37*cdd61349SPatrick Venture         return IOInterfaceType::SYSFS;
38*cdd61349SPatrick Venture     }
39*cdd61349SPatrick Venture 
40*cdd61349SPatrick Venture     if (path.find(openbmc_sensor) != std::string::npos)
41*cdd61349SPatrick Venture     {
42*cdd61349SPatrick Venture         return IOInterfaceType::DBUSACTIVE;
43*cdd61349SPatrick Venture     }
44*cdd61349SPatrick Venture 
45*cdd61349SPatrick Venture     return IOInterfaceType::UNKNOWN;
46*cdd61349SPatrick Venture }
47*cdd61349SPatrick Venture 
getReadInterfaceType(const std::string & path)48*cdd61349SPatrick Venture IOInterfaceType getReadInterfaceType(const std::string& path)
49*cdd61349SPatrick Venture {
50*cdd61349SPatrick Venture     if (path.empty() || "None" == path)
51*cdd61349SPatrick Venture     {
52*cdd61349SPatrick Venture         return IOInterfaceType::NONE;
53*cdd61349SPatrick Venture     }
54*cdd61349SPatrick Venture 
55*cdd61349SPatrick Venture     if (path.find(external_sensor) != std::string::npos)
56*cdd61349SPatrick Venture     {
57*cdd61349SPatrick Venture         return IOInterfaceType::EXTERNAL;
58*cdd61349SPatrick Venture     }
59*cdd61349SPatrick Venture 
60*cdd61349SPatrick Venture     if (path.find(openbmc_sensor) != std::string::npos)
61*cdd61349SPatrick Venture     {
62*cdd61349SPatrick Venture         return IOInterfaceType::DBUSPASSIVE;
63*cdd61349SPatrick Venture     }
64*cdd61349SPatrick Venture 
65*cdd61349SPatrick Venture     if (path.find(sysfs) != std::string::npos)
66*cdd61349SPatrick Venture     {
67*cdd61349SPatrick Venture         return IOInterfaceType::SYSFS;
68*cdd61349SPatrick Venture     }
69*cdd61349SPatrick Venture 
70*cdd61349SPatrick Venture     return IOInterfaceType::UNKNOWN;
71*cdd61349SPatrick Venture }
72*cdd61349SPatrick Venture 
73*cdd61349SPatrick Venture } // namespace pid_control
74