blob: ec60d7ab52f4cd5f59af06ce4c481082c929ae3c [file] [log] [blame]
Patrick Venturee6206562018-03-08 15:36:53 -08001/**
2 * Copyright 2017 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Patrick Venturee6206562018-03-08 15:36:53 -080017#include "util.hpp"
18
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070019#include <string>
Patrick Venturee6206562018-03-08 15:36:53 -080020
21static constexpr auto external_sensor =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070022 "/xyz/openbmc_project/extsensors/"; // type/
Patrick Venturee6206562018-03-08 15:36:53 -080023static constexpr auto openbmc_sensor = "/xyz/openbmc_project/"; // type/
24static constexpr auto sysfs = "/sys/";
25
Patrick Venture7af157b2018-10-30 11:24:40 -070026IOInterfaceType getWriteInterfaceType(const std::string& path)
Patrick Venturee6206562018-03-08 15:36:53 -080027{
Patrick Venturee6206562018-03-08 15:36:53 -080028 if (path.empty() || "None" == path)
29 {
30 return IOInterfaceType::NONE;
31 }
32
33 if (path.find(sysfs) != std::string::npos)
34 {
35 // A sysfs read sensor.
36 return IOInterfaceType::SYSFS;
37 }
38
Patrick Venture081b0352019-07-15 11:05:17 -070039 if (path.find(openbmc_sensor) != std::string::npos)
James Feist7136a5a2018-07-19 09:52:05 -070040 {
41 return IOInterfaceType::DBUSACTIVE;
42 }
43
Patrick Venturee6206562018-03-08 15:36:53 -080044 return IOInterfaceType::UNKNOWN;
45}
46
Patrick Venture7af157b2018-10-30 11:24:40 -070047IOInterfaceType getReadInterfaceType(const std::string& path)
Patrick Venturee6206562018-03-08 15:36:53 -080048{
Patrick Venturee6206562018-03-08 15:36:53 -080049 if (path.empty() || "None" == path)
50 {
51 return IOInterfaceType::NONE;
52 }
53
54 if (path.find(external_sensor) != std::string::npos)
55 {
56 return IOInterfaceType::EXTERNAL;
57 }
58
59 if (path.find(openbmc_sensor) != std::string::npos)
60 {
61 return IOInterfaceType::DBUSPASSIVE;
62 }
63
64 if (path.find(sysfs) != std::string::npos)
65 {
66 return IOInterfaceType::SYSFS;
67 }
68
69 return IOInterfaceType::UNKNOWN;
70}