blob: 81196c105db35863d5e68325f25a3a01ab0dbb50 [file] [log] [blame]
Matthew Barth37d73ec2020-03-30 16:10:39 -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
17#include "manager_interface.hpp"
18
19#include <phosphor-logging/log.hpp>
20#include <sdbusplus/exception.hpp>
21#include <sdbusplus/sdbus.hpp>
22#include <sdbusplus/server.hpp>
23
24#include <string>
25#include <tuple>
26
27namespace phosphor
28{
29namespace power
30{
31namespace regulators
32{
33namespace interface
34{
35
Patrick Williams7354ce62022-07-22 19:26:56 -050036ManagerInterface::ManagerInterface(sdbusplus::bus_t& bus, const char* path) :
Matthew Barth37d73ec2020-03-30 16:10:39 -050037 _serverInterface(bus, path, interface, _vtable, this)
Adriana Kobylak0c9a33d2021-09-13 18:05:09 +000038{}
Matthew Barth37d73ec2020-03-30 16:10:39 -050039
40int ManagerInterface::callbackConfigure(sd_bus_message* msg, void* context,
41 sd_bus_error* error)
42{
43 if (msg != nullptr && context != nullptr)
44 {
45 try
46 {
Patrick Williams7354ce62022-07-22 19:26:56 -050047 auto m = sdbusplus::message_t(msg);
Matthew Barth37d73ec2020-03-30 16:10:39 -050048
49 auto mgrObj = static_cast<ManagerInterface*>(context);
50 mgrObj->configure();
51
52 auto reply = m.new_method_return();
53
54 reply.method_return();
55 }
Patrick Williamsc1d4de52021-10-06 12:45:57 -050056 catch (const sdbusplus::exception_t& e)
Matthew Barth37d73ec2020-03-30 16:10:39 -050057 {
58 return sd_bus_error_set(error, e.name(), e.description());
59 }
60 }
61 else
62 {
63 // The message or context were null
64 using namespace phosphor::logging;
65 log<level::ERR>("Unable to service Configure method callback");
66 return -1;
67 }
68
69 return 1;
70}
71
72int ManagerInterface::callbackMonitor(sd_bus_message* msg, void* context,
73 sd_bus_error* error)
74{
75 if (msg != nullptr && context != nullptr)
76 {
77 try
78 {
79 bool enable{};
Patrick Williams7354ce62022-07-22 19:26:56 -050080 auto m = sdbusplus::message_t(msg);
Matthew Barth37d73ec2020-03-30 16:10:39 -050081
82 m.read(enable);
83
84 auto mgrObj = static_cast<ManagerInterface*>(context);
85 mgrObj->monitor(enable);
86
87 auto reply = m.new_method_return();
88
89 reply.method_return();
90 }
Patrick Williamsc1d4de52021-10-06 12:45:57 -050091 catch (const sdbusplus::exception_t& e)
Matthew Barth37d73ec2020-03-30 16:10:39 -050092 {
93 return sd_bus_error_set(error, e.name(), e.description());
94 }
95 }
96 else
97 {
98 // The message or context were null
99 using namespace phosphor::logging;
100 log<level::ERR>("Unable to service Monitor method callback");
101 return -1;
102 }
103
104 return 1;
105}
106
107const sdbusplus::vtable::vtable_t ManagerInterface::_vtable[] = {
108 sdbusplus::vtable::start(),
109 // No configure method parameters and returns void
110 sdbusplus::vtable::method("Configure", "", "", callbackConfigure),
111 // Monitor method takes a boolean parameter and returns void
112 sdbusplus::vtable::method("Monitor", "b", "", callbackMonitor),
113 sdbusplus::vtable::end()};
114
115} // namespace interface
116} // namespace regulators
117} // namespace power
118} // namespace phosphor