Enable gtest for testing LED set operations
This patchset enables gtest to allow different combinations
of LED set operations to be verified at build time.
Change-Id: I9c2ddf82c2e23be911233b23037ee44e3ce301db
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
diff --git a/manager.hpp b/manager.hpp
index 9e32216..10af42d 100644
--- a/manager.hpp
+++ b/manager.hpp
@@ -2,6 +2,7 @@
#include <map>
#include <set>
+#include "ledlayout.hpp"
namespace phosphor
{
namespace led
@@ -13,61 +14,62 @@
class Manager
{
public:
- /** @brief Define possible actions on a given LED.
- * For the BLINK operation, follow 50-50 duty cycle
- */
- enum Action
- {
- Off,
- On,
- Blink,
- };
-
/** @brief Only need the default Manager */
- Manager() = default;
+ Manager() = delete;
~Manager() = default;
Manager(const Manager&) = delete;
Manager& operator=(const Manager&) = delete;
Manager(Manager&&) = delete;
Manager& operator=(Manager&&) = delete;
- /** @brief Name of the LED and it's proposed action.
- * This structure is supplied as configuration at build time
- */
- struct LedAction
- {
- std::string name;
- Action action;
-
- // Needed for inserting elements into sets
- bool operator<(const LedAction& right) const
- {
- if (name == right.name)
- {
- return action < right.action;
- }
- return name < right.name;
- }
- };
-
/** @brief For finding intersection */
- static bool ledComp(const LedAction& left, const LedAction& right)
+ static bool ledComp(const phosphor::led::Layout::LedAction& left,
+ const phosphor::led::Layout::LedAction& right)
{
return left.name < right.name;
}
- using group = std::set<LedAction>;
+ using group = std::set<phosphor::led::Layout::LedAction>;
/** @brief static global map constructed at compile time */
- static const std::map<std::string, group> ledMap;
+ 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
- * @return - Success or exception thrown
+ * @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);
+ 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 */
@@ -76,11 +78,6 @@
/** @brief Contains the LEDs that are in asserted state */
group currentState;
- /** @brief Finds the set of LEDs to operate on and executes action
- *
- * @return: None
- */
- void driveLEDs();
};
} // namespace led