blob: 23cffa2093f8dd6efebaa8627021df6fa0c4b53f [file] [log] [blame]
George Liu2098aa62020-05-09 11:26:35 +08001#pragma once
2
3#include <filesystem>
4#include <fstream>
5#include <set>
6#include <string>
7
8namespace phosphor
9{
10namespace led
11{
12
13namespace fs = std::filesystem;
14
15// the set of names of asserted groups, which contains the D-Bus Object path
16using SavedGroups = std::set<std::string>;
17
18/** @class Serialize
19 * @brief Store and restore groups of LEDs
20 */
21class Serialize
22{
23 public:
24 Serialize(const fs::path& path) : path(path)
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