blob: c807252a0fbd4b296efca16f2500c9702480ac44 [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 */
Matt Spinlerd0ba86a2021-11-09 10:09:13 -060089using TriggerActions =
Matthew Barthc3a69082021-11-15 14:32:48 -060090 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
Matt Spinlerd0ba86a2021-11-09 10:09:13 -0600102 * TriggerActions = List of actions that are run when the signal is received
Matthew Barthebabc042021-05-13 15:38:58 -0500103 */
Matt Spinlerd0ba86a2021-11-09 10:09:13 -0600104using SignalPkg = std::tuple<SignalHandler, SignalObject, TriggerActions>;
Matthew Barthebabc042021-05-13 15:38:58 -0500105/**
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/**
Matt Spinlerd0ba86a2021-11-09 10:09:13 -0600131 * Actions to run when a parameter trigger runs.
132 */
133using ParamTriggerData = std::vector<
134 std::reference_wrapper<const std::vector<std::unique_ptr<ActionBase>>>>;
135
136/**
Matthew Bartha227a162020-08-05 10:51:45 -0500137 * @class Manager - Represents the fan control manager's configuration
138 *
139 * A fan control manager configuration is optional, therefore the "manager.json"
140 * file is also optional. The manager configuration is used to populate
141 * fan control's manager parameters which are used in how the application
142 * operates, not in how the fans are controlled.
143 *
144 * When no manager configuration exists, the fan control application starts,
145 * processes any configured events and then begins controlling fans according
146 * to those events.
147 */
148class Manager
149{
150 public:
151 Manager() = delete;
152 Manager(const Manager&) = delete;
153 Manager(Manager&&) = delete;
154 Manager& operator=(const Manager&) = delete;
155 Manager& operator=(Manager&&) = delete;
156 ~Manager() = default;
157
158 /**
159 * Constructor
160 * Parses and populates the fan control manager attributes from a json file
161 *
Matthew Barth06764942021-03-04 09:28:40 -0600162 * @param[in] event - sdeventplus event loop
Matthew Bartha227a162020-08-05 10:51:45 -0500163 */
Matthew Barth9403a212021-05-17 09:31:50 -0500164 Manager(const sdeventplus::Event& event);
Matthew Bartha227a162020-08-05 10:51:45 -0500165
166 /**
Matthew Barthe91ac862021-05-25 16:22:17 -0500167 * @brief Callback function to handle receiving a HUP signal to reload the
168 * JSON configurations.
169 */
170 void sighupHandler(sdeventplus::source::Signal&,
171 const struct signalfd_siginfo*);
172
173 /**
Matt Spinler2fc0a352021-10-04 15:10:57 -0500174 * @brief Callback function to handle receiving a USR1 signal to dump
175 * the flight recorder.
176 */
177 void sigUsr1Handler(sdeventplus::source::Signal&,
178 const struct signalfd_siginfo*);
179
180 /**
Matthew Barthacd737c2021-03-04 11:04:01 -0600181 * @brief Get the active profiles of the system where an empty list
182 * represents that only configuration entries without a profile defined will
183 * be loaded.
184 *
185 * @return - The list of active profiles
186 */
187 static const std::vector<std::string>& getActiveProfiles();
188
189 /**
190 * @brief Load the configuration of a given JSON class object based on the
191 * active profiles
192 *
Matthew Barthacd737c2021-03-04 11:04:01 -0600193 * @param[in] isOptional - JSON configuration file is optional or not
Matthew Barth603ef162021-03-24 15:34:53 -0500194 * @param[in] args - Arguments to be forwarded to each instance of `T`
Matthew Barthe6d1f782021-05-14 12:52:20 -0500195 * (*Note that a sdbusplus bus object is required as the first argument)
Matthew Barthacd737c2021-03-04 11:04:01 -0600196 *
197 * @return Map of configuration entries
198 * Map of configuration keys to their corresponding configuration object
199 */
Matthew Barth603ef162021-03-24 15:34:53 -0500200 template <typename T, typename... Args>
Matthew Barthe6d1f782021-05-14 12:52:20 -0500201 static std::map<configKey, std::unique_ptr<T>> getConfig(bool isOptional,
202 Args&&... args)
Matthew Barthacd737c2021-03-04 11:04:01 -0600203 {
204 std::map<configKey, std::unique_ptr<T>> config;
205
Matthew Barth9403a212021-05-17 09:31:50 -0500206 auto confFile =
207 fan::JsonConfig::getConfFile(util::SDBusPlus::getBus(), confAppName,
208 T::confFileName, isOptional);
Matthew Barthacd737c2021-03-04 11:04:01 -0600209 if (!confFile.empty())
210 {
211 for (const auto& entry : fan::JsonConfig::load(confFile))
212 {
213 if (entry.contains("profiles"))
214 {
215 std::vector<std::string> profiles;
216 for (const auto& profile : entry["profiles"])
217 {
218 profiles.emplace_back(
219 profile.template get<std::string>());
220 }
221 // Do not create the object if its profiles are not in the
222 // list of active profiles
Matthew Barth42428052021-03-30 12:50:59 -0500223 if (!profiles.empty() &&
224 !std::any_of(profiles.begin(), profiles.end(),
Matthew Barthacd737c2021-03-04 11:04:01 -0600225 [](const auto& name) {
226 return std::find(
227 getActiveProfiles().begin(),
228 getActiveProfiles().end(),
229 name) !=
230 getActiveProfiles().end();
231 }))
232 {
233 continue;
234 }
235 }
Matthew Barth603ef162021-03-24 15:34:53 -0500236 auto obj =
237 std::make_unique<T>(entry, std::forward<Args>(args)...);
Matthew Barthacd737c2021-03-04 11:04:01 -0600238 config.emplace(
239 std::make_pair(obj->getName(), obj->getProfiles()),
240 std::move(obj));
241 }
Matthew Barth68ac0042021-06-01 15:38:36 -0500242 log<level::INFO>(
243 fmt::format("Configuration({}) loaded successfully",
244 T::confFileName)
245 .c_str());
Matthew Barthacd737c2021-03-04 11:04:01 -0600246 }
247 return config;
248 }
249
250 /**
Matthew Barth0206c722021-03-30 15:20:05 -0500251 * @brief Check if the given input configuration key matches with another
252 * configuration key that it's to be included in
253 *
254 * @param[in] input - Config key to be included in another config object
255 * @param[in] comp - Config key of the config object to compare with
256 *
257 * @return Whether the configuration object should be included
258 */
259 static bool inConfig(const configKey& input, const configKey& comp);
260
261 /**
Matthew Barth12cb1252021-03-08 16:47:30 -0600262 * @brief Check if the given path and inteface is owned by a dbus service
263 *
264 * @param[in] path - Dbus object path
265 * @param[in] intf - Dbus object interface
266 *
267 * @return - Whether the service has an owner for the given object path and
268 * interface
269 */
270 static bool hasOwner(const std::string& path, const std::string& intf);
271
272 /**
Matthew Barth6d8e2d32022-02-01 16:47:08 -0600273 * @brief Sets the dbus service owner state for all entries in the _servTree
274 * cache and removes associated objects from the _objects cache
275 *
276 * @param[in] serv - Dbus service name
277 * @param[in] hasOwner - Dbus service owner state
278 */
279 void setOwner(const std::string& serv, bool hasOwner);
280
281 /**
Matthew Barth4ca87fa2021-04-14 11:31:13 -0500282 * @brief Sets the dbus service owner state of a given object
283 *
284 * @param[in] path - Dbus object path
285 * @param[in] serv - Dbus service name
286 * @param[in] intf - Dbus object interface
287 * @param[in] isOwned - Dbus service owner state
288 */
289 void setOwner(const std::string& path, const std::string& serv,
290 const std::string& intf, bool isOwned);
291
292 /**
293 * @brief Add a set of services for a path and interface by retrieving all
294 * the path subtrees to the given depth from root for the interface
295 *
Matthew Barth4ca87fa2021-04-14 11:31:13 -0500296 * @param[in] intf - Interface to add services for
297 * @param[in] depth - Depth of tree traversal from root path
298 *
299 * @throws - DBusMethodError
300 * Throws a DBusMethodError when the `getSubTree` method call fails
301 */
Matthew Barth98f6fc12021-04-16 10:48:37 -0500302 static void addServices(const std::string& intf, int32_t depth);
Matthew Barth4ca87fa2021-04-14 11:31:13 -0500303
304 /**
305 * @brief Get the service for a given path and interface from cached
306 * dataset and attempt to add all the services for the given path/interface
307 * when it's not found
308 *
309 * @param[in] path - Path to get service for
310 * @param[in] intf - Interface to get service for
311 *
312 * @return - The now cached service name
313 *
314 * @throws - DBusMethodError
315 * Ripples up a DBusMethodError exception from calling addServices
316 */
317 static const std::string& getService(const std::string& path,
318 const std::string& intf);
319
320 /**
Matthew Barthf41e9472021-05-13 16:38:06 -0500321 * @brief Get all the object paths for a given service and interface from
322 * the cached dataset and try to add all the services for the given
323 * interface when no paths are found and then attempt to get all the object
324 * paths again
325 *
326 * @param[in] serv - Service name to get paths for
327 * @param[in] intf - Interface to get paths for
328 *
329 * @return The cached object paths
330 */
331 std::vector<std::string> getPaths(const std::string& serv,
332 const std::string& intf);
333
334 /**
335 * @brief Add objects to the cached dataset by first using
336 * `getManagedObjects` for the same service providing the given path and
337 * interface or just add the single object of the given path, interface, and
338 * property if that fails.
339 *
340 * @param[in] path - Dbus object's path
341 * @param[in] intf - Dbus object's interface
342 * @param[in] prop - Dbus object's property
343 *
344 * @throws - DBusMethodError
345 * Throws a DBusMethodError when the the service is failed to be found or
346 * when the `getManagedObjects` method call fails
347 */
348 void addObjects(const std::string& path, const std::string& intf,
349 const std::string& prop);
350
351 /**
352 * @brief Get an object's property value
353 *
354 * @param[in] path - Dbus object's path
355 * @param[in] intf - Dbus object's interface
356 * @param[in] prop - Dbus object's property
357 */
358 const std::optional<PropertyVariantType>
359 getProperty(const std::string& path, const std::string& intf,
360 const std::string& prop);
361
362 /**
Matthew Barthbaeeb8f2021-05-13 16:03:54 -0500363 * @brief Set/update an object's property value
364 *
365 * @param[in] path - Dbus object's path
366 * @param[in] intf - Dbus object's interface
367 * @param[in] prop - Dbus object's property
368 * @param[in] value - Dbus object's property value
369 */
370 void setProperty(const std::string& path, const std::string& intf,
Mike Capps1a19ead2021-10-22 09:15:14 -0400371 const std::string& prop, PropertyVariantType value);
Matthew Barthbaeeb8f2021-05-13 16:03:54 -0500372
373 /**
Matthew Barthc2691402021-05-13 16:20:32 -0500374 * @brief Remove an object's interface
375 *
376 * @param[in] path - Dbus object's path
377 * @param[in] intf - Dbus object's interface
378 */
379 inline void removeInterface(const std::string& path,
380 const std::string& intf)
381 {
382 auto itPath = _objects.find(path);
383 if (itPath != std::end(_objects))
384 {
385 _objects[path].erase(intf);
386 }
387 }
388
389 /**
Matthew Barth07fecfc2021-01-29 09:04:43 -0600390 * @brief Get the object's property value as a variant
391 *
392 * @param[in] path - Path of the object containing the property
393 * @param[in] intf - Interface name containing the property
394 * @param[in] prop - Name of property
395 *
396 * @return - The object's property value as a variant
397 */
398 static inline auto getObjValueVariant(const std::string& path,
399 const std::string& intf,
400 const std::string& prop)
401 {
402 return _objects.at(path).at(intf).at(prop);
403 };
404
405 /**
Matthew Barthd9cb63b2021-03-24 14:36:49 -0500406 * @brief Add a dbus timer
407 *
408 * @param[in] type - Type of timer
409 * @param[in] interval - Timer interval in microseconds
410 * @param[in] pkg - Packaged data for when timer expires
411 */
412 void addTimer(const TimerType type,
413 const std::chrono::microseconds interval,
414 std::unique_ptr<TimerPkg> pkg);
415
416 /**
417 * @brief Callback when a timer expires
418 *
419 * @param[in] data - Data to be used when the timer expired
420 */
421 void timerExpired(TimerData& data);
422
423 /**
Matthew Barthebabc042021-05-13 15:38:58 -0500424 * @brief Get the signal data for a given match string
425 *
426 * @param[in] sigMatch - Signal match string
427 *
428 * @return - Reference to the signal data for the given match string
429 */
430 std::vector<SignalData>& getSignal(const std::string& sigMatch)
431 {
432 return _signals[sigMatch];
433 }
434
435 /**
436 * @brief Handle receiving signals
437 *
438 * @param[in] msg - Signal message containing the signal's data
439 * @param[in] pkgs - Signal packages associated to the signal being handled
440 */
441 void handleSignal(sdbusplus::message::message& msg,
Matthew Barthc024d782021-11-09 16:15:49 -0600442 const std::vector<SignalPkg>* pkgs);
Matthew Barthebabc042021-05-13 15:38:58 -0500443
444 /**
Matthew Bartheebde062021-04-14 12:48:52 -0500445 * @brief Get the sdbusplus bus object
446 */
447 inline auto& getBus()
448 {
449 return _bus;
450 }
451
452 /**
Matthew Barth48f44da2021-05-27 15:43:34 -0500453 * @brief Is the power state on
454 *
455 * @return Current power state of the system
456 */
457 inline bool isPowerOn() const
458 {
459 return _powerState->isPowerOn();
460 }
461
Matthew Barth3770a1d2021-06-10 15:09:37 -0500462 /**
463 * @brief Load all the fan control JSON configuration files
464 *
465 * This is where all the fan control JSON configuration files are parsed and
466 * loaded into their associated objects. Anything that needs to be done when
467 * the Manager object is constructed or handling a SIGHUP to reload the
468 * configurations needs to be done here.
469 */
470 void load();
471
Matt Spinlerd76351b2021-08-05 16:23:09 -0500472 /**
473 * @brief Sets a value in the parameter map.
474 *
Matt Spinler72c4af42021-11-29 14:40:17 -0600475 * If it's a std::nullopt, it will be deleted instead.
476 *
Matt Spinlerd76351b2021-08-05 16:23:09 -0500477 * @param[in] name - The parameter name
478 * @param[in] value - The parameter value
479 */
480 static void setParameter(const std::string& name,
Matt Spinler72c4af42021-11-29 14:40:17 -0600481 const std::optional<PropertyVariantType>& value)
Matt Spinlerd76351b2021-08-05 16:23:09 -0500482 {
Matt Spinler72c4af42021-11-29 14:40:17 -0600483 if (value)
Matt Spinlerd0ba86a2021-11-09 10:09:13 -0600484 {
Matt Spinler72c4af42021-11-29 14:40:17 -0600485 auto it = _parameters.find(name);
486 auto changed = (it == _parameters.end()) ||
487 ((it != _parameters.end()) && it->second != *value);
488 _parameters[name] = *value;
489
490 if (changed)
491 {
492 runParameterActions(name);
493 }
494 }
495 else
496 {
497 size_t deleted = _parameters.erase(name);
498
499 if (deleted)
500 {
501 runParameterActions(name);
502 }
Matt Spinlerd0ba86a2021-11-09 10:09:13 -0600503 }
Matt Spinlerd76351b2021-08-05 16:23:09 -0500504 }
505
506 /**
507 * @brief Returns a value from the parameter map
508 *
509 * @param[in] name - The parameter name
510 *
511 * @return The parameter value, or std::nullopt if not found
512 */
513 static std::optional<PropertyVariantType>
514 getParameter(const std::string& name)
515 {
516 auto it = _parameters.find(name);
517 if (it != _parameters.end())
518 {
519 return it->second;
520 }
521
522 return std::nullopt;
523 }
524
525 /**
Matt Spinlerd0ba86a2021-11-09 10:09:13 -0600526 * @brief Runs the actions registered to a parameter
527 * trigger with this name.
528 *
529 * @param[in] name - The parameter name
530 */
531 static void runParameterActions(const std::string& name);
532
533 /**
534 * @brief Adds a parameter trigger
535 *
536 * @param[in] name - The parameter name
537 * @param[in] actions - The actions to run on the trigger
538 */
539 static void
540 addParameterTrigger(const std::string& name,
541 std::vector<std::unique_ptr<ActionBase>>& actions);
542
Matt Spinler7787def2021-10-14 16:33:16 -0500543 /* The name of the dump file */
544 static const std::string dumpFile;
545
Matthew Bartha227a162020-08-05 10:51:45 -0500546 private:
Mike Capps1a19ead2021-10-22 09:15:14 -0400547 /**
548 * @brief Helper to detect when a property's double contains a NaN
549 * (not-a-number) value.
550 *
551 * @param[in] value - The property to test
552 */
553 static bool PropertyContainsNan(const PropertyVariantType& value)
554 {
555 return (std::holds_alternative<double>(value) &&
556 std::isnan(std::get<double>(value)));
557 }
558
559 /**
560 * @brief Insert managed objects into cache, but filter out properties
561 * containing unwanted NaN (not-a-number) values.
562 *
563 * @param[in] ref - The map of ManagedObjects to insert into cache
564 */
565 void insertFilteredObjects(ManagedObjects& ref);
566
Matthew Barth1542fb52021-06-10 14:09:09 -0500567 /* The sdbusplus bus object to use */
Matthew Barthacd737c2021-03-04 11:04:01 -0600568 sdbusplus::bus::bus& _bus;
569
Matthew Barth1542fb52021-06-10 14:09:09 -0500570 /* The sdeventplus even loop to use */
Matthew Barthacd737c2021-03-04 11:04:01 -0600571 sdeventplus::Event _event;
572
Matthew Barth1542fb52021-06-10 14:09:09 -0500573 /* The sdbusplus manager object to set the ObjectManager interface */
574 sdbusplus::server::manager::manager _mgr;
575
Matthew Barth3770a1d2021-06-10 15:09:37 -0500576 /* Whether loading the config files is allowed or not */
577 bool _loadAllowed;
578
Matthew Barth48f44da2021-05-27 15:43:34 -0500579 /* The system's power state determination object */
580 std::unique_ptr<PowerState> _powerState;
581
Matthew Barth06764942021-03-04 09:28:40 -0600582 /* List of profiles configured */
Matthew Barthacd737c2021-03-04 11:04:01 -0600583 std::map<configKey, std::unique_ptr<Profile>> _profiles;
Matthew Barth06764942021-03-04 09:28:40 -0600584
585 /* List of active profiles */
Matthew Barthacd737c2021-03-04 11:04:01 -0600586 static std::vector<std::string> _activeProfiles;
587
Matthew Barth4ca87fa2021-04-14 11:31:13 -0500588 /* Subtree map of paths to services of interfaces(with ownership state) */
589 static std::map<
590 std::string,
591 std::map<std::string, std::pair<bool, std::vector<std::string>>>>
Matthew Barth12cb1252021-03-08 16:47:30 -0600592 _servTree;
593
Matthew Barth07fecfc2021-01-29 09:04:43 -0600594 /* Object map of paths to interfaces of properties and their values */
595 static std::map<
596 std::string,
597 std::map<std::string, std::map<std::string, PropertyVariantType>>>
598 _objects;
599
Matthew Barthd9cb63b2021-03-24 14:36:49 -0500600 /* List of timers and their data to be processed when expired */
601 std::vector<std::pair<std::unique_ptr<TimerData>, Timer>> _timers;
602
Matthew Barthebabc042021-05-13 15:38:58 -0500603 /* Map of signal match strings to a list of signal handler data */
604 std::unordered_map<std::string, std::vector<SignalData>> _signals;
605
Matthew Barthacd737c2021-03-04 11:04:01 -0600606 /* List of zones configured */
607 std::map<configKey, std::unique_ptr<Zone>> _zones;
608
Matthew Barth44ab7692021-03-26 11:40:10 -0500609 /* List of events configured */
610 std::map<configKey, std::unique_ptr<Event>> _events;
611
Matt Spinler7787def2021-10-14 16:33:16 -0500612 /* The sdeventplus wrapper around sd_event_add_defer to dump debug
613 * data from the event loop after the USR1 signal. */
614 std::unique_ptr<sdeventplus::source::Defer> debugDumpEventSource;
Matt Spinler2fc0a352021-10-04 15:10:57 -0500615
Matthew Barthacd737c2021-03-04 11:04:01 -0600616 /**
Matt Spinlerd76351b2021-08-05 16:23:09 -0500617 * @brief A map of parameter names and values that are something
618 * other than just D-Bus property values that other actions
619 * can set and use.
620 */
621 static std::unordered_map<std::string, PropertyVariantType> _parameters;
622
623 /**
Matt Spinlerd0ba86a2021-11-09 10:09:13 -0600624 * @brief Map of parameter names to the actions to run when their
625 * values change.
626 */
627 static std::unordered_map<std::string, TriggerActions> _parameterTriggers;
628
629 /**
Matthew Barthb2cd93f2021-06-16 16:37:40 -0500630 * @brief Callback for power state changes
631 *
632 * @param[in] powerStateOn - Whether the power state is on or not
633 *
634 * Callback function bound to the PowerState object instance to handle each
635 * time the power state changes.
636 */
637 void powerStateChanged(bool powerStateOn);
638
639 /**
Matthew Barth4ca87fa2021-04-14 11:31:13 -0500640 * @brief Find the service name for a given path and interface from the
641 * cached dataset
642 *
643 * @param[in] path - Path to get service for
644 * @param[in] intf - Interface to get service for
645 *
646 * @return - The cached service name
647 */
648 static const std::string& findService(const std::string& path,
649 const std::string& intf);
650
651 /**
Matthew Barthf41e9472021-05-13 16:38:06 -0500652 * @brief Find all the paths for a given service and interface from the
653 * cached dataset
654 *
655 * @param[in] serv - Service name to get paths for
656 * @param[in] intf - Interface to get paths for
657 *
658 * @return - The cached object paths
659 */
660 std::vector<std::string> findPaths(const std::string& serv,
661 const std::string& intf);
662
663 /**
Matthew Barthacd737c2021-03-04 11:04:01 -0600664 * @brief Parse and set the configured profiles from the profiles JSON file
665 *
666 * Retrieves the optional profiles JSON configuration file, parses it, and
667 * creates a list of configured profiles available to the other
668 * configuration files. These profiles can be used to remove or include
669 * entries within the other configuration files.
670 */
671 void setProfiles();
Matt Spinler2fc0a352021-10-04 15:10:57 -0500672
673 /**
Matt Spinler7787def2021-10-14 16:33:16 -0500674 * @brief Callback from debugDumpEventSource to dump debug data
Matt Spinler2fc0a352021-10-04 15:10:57 -0500675 */
Matt Spinler7787def2021-10-14 16:33:16 -0500676 void dumpDebugData(sdeventplus::source::EventBase&);
Matt Spinlerb5c21a22021-10-14 16:52:12 -0500677
678 /**
679 * @brief Dump the _objects, _servTree, and _parameters maps to JSON
680 *
681 * @param[out] data - The JSON that will be filled in
682 */
683 void dumpCache(json& data);
Matt Spinlerade0c372021-10-28 16:09:44 -0500684
685 /**
686 * @brief Add a group to the cache dataset.
687 *
688 * @param[in] group - The group to add
689 */
690 void addGroup(const Group& group);
Matthew Bartha227a162020-08-05 10:51:45 -0500691};
692
693} // namespace phosphor::fan::control::json