blob: 15071d5921a25573d42e72065156e457c2e72491 [file] [log] [blame]
Matthew Barth29e9e382020-01-23 13:40:49 -06001/**
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
17#include "manager.hpp"
18
19#include <sdbusplus/bus.hpp>
20
Matthew Barthf2bcf1f2020-01-29 14:42:47 -060021#include <chrono>
22
Matthew Barth29e9e382020-01-23 13:40:49 -060023namespace phosphor
24{
25namespace power
26{
27namespace regulators
28{
29
Matthew Barthf2bcf1f2020-01-29 14:42:47 -060030Manager::Manager(sdbusplus::bus::bus& bus, const sdeventplus::Event& event) :
31 ManagerObject(bus, objPath, true), bus(bus), eventLoop(event)
Matthew Barth29e9e382020-01-23 13:40:49 -060032{
33 // TODO get property (IM keyword)
34 // call parse json function
35 // TODO subscribe to interfacesadded (IM keyword)
36 // callback would call parse json function
37
38 // Obtain dbus service name
39 bus.request_name(busName);
40}
41
42void Manager::configure()
43{
44 // TODO Configuration errors that should halt poweron,
45 // throw InternalFailure exception (or similar) to
46 // fail the call(busctl) to this method
47}
48
49void Manager::monitor(bool enable)
50{
51 if (enable)
52 {
Matthew Barthf2bcf1f2020-01-29 14:42:47 -060053 Timer timer(eventLoop, std::bind(&Manager::timerExpired, this));
54 // Set timer as a repeating 1sec timer
55 timer.restart(std::chrono::milliseconds(1000));
56 timers.emplace_back(std::move(timer));
Matthew Barth29e9e382020-01-23 13:40:49 -060057 }
58 else
59 {
Matthew Barthf2bcf1f2020-01-29 14:42:47 -060060 // Delete all timers to disable monitoring
61 timers.clear();
Matthew Barth29e9e382020-01-23 13:40:49 -060062 }
63}
64
Matthew Barthf2bcf1f2020-01-29 14:42:47 -060065void Manager::timerExpired()
66{
67 // TODO Analyze, refresh sensor status, and
68 // collect/update telemetry for each regulator
69}
70
Matthew Barth7cbc5532020-01-29 15:13:13 -060071void Manager::sighupHandler(sdeventplus::source::Signal& /*sigSrc*/,
72 const struct signalfd_siginfo* /*sigInfo*/)
73{
74 // TODO Reload and process the configuration data
75}
76
Matthew Barth29e9e382020-01-23 13:40:49 -060077} // namespace regulators
78} // namespace power
79} // namespace phosphor