summaryrefslogtreecommitdiffstats
path: root/targets.hpp
blob: 86058ca27d8593df23c2d10271c27bda5f4b8e7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#pragma once

#include <experimental/filesystem>
#include "fan_speed.hpp"

/** @class Targets
 *  @brief Target type traits.
 *
 *  @tparam T - The target type.
 */
template <typename T>
struct Targets
{
    static void fail()
    {
        static_assert(sizeof(Targets) == -1, "Unsupported Target type");
    }
};

/**@brief Targets specialization for fan speed. */
template <>
struct Targets<hwmon::FanSpeed>
{
    static constexpr InterfaceType type = InterfaceType::FAN_SPEED;
};

/** @brief addTarget
 *
 *  Creates the target type interface
 *
 *  @tparam T - The target type
 *
 *  @param[in] sensor - A sensor type and name
 *  @param[in] hwmonRoot - The root hwmon path
 *  @param[in] instance - The target instance name
 *  @param[in] info - The sdbusplus server connection and interfaces
 *
 *  @return A shared pointer to the target interface object
 *          Will be empty if no interface was created
 */
template <typename T>
std::shared_ptr<T> addTarget(const SensorSet::key_type& sensor,
                             const std::string& hwmonRoot,
                             const std::string& instance,
                             ObjectInfo& info)
{
    std::shared_ptr<T> target;
    namespace fs = std::experimental::filesystem;
    static constexpr bool deferSignals = true;

    auto& bus = *std::get<sdbusplus::bus::bus*>(info);
    auto& obj = std::get<Object>(info);
    auto& objPath = std::get<std::string>(info);

    // Check if target sysfs file exists
    auto targetPath = hwmonRoot + '/' + instance;
    auto sysfsFullPath = sysfs::make_sysfs_path(targetPath,
                                                sensor.first,
                                                sensor.second,
                                                hwmon::entry::target);
    if (fs::exists(sysfsFullPath))
    {
        target = std::make_shared<T>(hwmonRoot,
                                     instance,
                                     sensor.second,
                                     bus,
                                     objPath.c_str(),
                                     deferSignals);
        auto type = Targets<T>::type;
        obj[type] = target;
    }

    return target;
}
OpenPOWER on IntegriCloud