1 /** 2 * Copyright © 2017 IBM Corporation 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 #include <phosphor-logging/log.hpp> 17 #include <vector> 18 #include "fan_enclosure.hpp" 19 #include "fan_detect_defs.hpp" 20 #include "sdbusplus.hpp" 21 #include "tach_sensor.hpp" 22 23 24 int main(void) 25 { 26 using namespace phosphor::fan; 27 using namespace std::literals::string_literals; 28 using namespace phosphor::logging; 29 30 std::vector<std::unique_ptr<phosphor::fan::presence::FanEnclosure>> fans; 31 32 for (auto const& detectMap: fanDetectMap) 33 { 34 if (detectMap.first == "tach") 35 { 36 for (auto const& fanProp: detectMap.second) 37 { 38 auto path = "/xyz/openbmc_project/inventory"s + 39 std::get<0>(fanProp); 40 41 auto state = presence::UNKNOWN; 42 try 43 { 44 auto boolstate = util::SDBusPlus::getProperty<bool>( 45 path, 46 "xyz.openbmc_project.Inventory.Item"s, 47 "Present"s); 48 state = boolstate ? 49 presence::PRESENT : presence::NOT_PRESENT; 50 } 51 catch (const std::exception& err) 52 { 53 log<level::INFO>(err.what()); 54 } 55 56 auto fan = std::make_unique< 57 phosphor::fan::presence::FanEnclosure>(fanProp, 58 state); 59 for (auto const &fanSensor: std::get<2>(fanProp)) 60 { 61 auto initialSpeed = static_cast<int64_t>(0); 62 auto sensorPath = 63 "/xyz/openbmc_project/sensors/fan_tach/"s + 64 fanSensor; 65 initialSpeed = util::SDBusPlus::getProperty<int64_t>( 66 sensorPath, 67 "xyz.openbmc_project.Sensor.Value"s, 68 "Value"s); 69 70 auto sensor = std::make_unique< 71 phosphor::fan::presence::TachSensor>(fanSensor, 72 *fan, 73 initialSpeed != 0); 74 fan->addSensor(std::move(sensor)); 75 } 76 77 fan->updInventory(); 78 fans.push_back(std::move(fan)); 79 } 80 } 81 } 82 83 while (true) 84 { 85 // Respond to dbus signals 86 util::SDBusPlus::getBus().process_discard(); 87 util::SDBusPlus::getBus().wait(); 88 } 89 return 0; 90 } 91