George Liu | 2098aa6 | 2020-05-09 11:26:35 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <filesystem> |
| 4 | #include <fstream> |
| 5 | #include <set> |
| 6 | #include <string> |
| 7 | |
| 8 | namespace phosphor |
| 9 | { |
| 10 | namespace led |
| 11 | { |
| 12 | |
| 13 | namespace fs = std::filesystem; |
| 14 | |
| 15 | // the set of names of asserted groups, which contains the D-Bus Object path |
| 16 | using SavedGroups = std::set<std::string>; |
| 17 | |
| 18 | /** @class Serialize |
| 19 | * @brief Store and restore groups of LEDs |
| 20 | */ |
| 21 | class Serialize |
| 22 | { |
| 23 | public: |
George Liu | c5e0f31 | 2021-12-27 15:54:31 +0800 | [diff] [blame] | 24 | explicit Serialize(const fs::path& path) : path(path) |
George Liu | 2098aa6 | 2020-05-09 11:26:35 +0800 | [diff] [blame] | 25 | { |
| 26 | restoreGroups(); |
| 27 | } |
| 28 | |
| 29 | /** @brief Store asserted group names to SAVED_GROUPS_FILE |
| 30 | * |
| 31 | * @param [in] group - name of the group |
| 32 | * @param [in] asserted - asserted state, true or false |
| 33 | */ |
| 34 | void storeGroups(const std::string& group, bool asserted); |
| 35 | |
| 36 | /** @brief Is the group in asserted state stored in SAVED_GROUPS_FILE |
| 37 | * |
| 38 | * @param [in] objPath - The D-Bus path that hosts LED group |
| 39 | * |
| 40 | * @return - true: exist, false: does not exist |
| 41 | */ |
| 42 | bool getGroupSavedState(const std::string& objPath) const; |
| 43 | |
| 44 | private: |
| 45 | /** @brief restore asserted group names from SAVED_GROUPS_FILE |
| 46 | */ |
| 47 | void restoreGroups(); |
| 48 | |
| 49 | /** @brief the set of names of asserted groups */ |
| 50 | SavedGroups savedGroups; |
| 51 | |
| 52 | /** @brief the path of file for storing the names of asserted groups */ |
| 53 | fs::path path; |
| 54 | }; |
| 55 | |
| 56 | } // namespace led |
| 57 | } // namespace phosphor |