Matthew Barth | bf7b7b1 | 2017-03-07 15:46:59 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <experimental/filesystem> |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame^] | 4 | #include "fan_speed.hpp" |
Matthew Barth | bf7b7b1 | 2017-03-07 15:46:59 -0600 | [diff] [blame] | 5 | |
| 6 | /** @class Targets |
| 7 | * @brief Target type traits. |
| 8 | * |
| 9 | * @tparam T - The target type. |
| 10 | */ |
| 11 | template <typename T> |
| 12 | struct Targets |
| 13 | { |
| 14 | static void fail() |
| 15 | { |
| 16 | static_assert(sizeof(Targets) == -1, "Unsupported Target type"); |
| 17 | } |
| 18 | }; |
| 19 | |
| 20 | /**@brief Targets specialization for fan speed. */ |
| 21 | template <> |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame^] | 22 | struct Targets<hwmon::FanSpeed> |
Matthew Barth | bf7b7b1 | 2017-03-07 15:46:59 -0600 | [diff] [blame] | 23 | { |
| 24 | static constexpr InterfaceType type = InterfaceType::FAN_SPEED; |
Matthew Barth | bf7b7b1 | 2017-03-07 15:46:59 -0600 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | /** @brief addTarget |
| 28 | * |
| 29 | * Creates the target type interface |
| 30 | * |
| 31 | * @tparam T - The target type |
| 32 | * |
| 33 | * @param[in] sensor - A sensor type and name |
| 34 | * @param[in] hwmonRoot - The root hwmon path |
| 35 | * @param[in] instance - The target instance name |
| 36 | * @param[in] info - The sdbusplus server connection and interfaces |
| 37 | */ |
| 38 | template <typename T> |
| 39 | void addTarget(const SensorSet::key_type& sensor, |
| 40 | const std::string& hwmonRoot, |
| 41 | const std::string& instance, |
| 42 | ObjectInfo& info) |
| 43 | { |
| 44 | namespace fs = std::experimental::filesystem; |
| 45 | static constexpr bool deferSignals = true; |
| 46 | |
| 47 | auto& bus = *std::get<sdbusplus::bus::bus*>(info); |
| 48 | auto& obj = std::get<Object>(info); |
| 49 | auto& objPath = std::get<std::string>(info); |
| 50 | |
| 51 | // Check if target sysfs file exists |
| 52 | auto targetPath = hwmonRoot + '/' + instance; |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame^] | 53 | auto sysfsFullPath = make_sysfs_path(targetPath, |
| 54 | sensor.first, |
| 55 | sensor.second, |
| 56 | hwmon::entry::target); |
| 57 | if (fs::exists(sysfsFullPath)) |
Matthew Barth | bf7b7b1 | 2017-03-07 15:46:59 -0600 | [diff] [blame] | 58 | { |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame^] | 59 | auto iface = std::make_shared<T>(hwmonRoot, |
| 60 | instance, |
| 61 | sensor.second, |
| 62 | bus, |
| 63 | objPath.c_str(), |
| 64 | deferSignals); |
Matthew Barth | bf7b7b1 | 2017-03-07 15:46:59 -0600 | [diff] [blame] | 65 | auto type = Targets<T>::type; |
| 66 | obj[type] = iface; |
| 67 | } |
| 68 | } |