blob: a11bc5efd3fd1ccc3bcf4888c14a4c910869d423 [file] [log] [blame]
Matthew Bartha227a162020-08-05 10:51:45 -05001/**
2 * Copyright © 2020 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#pragma once
17
Matthew Barthd9cb63b2021-03-24 14:36:49 -050018#include "action.hpp"
Matthew Barth44ab7692021-03-26 11:40:10 -050019#include "config_base.hpp"
20#include "event.hpp"
Matthew Barthd9cb63b2021-03-24 14:36:49 -050021#include "group.hpp"
Matthew Barthacd737c2021-03-04 11:04:01 -060022#include "json_config.hpp"
Matthew Barth48f44da2021-05-27 15:43:34 -050023#include "power_state.hpp"
Matthew Barth06764942021-03-04 09:28:40 -060024#include "profile.hpp"
Matthew Barth9403a212021-05-17 09:31:50 -050025#include "sdbusplus.hpp"
Matthew Barthacd737c2021-03-04 11:04:01 -060026#include "zone.hpp"
Matthew Barth06764942021-03-04 09:28:40 -060027
Matthew Barth68ac0042021-06-01 15:38:36 -050028#include <fmt/format.h>
29
Matthew Bartha227a162020-08-05 10:51:45 -050030#include <nlohmann/json.hpp>
Matthew Barth68ac0042021-06-01 15:38:36 -050031#include <phosphor-logging/log.hpp>
Matthew Bartha227a162020-08-05 10:51:45 -050032#include <sdbusplus/bus.hpp>
Matthew Barth1542fb52021-06-10 14:09:09 -050033#include <sdbusplus/server/manager.hpp>
Matthew Barth06764942021-03-04 09:28:40 -060034#include <sdeventplus/event.hpp>
Matt Spinler2fc0a352021-10-04 15:10:57 -050035#include <sdeventplus/source/event.hpp>
Matthew Barthd9cb63b2021-03-24 14:36:49 -050036#include <sdeventplus/utility/timer.hpp>
37
38#include <chrono>
39#include <map>
40#include <memory>
41#include <optional>
42#include <tuple>
43#include <utility>
44#include <vector>
Matthew Bartha227a162020-08-05 10:51:45 -050045
46namespace phosphor::fan::control::json
47{
48
49using json = nlohmann::json;
Matthew Barth68ac0042021-06-01 15:38:36 -050050using namespace phosphor::logging;
Matthew Bartha227a162020-08-05 10:51:45 -050051
Matthew Barthacd737c2021-03-04 11:04:01 -060052/* Application name to be appended to the path for loading a JSON config file */
53constexpr auto confAppName = "control";
54
Matthew Barthd9cb63b2021-03-24 14:36:49 -050055/* Type of timers supported */
56enum class TimerType
57{
58 oneshot,
59 repeating,
60};
61/**
62 * Package of data required when a timer expires
63 * Tuple constructed of:
64 * std::string = Timer package unique identifier
Matthew Barthd9cb63b2021-03-24 14:36:49 -050065 * std::vector<std::unique_ptr<ActionBase>> = List of pointers to actions
66 * that run when the timer expires
Matt Spinlerade0c372021-10-28 16:09:44 -050067 * const std::vector<Group> = List of groups
68 * bool = If groups should be preloaded before actions are run
Matthew Barthd9cb63b2021-03-24 14:36:49 -050069 */
Matthew Barth00f6aa02021-04-09 10:49:47 -050070using TimerPkg =
Matt Spinlerade0c372021-10-28 16:09:44 -050071 std::tuple<std::string, std::vector<std::unique_ptr<ActionBase>>&,
72 const std::vector<Group>&, bool>;
Matthew Barthd9cb63b2021-03-24 14:36:49 -050073/**
74 * Data associated with a running timer that's used when it expires
75 * Pair constructed of:
76 * TimerType = Type of timer to manage expired timer instances
77 * TimerPkg = Package of data required when the timer expires
78 */
79using TimerData = std::pair<TimerType, TimerPkg>;
80/* Dbus event timer */
81using Timer = sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>;
82
Matthew Barthebabc042021-05-13 15:38:58 -050083/* Dbus signal object */
84constexpr auto Path = 0;
85constexpr auto Intf = 1;
86constexpr auto Prop = 2;
87using SignalObject = std::tuple<std::string, std::string, std::string>;
88/* Dbus signal actions */
Matthew Barthc3a69082021-11-15 14:32:48 -060089using SignalActions =
90 std::vector<std::reference_wrapper<std::unique_ptr<ActionBase>>>;
Matthew Barthebabc042021-05-13 15:38:58 -050091/**
92 * Signal handler function that handles parsing a signal's message for a
93 * particular signal object and stores the results in the manager
94 */
95using SignalHandler = std::function<bool(sdbusplus::message::message&,
96 const SignalObject&, Manager&)>;
97/**
98 * Package of data required when a signal is received
99 * Tuple constructed of:
100 * SignalHandler = Signal handler function
101 * SignalObject = Dbus signal object
102 * SignalActions = List of actions that are run when the signal is received
103 */
104using SignalPkg = std::tuple<SignalHandler, SignalObject, SignalActions>;
105/**
106 * Data associated to a subscribed signal
107 * Tuple constructed of:
Matthew Barthc024d782021-11-09 16:15:49 -0600108 * std::unique_ptr<std::vector<SignalPkg>> =
109 * Pointer to list of the signal's packages
Patrick Williams3ea9ec22021-11-19 12:21:08 -0600110 * std::unique_ptr<sdbusplus::bus::match_t> =
Matthew Barthebabc042021-05-13 15:38:58 -0500111 * Pointer to match holding the subscription to a signal
112 */
Matthew Barthc024d782021-11-09 16:15:49 -0600113using SignalData = std::tuple<std::unique_ptr<std::vector<SignalPkg>>,
Patrick Williams3ea9ec22021-11-19 12:21:08 -0600114 std::unique_ptr<sdbusplus::bus::match_t>>;
Matthew Barthebabc042021-05-13 15:38:58 -0500115
Matthew Bartha227a162020-08-05 10:51:45 -0500116/**
Mike Capps1a19ead2021-10-22 09:15:14 -0400117 * Package of data from a D-Bus call to get managed objects
118 * Tuple constructed of:
119 * std::map<Path, // D-Bus Path
120 * std::map<Intf, // D-Bus Interface
121 * std::map<Property, // D-Bus Property
122 * std::variant>>> // Variant value of that property
123 */
124using Path_v = sdbusplus::message::object_path;
125using Intf_v = std::string;
126using Prop_v = std::string;
127using ManagedObjects =
128 std::map<Path_v, std::map<Intf_v, std::map<Prop_v, PropertyVariantType>>>;
129
130/**
Matthew Bartha227a162020-08-05 10:51:45 -0500131 * @class Manager - Represents the fan control manager's configuration
132 *
133 * A fan control manager configuration is optional, therefore the "manager.json"
134 * file is also optional. The manager configuration is used to populate
135 * fan control's manager parameters which are used in how the application
136 * operates, not in how the fans are controlled.
137 *
138 * When no manager configuration exists, the fan control application starts,
139 * processes any configured events and then begins controlling fans according
140 * to those events.
141 */
142class Manager
143{
144 public:
145 Manager() = delete;
146 Manager(const Manager&) = delete;
147 Manager(Manager&&) = delete;
148 Manager& operator=(const Manager&) = delete;
149 Manager& operator=(Manager&&) = delete;
150 ~Manager() = default;
151
152 /**
153 * Constructor
154 * Parses and populates the fan control manager attributes from a json file
155 *
Matthew Barth06764942021-03-04 09:28:40 -0600156 * @param[in] event - sdeventplus event loop
Matthew Bartha227a162020-08-05 10:51:45 -0500157 */
Matthew Barth9403a212021-05-17 09:31:50 -0500158 Manager(const sdeventplus::Event& event);
Matthew Bartha227a162020-08-05 10:51:45 -0500159
160 /**
Matthew Barthe91ac862021-05-25 16:22:17 -0500161 * @brief Callback function to handle receiving a HUP signal to reload the
162 * JSON configurations.
163 */
164 void sighupHandler(sdeventplus::source::Signal&,
165 const struct signalfd_siginfo*);
166
167 /**
Matt Spinler2fc0a352021-10-04 15:10:57 -0500168 * @brief Callback function to handle receiving a USR1 signal to dump
169 * the flight recorder.
170 */
171 void sigUsr1Handler(sdeventplus::source::Signal&,
172 const struct signalfd_siginfo*);
173
174 /**
Matthew Barthacd737c2021-03-04 11:04:01 -0600175 * @brief Get the active profiles of the system where an empty list
176 * represents that only configuration entries without a profile defined will
177 * be loaded.
178 *
179 * @return - The list of active profiles
180 */
181 static const std::vector<std::string>& getActiveProfiles();
182
183 /**
184 * @brief Load the configuration of a given JSON class object based on the
185 * active profiles
186 *
Matthew Barthacd737c2021-03-04 11:04:01 -0600187 * @param[in] isOptional - JSON configuration file is optional or not
Matthew Barth603ef162021-03-24 15:34:53 -0500188 * @param[in] args - Arguments to be forwarded to each instance of `T`
Matthew Barthe6d1f782021-05-14 12:52:20 -0500189 * (*Note that a sdbusplus bus object is required as the first argument)
Matthew Barthacd737c2021-03-04 11:04:01 -0600190 *
191 * @return Map of configuration entries
192 * Map of configuration keys to their corresponding configuration object
193 */
Matthew Barth603ef162021-03-24 15:34:53 -0500194 template <typename T, typename... Args>
Matthew Barthe6d1f782021-05-14 12:52:20 -0500195 static std::map<configKey, std::unique_ptr<T>> getConfig(bool isOptional,
196 Args&&... args)
Matthew Barthacd737c2021-03-04 11:04:01 -0600197 {
198 std::map<configKey, std::unique_ptr<T>> config;
199
Matthew Barth9403a212021-05-17 09:31:50 -0500200 auto confFile =
201 fan::JsonConfig::getConfFile(util::SDBusPlus::getBus(), confAppName,
202 T::confFileName, isOptional);
Matthew Barthacd737c2021-03-04 11:04:01 -0600203 if (!confFile.empty())
204 {
205 for (const auto& entry : fan::JsonConfig::load(confFile))
206 {
207 if (entry.contains("profiles"))
208 {
209 std::vector<std::string> profiles;
210 for (const auto& profile : entry["profiles"])
211 {
212 profiles.emplace_back(
213 profile.template get<std::string>());
214 }
215 // Do not create the object if its profiles are not in the
216 // list of active profiles
Matthew Barth42428052021-03-30 12:50:59 -0500217 if (!profiles.empty() &&
218 !std::any_of(profiles.begin(), profiles.end(),
Matthew Barthacd737c2021-03-04 11:04:01 -0600219 [](const auto& name) {
220 return std::find(
221 getActiveProfiles().begin(),
222 getActiveProfiles().end(),
223 name) !=
224 getActiveProfiles().end();
225 }))
226 {
227 continue;
228 }
229 }
Matthew Barth603ef162021-03-24 15:34:53 -0500230 auto obj =
231 std::make_unique<T>(entry, std::forward<Args>(args)...);
Matthew Barthacd737c2021-03-04 11:04:01 -0600232 config.emplace(
233 std::make_pair(obj->getName(), obj->getProfiles()),
234 std::move(obj));
235 }
Matthew Barth68ac0042021-06-01 15:38:36 -0500236 log<level::INFO>(
237 fmt::format("Configuration({}) loaded successfully",
238 T::confFileName)
239 .c_str());
Matthew Barthacd737c2021-03-04 11:04:01 -0600240 }
241 return config;
242 }
243
244 /**
Matthew Barth0206c722021-03-30 15:20:05 -0500245 * @brief Check if the given input configuration key matches with another
246 * configuration key that it's to be included in
247 *
248 * @param[in] input - Config key to be included in another config object
249 * @param[in] comp - Config key of the config object to compare with
250 *
251 * @return Whether the configuration object should be included
252 */
253 static bool inConfig(const configKey& input, const configKey& comp);
254
255 /**
Matthew Barth12cb1252021-03-08 16:47:30 -0600256 * @brief Check if the given path and inteface is owned by a dbus service
257 *
258 * @param[in] path - Dbus object path
259 * @param[in] intf - Dbus object interface
260 *
261 * @return - Whether the service has an owner for the given object path and
262 * interface
263 */
264 static bool hasOwner(const std::string& path, const std::string& intf);
265
266 /**
Matthew Barth4ca87fa2021-04-14 11:31:13 -0500267 * @brief Sets the dbus service owner state of a given object
268 *
269 * @param[in] path - Dbus object path
270 * @param[in] serv - Dbus service name
271 * @param[in] intf - Dbus object interface
272 * @param[in] isOwned - Dbus service owner state
273 */
274 void setOwner(const std::string& path, const std::string& serv,
275 const std::string& intf, bool isOwned);
276
277 /**
278 * @brief Add a set of services for a path and interface by retrieving all
279 * the path subtrees to the given depth from root for the interface
280 *
Matthew Barth4ca87fa2021-04-14 11:31:13 -0500281 * @param[in] intf - Interface to add services for
282 * @param[in] depth - Depth of tree traversal from root path
283 *
284 * @throws - DBusMethodError
285 * Throws a DBusMethodError when the `getSubTree` method call fails
286 */
Matthew Barth98f6fc12021-04-16 10:48:37 -0500287 static void addServices(const std::string& intf, int32_t depth);
Matthew Barth4ca87fa2021-04-14 11:31:13 -0500288
289 /**
290 * @brief Get the service for a given path and interface from cached
291 * dataset and attempt to add all the services for the given path/interface
292 * when it's not found
293 *
294 * @param[in] path - Path to get service for
295 * @param[in] intf - Interface to get service for
296 *
297 * @return - The now cached service name
298 *
299 * @throws - DBusMethodError
300 * Ripples up a DBusMethodError exception from calling addServices
301 */
302 static const std::string& getService(const std::string& path,
303 const std::string& intf);
304
305 /**
Matthew Barthf41e9472021-05-13 16:38:06 -0500306 * @brief Get all the object paths for a given service and interface from
307 * the cached dataset and try to add all the services for the given
308 * interface when no paths are found and then attempt to get all the object
309 * paths again
310 *
311 * @param[in] serv - Service name to get paths for
312 * @param[in] intf - Interface to get paths for
313 *
314 * @return The cached object paths
315 */
316 std::vector<std::string> getPaths(const std::string& serv,
317 const std::string& intf);
318
319 /**
320 * @brief Add objects to the cached dataset by first using
321 * `getManagedObjects` for the same service providing the given path and
322 * interface or just add the single object of the given path, interface, and
323 * property if that fails.
324 *
325 * @param[in] path - Dbus object's path
326 * @param[in] intf - Dbus object's interface
327 * @param[in] prop - Dbus object's property
328 *
329 * @throws - DBusMethodError
330 * Throws a DBusMethodError when the the service is failed to be found or
331 * when the `getManagedObjects` method call fails
332 */
333 void addObjects(const std::string& path, const std::string& intf,
334 const std::string& prop);
335
336 /**
337 * @brief Get an object's property value
338 *
339 * @param[in] path - Dbus object's path
340 * @param[in] intf - Dbus object's interface
341 * @param[in] prop - Dbus object's property
342 */
343 const std::optional<PropertyVariantType>
344 getProperty(const std::string& path, const std::string& intf,
345 const std::string& prop);
346
347 /**
Matthew Barthbaeeb8f2021-05-13 16:03:54 -0500348 * @brief Set/update an object's property value
349 *
350 * @param[in] path - Dbus object's path
351 * @param[in] intf - Dbus object's interface
352 * @param[in] prop - Dbus object's property
353 * @param[in] value - Dbus object's property value
354 */
355 void setProperty(const std::string& path, const std::string& intf,
Mike Capps1a19ead2021-10-22 09:15:14 -0400356 const std::string& prop, PropertyVariantType value);
Matthew Barthbaeeb8f2021-05-13 16:03:54 -0500357
358 /**
Matthew Barthc2691402021-05-13 16:20:32 -0500359 * @brief Remove an object's interface
360 *
361 * @param[in] path - Dbus object's path
362 * @param[in] intf - Dbus object's interface
363 */
364 inline void removeInterface(const std::string& path,
365 const std::string& intf)
366 {
367 auto itPath = _objects.find(path);
368 if (itPath != std::end(_objects))
369 {
370 _objects[path].erase(intf);
371 }
372 }
373
374 /**
Matthew Barth07fecfc2021-01-29 09:04:43 -0600375 * @brief Get the object's property value as a variant
376 *
377 * @param[in] path - Path of the object containing the property
378 * @param[in] intf - Interface name containing the property
379 * @param[in] prop - Name of property
380 *
381 * @return - The object's property value as a variant
382 */
383 static inline auto getObjValueVariant(const std::string& path,
384 const std::string& intf,
385 const std::string& prop)
386 {
387 return _objects.at(path).at(intf).at(prop);
388 };
389
390 /**
Matthew Barthd9cb63b2021-03-24 14:36:49 -0500391 * @brief Add a dbus timer
392 *
393 * @param[in] type - Type of timer
394 * @param[in] interval - Timer interval in microseconds
395 * @param[in] pkg - Packaged data for when timer expires
396 */
397 void addTimer(const TimerType type,
398 const std::chrono::microseconds interval,
399 std::unique_ptr<TimerPkg> pkg);
400
401 /**
402 * @brief Callback when a timer expires
403 *
404 * @param[in] data - Data to be used when the timer expired
405 */
406 void timerExpired(TimerData& data);
407
408 /**
Matthew Barthebabc042021-05-13 15:38:58 -0500409 * @brief Get the signal data for a given match string
410 *
411 * @param[in] sigMatch - Signal match string
412 *
413 * @return - Reference to the signal data for the given match string
414 */
415 std::vector<SignalData>& getSignal(const std::string& sigMatch)
416 {
417 return _signals[sigMatch];
418 }
419
420 /**
421 * @brief Handle receiving signals
422 *
423 * @param[in] msg - Signal message containing the signal's data
424 * @param[in] pkgs - Signal packages associated to the signal being handled
425 */
426 void handleSignal(sdbusplus::message::message& msg,
Matthew Barthc024d782021-11-09 16:15:49 -0600427 const std::vector<SignalPkg>* pkgs);
Matthew Barthebabc042021-05-13 15:38:58 -0500428
429 /**
Matthew Bartheebde062021-04-14 12:48:52 -0500430 * @brief Get the sdbusplus bus object
431 */
432 inline auto& getBus()
433 {
434 return _bus;
435 }
436
437 /**
Matthew Barth48f44da2021-05-27 15:43:34 -0500438 * @brief Is the power state on
439 *
440 * @return Current power state of the system
441 */
442 inline bool isPowerOn() const
443 {
444 return _powerState->isPowerOn();
445 }
446
Matthew Barth3770a1d2021-06-10 15:09:37 -0500447 /**
448 * @brief Load all the fan control JSON configuration files
449 *
450 * This is where all the fan control JSON configuration files are parsed and
451 * loaded into their associated objects. Anything that needs to be done when
452 * the Manager object is constructed or handling a SIGHUP to reload the
453 * configurations needs to be done here.
454 */
455 void load();
456
Matt Spinlerd76351b2021-08-05 16:23:09 -0500457 /**
458 * @brief Sets a value in the parameter map.
459 *
460 * @param[in] name - The parameter name
461 * @param[in] value - The parameter value
462 */
463 static void setParameter(const std::string& name,
464 const PropertyVariantType& value)
465 {
466 _parameters[name] = value;
467 }
468
469 /**
470 * @brief Returns a value from the parameter map
471 *
472 * @param[in] name - The parameter name
473 *
474 * @return The parameter value, or std::nullopt if not found
475 */
476 static std::optional<PropertyVariantType>
477 getParameter(const std::string& name)
478 {
479 auto it = _parameters.find(name);
480 if (it != _parameters.end())
481 {
482 return it->second;
483 }
484
485 return std::nullopt;
486 }
487
488 /**
489 * @brief Deletes a parameter from the parameter map
490 *
491 * @param[in] name - The parameter name
492 */
493 static void deleteParameter(const std::string& name)
494 {
495 _parameters.erase(name);
496 }
497
Matt Spinler7787def2021-10-14 16:33:16 -0500498 /* The name of the dump file */
499 static const std::string dumpFile;
500
Matthew Bartha227a162020-08-05 10:51:45 -0500501 private:
Mike Capps1a19ead2021-10-22 09:15:14 -0400502 /**
503 * @brief Helper to detect when a property's double contains a NaN
504 * (not-a-number) value.
505 *
506 * @param[in] value - The property to test
507 */
508 static bool PropertyContainsNan(const PropertyVariantType& value)
509 {
510 return (std::holds_alternative<double>(value) &&
511 std::isnan(std::get<double>(value)));
512 }
513
514 /**
515 * @brief Insert managed objects into cache, but filter out properties
516 * containing unwanted NaN (not-a-number) values.
517 *
518 * @param[in] ref - The map of ManagedObjects to insert into cache
519 */
520 void insertFilteredObjects(ManagedObjects& ref);
521
Matthew Barth1542fb52021-06-10 14:09:09 -0500522 /* The sdbusplus bus object to use */
Matthew Barthacd737c2021-03-04 11:04:01 -0600523 sdbusplus::bus::bus& _bus;
524
Matthew Barth1542fb52021-06-10 14:09:09 -0500525 /* The sdeventplus even loop to use */
Matthew Barthacd737c2021-03-04 11:04:01 -0600526 sdeventplus::Event _event;
527
Matthew Barth1542fb52021-06-10 14:09:09 -0500528 /* The sdbusplus manager object to set the ObjectManager interface */
529 sdbusplus::server::manager::manager _mgr;
530
Matthew Barth3770a1d2021-06-10 15:09:37 -0500531 /* Whether loading the config files is allowed or not */
532 bool _loadAllowed;
533
Matthew Barth48f44da2021-05-27 15:43:34 -0500534 /* The system's power state determination object */
535 std::unique_ptr<PowerState> _powerState;
536
Matthew Barth06764942021-03-04 09:28:40 -0600537 /* List of profiles configured */
Matthew Barthacd737c2021-03-04 11:04:01 -0600538 std::map<configKey, std::unique_ptr<Profile>> _profiles;
Matthew Barth06764942021-03-04 09:28:40 -0600539
540 /* List of active profiles */
Matthew Barthacd737c2021-03-04 11:04:01 -0600541 static std::vector<std::string> _activeProfiles;
542
Matthew Barth4ca87fa2021-04-14 11:31:13 -0500543 /* Subtree map of paths to services of interfaces(with ownership state) */
544 static std::map<
545 std::string,
546 std::map<std::string, std::pair<bool, std::vector<std::string>>>>
Matthew Barth12cb1252021-03-08 16:47:30 -0600547 _servTree;
548
Matthew Barth07fecfc2021-01-29 09:04:43 -0600549 /* Object map of paths to interfaces of properties and their values */
550 static std::map<
551 std::string,
552 std::map<std::string, std::map<std::string, PropertyVariantType>>>
553 _objects;
554
Matthew Barthd9cb63b2021-03-24 14:36:49 -0500555 /* List of timers and their data to be processed when expired */
556 std::vector<std::pair<std::unique_ptr<TimerData>, Timer>> _timers;
557
Matthew Barthebabc042021-05-13 15:38:58 -0500558 /* Map of signal match strings to a list of signal handler data */
559 std::unordered_map<std::string, std::vector<SignalData>> _signals;
560
Matthew Barthacd737c2021-03-04 11:04:01 -0600561 /* List of zones configured */
562 std::map<configKey, std::unique_ptr<Zone>> _zones;
563
Matthew Barth44ab7692021-03-26 11:40:10 -0500564 /* List of events configured */
565 std::map<configKey, std::unique_ptr<Event>> _events;
566
Matt Spinler7787def2021-10-14 16:33:16 -0500567 /* The sdeventplus wrapper around sd_event_add_defer to dump debug
568 * data from the event loop after the USR1 signal. */
569 std::unique_ptr<sdeventplus::source::Defer> debugDumpEventSource;
Matt Spinler2fc0a352021-10-04 15:10:57 -0500570
Matthew Barthacd737c2021-03-04 11:04:01 -0600571 /**
Matt Spinlerd76351b2021-08-05 16:23:09 -0500572 * @brief A map of parameter names and values that are something
573 * other than just D-Bus property values that other actions
574 * can set and use.
575 */
576 static std::unordered_map<std::string, PropertyVariantType> _parameters;
577
578 /**
Matthew Barthb2cd93f2021-06-16 16:37:40 -0500579 * @brief Callback for power state changes
580 *
581 * @param[in] powerStateOn - Whether the power state is on or not
582 *
583 * Callback function bound to the PowerState object instance to handle each
584 * time the power state changes.
585 */
586 void powerStateChanged(bool powerStateOn);
587
588 /**
Matthew Barth4ca87fa2021-04-14 11:31:13 -0500589 * @brief Find the service name for a given path and interface from the
590 * cached dataset
591 *
592 * @param[in] path - Path to get service for
593 * @param[in] intf - Interface to get service for
594 *
595 * @return - The cached service name
596 */
597 static const std::string& findService(const std::string& path,
598 const std::string& intf);
599
600 /**
Matthew Barthf41e9472021-05-13 16:38:06 -0500601 * @brief Find all the paths for a given service and interface from the
602 * cached dataset
603 *
604 * @param[in] serv - Service name to get paths for
605 * @param[in] intf - Interface to get paths for
606 *
607 * @return - The cached object paths
608 */
609 std::vector<std::string> findPaths(const std::string& serv,
610 const std::string& intf);
611
612 /**
Matthew Barthacd737c2021-03-04 11:04:01 -0600613 * @brief Parse and set the configured profiles from the profiles JSON file
614 *
615 * Retrieves the optional profiles JSON configuration file, parses it, and
616 * creates a list of configured profiles available to the other
617 * configuration files. These profiles can be used to remove or include
618 * entries within the other configuration files.
619 */
620 void setProfiles();
Matt Spinler2fc0a352021-10-04 15:10:57 -0500621
622 /**
Matt Spinler7787def2021-10-14 16:33:16 -0500623 * @brief Callback from debugDumpEventSource to dump debug data
Matt Spinler2fc0a352021-10-04 15:10:57 -0500624 */
Matt Spinler7787def2021-10-14 16:33:16 -0500625 void dumpDebugData(sdeventplus::source::EventBase&);
Matt Spinlerb5c21a22021-10-14 16:52:12 -0500626
627 /**
628 * @brief Dump the _objects, _servTree, and _parameters maps to JSON
629 *
630 * @param[out] data - The JSON that will be filled in
631 */
632 void dumpCache(json& data);
Matt Spinlerade0c372021-10-28 16:09:44 -0500633
634 /**
635 * @brief Add a group to the cache dataset.
636 *
637 * @param[in] group - The group to add
638 */
639 void addGroup(const Group& group);
Matthew Bartha227a162020-08-05 10:51:45 -0500640};
641
642} // namespace phosphor::fan::control::json