summaryrefslogtreecommitdiffstats
path: root/manager.hpp
blob: 10af42da9bf343aa6ecb37113d91a7fba54ca05b (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
75
76
77
78
79
80
81
82
83
84
#pragma once

#include <map>
#include <set>
#include "ledlayout.hpp"
namespace phosphor
{
namespace led
{

/** @class Manager
 *  @brief Manages group of LEDs and applies action on the elements of group
 */
class Manager
{
    public:
        /** @brief Only need the default Manager */
        Manager() = delete;
        ~Manager() = default;
        Manager(const Manager&) = delete;
        Manager& operator=(const Manager&) = delete;
        Manager(Manager&&) = delete;
        Manager& operator=(Manager&&) = delete;

        /** @brief For finding intersection */
        static bool ledComp(const phosphor::led::Layout::LedAction& left,
                            const phosphor::led::Layout::LedAction& right)
        {
            return left.name < right.name;
        }

        using group = std::set<phosphor::led::Layout::LedAction>;

        /** @brief static global map constructed at compile time */
        const std::map<std::string, group>& ledMap;

        /** @brief Refer the user supplied LED layout.
         *
         *  @param [in] ledLayout - LEDs group layout
         */
        explicit Manager(const std::map<std::string, Manager::group>& ledLayout)
                : ledMap(ledLayout)
        {
            // Nothing here
        }

        /** @brief Given a group name, applies the action on the group
         *
         *  @param[in]  path          -  dbus path of group
         *  @param[in]  assert        -  Could be true or false
         *  @param[in]  ledsAssert    -  LEDs that are to be asserted newly
         *  @param[in]  ledsDeAssert  -  LEDs that are to be Deasserted
         *  @param[in]  ledsUpdate    -  LEDs that need a transition between
         *                               different types of asserted states.
         *
         *  @return                   -  Success or exception thrown
         */
        bool setGroupState(const std::string& path, bool assert,
                           group& ledsAssert, group& ledsDeAssert,
                           group& ledsUpdate);

        /** @brief Finds the set of LEDs to operate on and executes action
         *
         *  @param[in]  ledsAssert    -  LEDs that are to be asserted newly
         *  @param[in]  ledsDeAssert  -  LEDs that are to be Deasserted
         *  @param[in]  ledsUpdate    -  LEDs that need a transition between
         *                               different types of asserted states.
         *
         *  @return: None
         */
        void driveLEDs(group& ledsAssert, group& ledsDeAssert,
                       group& ledsUpdate);

    private:
        /** @brief Pointers to groups that are in asserted state */
        std::set<const group*> assertedGroups;

        /** @brief Contains the LEDs that are in asserted state */
        group currentState;

};

} // namespace led
} // namespace phosphor
OpenPOWER on IntegriCloud