blob: 8b8134cfe3d2d5bf140b4984424504d45d986302 [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
Matthew Barthbbc7c582020-02-03 15:55:15 -060019#include "utility.hpp"
20
Matthew Barth29e9e382020-01-23 13:40:49 -060021#include <sdbusplus/bus.hpp>
22
Matthew Barthf2bcf1f2020-01-29 14:42:47 -060023#include <chrono>
24
Matthew Barth29e9e382020-01-23 13:40:49 -060025namespace phosphor
26{
27namespace power
28{
29namespace regulators
30{
31
Matthew Barthf2bcf1f2020-01-29 14:42:47 -060032Manager::Manager(sdbusplus::bus::bus& bus, const sdeventplus::Event& event) :
Matthew Barthbbc7c582020-02-03 15:55:15 -060033 ManagerObject(bus, objPath, true), bus(bus), eventLoop(event), fileName("")
Matthew Barth29e9e382020-01-23 13:40:49 -060034{
Matthew Barthbbc7c582020-02-03 15:55:15 -060035 // Attempt to get the filename property from dbus
36 setFileName(getFileNameDbus());
37
38 // TODO Subscribe to interfacesAdded signal for filename property
39 // Callback should set fileName and call parse json function
40
41 if (!fileName.empty())
42 {
43 // TODO Load & parse JSON configuration data file
44 }
Matthew Barth29e9e382020-01-23 13:40:49 -060045
46 // Obtain dbus service name
47 bus.request_name(busName);
48}
49
50void Manager::configure()
51{
52 // TODO Configuration errors that should halt poweron,
53 // throw InternalFailure exception (or similar) to
54 // fail the call(busctl) to this method
55}
56
57void Manager::monitor(bool enable)
58{
59 if (enable)
60 {
Matthew Barthf2bcf1f2020-01-29 14:42:47 -060061 Timer timer(eventLoop, std::bind(&Manager::timerExpired, this));
62 // Set timer as a repeating 1sec timer
63 timer.restart(std::chrono::milliseconds(1000));
64 timers.emplace_back(std::move(timer));
Matthew Barth29e9e382020-01-23 13:40:49 -060065 }
66 else
67 {
Matthew Barthf2bcf1f2020-01-29 14:42:47 -060068 // Delete all timers to disable monitoring
69 timers.clear();
Matthew Barth29e9e382020-01-23 13:40:49 -060070 }
71}
72
Matthew Barthf2bcf1f2020-01-29 14:42:47 -060073void Manager::timerExpired()
74{
75 // TODO Analyze, refresh sensor status, and
76 // collect/update telemetry for each regulator
77}
78
Matthew Barth7cbc5532020-01-29 15:13:13 -060079void Manager::sighupHandler(sdeventplus::source::Signal& /*sigSrc*/,
80 const struct signalfd_siginfo* /*sigInfo*/)
81{
82 // TODO Reload and process the configuration data
83}
84
Matthew Barthbbc7c582020-02-03 15:55:15 -060085const std::string Manager::getFileNameDbus()
86{
87 std::string fileName = "";
88 using namespace phosphor::power::util;
89
90 try
91 {
92 // Do not log an error when service or property are not found
93 auto service = getService(sysDbusPath, sysDbusIntf, bus, false);
94 if (!service.empty())
95 {
96 getProperty(sysDbusIntf, sysDbusProp, sysDbusPath, service, bus,
97 fileName);
98 }
99 }
100 catch (const sdbusplus::exception::SdBusError&)
101 {
102 // File name property not available on dbus
103 fileName = "";
104 }
105
106 return fileName;
107}
108
Matthew Barth29e9e382020-01-23 13:40:49 -0600109} // namespace regulators
110} // namespace power
111} // namespace phosphor