137d73ec3SMatthew Barth /**
237d73ec3SMatthew Barth * Copyright © 2020 IBM Corporation
337d73ec3SMatthew Barth *
437d73ec3SMatthew Barth * Licensed under the Apache License, Version 2.0 (the "License");
537d73ec3SMatthew Barth * you may not use this file except in compliance with the License.
637d73ec3SMatthew Barth * You may obtain a copy of the License at
737d73ec3SMatthew Barth *
837d73ec3SMatthew Barth * http://www.apache.org/licenses/LICENSE-2.0
937d73ec3SMatthew Barth *
1037d73ec3SMatthew Barth * Unless required by applicable law or agreed to in writing, software
1137d73ec3SMatthew Barth * distributed under the License is distributed on an "AS IS" BASIS,
1237d73ec3SMatthew Barth * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1337d73ec3SMatthew Barth * See the License for the specific language governing permissions and
1437d73ec3SMatthew Barth * limitations under the License.
1537d73ec3SMatthew Barth */
1637d73ec3SMatthew Barth
1737d73ec3SMatthew Barth #include "manager_interface.hpp"
1837d73ec3SMatthew Barth
1937d73ec3SMatthew Barth #include <phosphor-logging/log.hpp>
2037d73ec3SMatthew Barth #include <sdbusplus/exception.hpp>
2137d73ec3SMatthew Barth #include <sdbusplus/sdbus.hpp>
2237d73ec3SMatthew Barth #include <sdbusplus/server.hpp>
2337d73ec3SMatthew Barth
2437d73ec3SMatthew Barth #include <string>
2537d73ec3SMatthew Barth #include <tuple>
2637d73ec3SMatthew Barth
2737d73ec3SMatthew Barth namespace phosphor
2837d73ec3SMatthew Barth {
2937d73ec3SMatthew Barth namespace power
3037d73ec3SMatthew Barth {
3137d73ec3SMatthew Barth namespace regulators
3237d73ec3SMatthew Barth {
3337d73ec3SMatthew Barth namespace interface
3437d73ec3SMatthew Barth {
3537d73ec3SMatthew Barth
ManagerInterface(sdbusplus::bus_t & bus,const char * path)36*7354ce62SPatrick Williams ManagerInterface::ManagerInterface(sdbusplus::bus_t& bus, const char* path) :
3737d73ec3SMatthew Barth _serverInterface(bus, path, interface, _vtable, this)
380c9a33d6SAdriana Kobylak {}
3937d73ec3SMatthew Barth
callbackConfigure(sd_bus_message * msg,void * context,sd_bus_error * error)4037d73ec3SMatthew Barth int ManagerInterface::callbackConfigure(sd_bus_message* msg, void* context,
4137d73ec3SMatthew Barth sd_bus_error* error)
4237d73ec3SMatthew Barth {
4337d73ec3SMatthew Barth if (msg != nullptr && context != nullptr)
4437d73ec3SMatthew Barth {
4537d73ec3SMatthew Barth try
4637d73ec3SMatthew Barth {
47*7354ce62SPatrick Williams auto m = sdbusplus::message_t(msg);
4837d73ec3SMatthew Barth
4937d73ec3SMatthew Barth auto mgrObj = static_cast<ManagerInterface*>(context);
5037d73ec3SMatthew Barth mgrObj->configure();
5137d73ec3SMatthew Barth
5237d73ec3SMatthew Barth auto reply = m.new_method_return();
5337d73ec3SMatthew Barth
5437d73ec3SMatthew Barth reply.method_return();
5537d73ec3SMatthew Barth }
56c1d4de5eSPatrick Williams catch (const sdbusplus::exception_t& e)
5737d73ec3SMatthew Barth {
5837d73ec3SMatthew Barth return sd_bus_error_set(error, e.name(), e.description());
5937d73ec3SMatthew Barth }
6037d73ec3SMatthew Barth }
6137d73ec3SMatthew Barth else
6237d73ec3SMatthew Barth {
6337d73ec3SMatthew Barth // The message or context were null
6437d73ec3SMatthew Barth using namespace phosphor::logging;
6537d73ec3SMatthew Barth log<level::ERR>("Unable to service Configure method callback");
6637d73ec3SMatthew Barth return -1;
6737d73ec3SMatthew Barth }
6837d73ec3SMatthew Barth
6937d73ec3SMatthew Barth return 1;
7037d73ec3SMatthew Barth }
7137d73ec3SMatthew Barth
callbackMonitor(sd_bus_message * msg,void * context,sd_bus_error * error)7237d73ec3SMatthew Barth int ManagerInterface::callbackMonitor(sd_bus_message* msg, void* context,
7337d73ec3SMatthew Barth sd_bus_error* error)
7437d73ec3SMatthew Barth {
7537d73ec3SMatthew Barth if (msg != nullptr && context != nullptr)
7637d73ec3SMatthew Barth {
7737d73ec3SMatthew Barth try
7837d73ec3SMatthew Barth {
7937d73ec3SMatthew Barth bool enable{};
80*7354ce62SPatrick Williams auto m = sdbusplus::message_t(msg);
8137d73ec3SMatthew Barth
8237d73ec3SMatthew Barth m.read(enable);
8337d73ec3SMatthew Barth
8437d73ec3SMatthew Barth auto mgrObj = static_cast<ManagerInterface*>(context);
8537d73ec3SMatthew Barth mgrObj->monitor(enable);
8637d73ec3SMatthew Barth
8737d73ec3SMatthew Barth auto reply = m.new_method_return();
8837d73ec3SMatthew Barth
8937d73ec3SMatthew Barth reply.method_return();
9037d73ec3SMatthew Barth }
91c1d4de5eSPatrick Williams catch (const sdbusplus::exception_t& e)
9237d73ec3SMatthew Barth {
9337d73ec3SMatthew Barth return sd_bus_error_set(error, e.name(), e.description());
9437d73ec3SMatthew Barth }
9537d73ec3SMatthew Barth }
9637d73ec3SMatthew Barth else
9737d73ec3SMatthew Barth {
9837d73ec3SMatthew Barth // The message or context were null
9937d73ec3SMatthew Barth using namespace phosphor::logging;
10037d73ec3SMatthew Barth log<level::ERR>("Unable to service Monitor method callback");
10137d73ec3SMatthew Barth return -1;
10237d73ec3SMatthew Barth }
10337d73ec3SMatthew Barth
10437d73ec3SMatthew Barth return 1;
10537d73ec3SMatthew Barth }
10637d73ec3SMatthew Barth
10737d73ec3SMatthew Barth const sdbusplus::vtable::vtable_t ManagerInterface::_vtable[] = {
10837d73ec3SMatthew Barth sdbusplus::vtable::start(),
10937d73ec3SMatthew Barth // No configure method parameters and returns void
11037d73ec3SMatthew Barth sdbusplus::vtable::method("Configure", "", "", callbackConfigure),
11137d73ec3SMatthew Barth // Monitor method takes a boolean parameter and returns void
11237d73ec3SMatthew Barth sdbusplus::vtable::method("Monitor", "b", "", callbackMonitor),
11337d73ec3SMatthew Barth sdbusplus::vtable::end()};
11437d73ec3SMatthew Barth
11537d73ec3SMatthew Barth } // namespace interface
11637d73ec3SMatthew Barth } // namespace regulators
11737d73ec3SMatthew Barth } // namespace power
11837d73ec3SMatthew Barth } // namespace phosphor
119