geopm  3.1.1.dev272+gdfb40a8d
GEOPM - Global Extensible Open Power Manager
SaveControl.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 - 2024 Intel Corporation
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef SAVECONTROL_HPP_INCLUDE
7 #define SAVECONTROL_HPP_INCLUDE
8 
9 #include <memory>
10 #include <vector>
11 #include <string>
12 #include <set>
13 
14 #include "geopm_public.h"
15 
16 namespace geopm
17 {
18  class IOGroup;
19  class PlatformTopo;
20 
43  {
44  public:
47  struct m_setting_s {
49  std::string name;
55  double setting;
56  };
57  SaveControl() = default;
58  virtual ~SaveControl() = default;
70  static std::unique_ptr<SaveControl> make_unique(const std::vector<m_setting_s> &settings);
79  static std::unique_ptr<SaveControl> make_unique(const std::string &json_string);
94  static std::unique_ptr<SaveControl> make_unique(IOGroup &io_group);
99  virtual std::string json(void) const = 0;
104  virtual std::vector<m_setting_s> settings(void) const = 0;
115  virtual void write_json(const std::string &save_path) const = 0;
122  virtual void restore(IOGroup &io_group) const = 0;
123  virtual std::set<std::string> unsaved_controls(const std::set<std::string> &all_controls) const = 0;
124  };
125 
127  {
128  public:
129  SaveControlImp(const std::vector<m_setting_s> &settings);
130  SaveControlImp(const std::string &json_string);
131  SaveControlImp(IOGroup &io_group, const PlatformTopo &topo);
132  virtual ~SaveControlImp() = default;
133  std::string json(void) const override;
134  std::vector<m_setting_s> settings(void) const override;
135  void write_json(const std::string &save_path) const override;
136  void restore(IOGroup &io_group) const override;
137  std::set<std::string> unsaved_controls(const std::set<std::string> &all_controls) const override;
138 
139  static std::string json(const std::vector<m_setting_s> &settings);
140  static std::vector<m_setting_s> settings(const std::string &json_string);
141  static std::vector<m_setting_s> settings(IOGroup &io_group,
142  const PlatformTopo &topo);
143  private:
144  const std::vector<m_setting_s> m_settings;
145  const std::string m_json;
146  };
147 }
148 
149 #endif
Definition: IOGroup.hpp:21
Definition: PlatformTopo.hpp:28
Class that enables the save/restore feature for IOGroups.
Definition: SaveControl.hpp:43
virtual std::set< std::string > unsaved_controls(const std::set< std::string > &all_controls) const =0
virtual std::vector< m_setting_s > settings(void) const =0
Get saved control settings structures.
virtual void restore(IOGroup &io_group) const =0
Write all of the control settings to the platform.
virtual std::string json(void) const =0
Get saved control settings JSON.
virtual void write_json(const std::string &save_path) const =0
Write the JSON formatted settings to a file.
SaveControl()=default
virtual ~SaveControl()=default
Definition: SaveControl.hpp:127
virtual ~SaveControlImp()=default
#define GEOPM_PUBLIC
Definition: geopm_public.h:10
Definition: Agg.cpp:20
std::unique_ptr< Type > make_unique(Args &&...args)
Implementation of std::make_unique (C++14) for C++11. Note that this version will only work for non-a...
Definition: Helper.hpp:28
Structure that holds the parameters passed to the IOGroup::write_control() method.
Definition: SaveControl.hpp:47
int domain_type
Domain to apply the setting.
Definition: SaveControl.hpp:51
int domain_idx
Index of the domain to apply the setting.
Definition: SaveControl.hpp:53
std::string name
Name of the control.
Definition: SaveControl.hpp:49
double setting
Value for restoring the control.
Definition: SaveControl.hpp:55