blob: 1b35d2543dbc3d21e01af6165e8620863780a0b1 [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
36ManagerInterface::ManagerInterface(sdbusplus::bus::bus& bus, const char* path) :
37 _serverInterface(bus, path, interface, _vtable, this)
38{
39}
40
41int ManagerInterface::callbackConfigure(sd_bus_message* msg, void* context,
42 sd_bus_error* error)
43{
44 if (msg != nullptr && context != nullptr)
45 {
46 try
47 {
48 auto m = sdbusplus::message::message(msg);
49
50 auto mgrObj = static_cast<ManagerInterface*>(context);
51 mgrObj->configure();
52
53 auto reply = m.new_method_return();
54
55 reply.method_return();
56 }
Shawn McCarney415094c2021-02-15 11:08:19 -060057 catch (sdbusplus::exception_t& e)
Matthew Barth37d73ec2020-03-30 16:10:39 -050058 {
59 return sd_bus_error_set(error, e.name(), e.description());
60 }
61 }
62 else
63 {
64 // The message or context were null
65 using namespace phosphor::logging;
66 log<level::ERR>("Unable to service Configure method callback");
67 return -1;
68 }
69
70 return 1;
71}
72
73int ManagerInterface::callbackMonitor(sd_bus_message* msg, void* context,
74 sd_bus_error* error)
75{
76 if (msg != nullptr && context != nullptr)
77 {
78 try
79 {
80 bool enable{};
81 auto m = sdbusplus::message::message(msg);
82
83 m.read(enable);
84
85 auto mgrObj = static_cast<ManagerInterface*>(context);
86 mgrObj->monitor(enable);
87
88 auto reply = m.new_method_return();
89
90 reply.method_return();
91 }
Shawn McCarney415094c2021-02-15 11:08:19 -060092 catch (sdbusplus::exception_t& e)
Matthew Barth37d73ec2020-03-30 16:10:39 -050093 {
94 return sd_bus_error_set(error, e.name(), e.description());
95 }
96 }
97 else
98 {
99 // The message or context were null
100 using namespace phosphor::logging;
101 log<level::ERR>("Unable to service Monitor method callback");
102 return -1;
103 }
104
105 return 1;
106}
107
108const sdbusplus::vtable::vtable_t ManagerInterface::_vtable[] = {
109 sdbusplus::vtable::start(),
110 // No configure method parameters and returns void
111 sdbusplus::vtable::method("Configure", "", "", callbackConfigure),
112 // Monitor method takes a boolean parameter and returns void
113 sdbusplus::vtable::method("Monitor", "b", "", callbackMonitor),
114 sdbusplus::vtable::end()};
115
116} // namespace interface
117} // namespace regulators
118} // namespace power
119} // namespace phosphor