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