1 /**
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 
21 #include <chrono>
22 
23 namespace phosphor
24 {
25 namespace power
26 {
27 namespace regulators
28 {
29 
30 Manager::Manager(sdbusplus::bus::bus& bus, const sdeventplus::Event& event) :
31     ManagerObject(bus, objPath, true), bus(bus), eventLoop(event)
32 {
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 
42 void 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 
49 void Manager::monitor(bool enable)
50 {
51     if (enable)
52     {
53         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));
57     }
58     else
59     {
60         // Delete all timers to disable monitoring
61         timers.clear();
62     }
63 }
64 
65 void Manager::timerExpired()
66 {
67     // TODO Analyze, refresh sensor status, and
68     // collect/update telemetry for each regulator
69 }
70 
71 void Manager::sighupHandler(sdeventplus::source::Signal& /*sigSrc*/,
72                             const struct signalfd_siginfo* /*sigInfo*/)
73 {
74     // TODO Reload and process the configuration data
75 }
76 
77 } // namespace regulators
78 } // namespace power
79 } // namespace phosphor
80