blob: 18892568c79dcd15fffdb43cc9ba0ac6d47bf7c3 [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
17#include <string>
18
19#include "util.hpp"
20
21
22static constexpr auto external_sensor =
23 "/xyz/openbmc_project/extsensors/"; // type/
24static constexpr auto openbmc_sensor = "/xyz/openbmc_project/"; // type/
25static constexpr auto sysfs = "/sys/";
26
27
28IOInterfaceType GetWriteInterfaceType(const std::string& path)
29{
Patrick Venturee6206562018-03-08 15:36:53 -080030 if (path.empty() || "None" == path)
31 {
32 return IOInterfaceType::NONE;
33 }
34
35 if (path.find(sysfs) != std::string::npos)
36 {
37 // A sysfs read sensor.
38 return IOInterfaceType::SYSFS;
39 }
40
41 return IOInterfaceType::UNKNOWN;
42}
43
44IOInterfaceType GetReadInterfaceType(const std::string& path)
45{
Patrick Venturee6206562018-03-08 15:36:53 -080046 if (path.empty() || "None" == path)
47 {
48 return IOInterfaceType::NONE;
49 }
50
51 if (path.find(external_sensor) != std::string::npos)
52 {
53 return IOInterfaceType::EXTERNAL;
54 }
55
56 if (path.find(openbmc_sensor) != std::string::npos)
57 {
58 return IOInterfaceType::DBUSPASSIVE;
59 }
60
61 if (path.find(sysfs) != std::string::npos)
62 {
63 return IOInterfaceType::SYSFS;
64 }
65
66 return IOInterfaceType::UNKNOWN;
67}
68