Matthew Barth | 37d73ec | 2020-03-30 16:10:39 -0500 | [diff] [blame] | 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_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 | |
| 27 | namespace phosphor |
| 28 | { |
| 29 | namespace power |
| 30 | { |
| 31 | namespace regulators |
| 32 | { |
| 33 | namespace interface |
| 34 | { |
| 35 | |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 36 | ManagerInterface::ManagerInterface(sdbusplus::bus_t& bus, const char* path) : |
Matthew Barth | 37d73ec | 2020-03-30 16:10:39 -0500 | [diff] [blame] | 37 | _serverInterface(bus, path, interface, _vtable, this) |
Adriana Kobylak | 0c9a33d | 2021-09-13 18:05:09 +0000 | [diff] [blame] | 38 | {} |
Matthew Barth | 37d73ec | 2020-03-30 16:10:39 -0500 | [diff] [blame] | 39 | |
| 40 | int 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 Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 47 | auto m = sdbusplus::message_t(msg); |
Matthew Barth | 37d73ec | 2020-03-30 16:10:39 -0500 | [diff] [blame] | 48 | |
| 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 Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 56 | catch (const sdbusplus::exception_t& e) |
Matthew Barth | 37d73ec | 2020-03-30 16:10:39 -0500 | [diff] [blame] | 57 | { |
| 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 | |
| 72 | int 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 Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 80 | auto m = sdbusplus::message_t(msg); |
Matthew Barth | 37d73ec | 2020-03-30 16:10:39 -0500 | [diff] [blame] | 81 | |
| 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 Williams | c1d4de5 | 2021-10-06 12:45:57 -0500 | [diff] [blame] | 91 | catch (const sdbusplus::exception_t& e) |
Matthew Barth | 37d73ec | 2020-03-30 16:10:39 -0500 | [diff] [blame] | 92 | { |
| 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 | |
| 107 | const 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 |