diff options
-rw-r--r-- | Makefile.am | 9 | ||||
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | controller.cpp | 2 | ||||
-rw-r--r-- | physical.hpp | 6 | ||||
-rw-r--r-- | xyz.openbmc_project.Led.Physical.cpp | 355 | ||||
-rw-r--r-- | xyz/openbmc_project/Led/Physical/server.hpp | 149 |
6 files changed, 10 insertions, 512 deletions
diff --git a/Makefile.am b/Makefile.am index 869679d..3c42e07 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,8 +3,9 @@ sbin_PROGRAMS = phosphor-ledcontroller phosphor_ledcontroller_SOURCES = \ controller.cpp \ argument.cpp \ - physical.cpp \ - xyz.openbmc_project.Led.Physical.cpp + physical.cpp -phosphor_ledcontroller_LDFLAGS = $(SDBUSPLUS_LIBS) -phosphor_ledcontroller_CFLAGS = $(SDBUSPLUS_CFLAGS) +phosphor_ledcontroller_LDFLAGS = $(SDBUSPLUS_LIBS) \ + $(PHOSPHOR_DBUS_INTERFACES_LIBS) +phosphor_ledcontroller_CFLAGS = $(SDBUSPLUS_CFLAGS) \ + $(PHOSPHOR_DBUS_INTERFACES_CFLAGS) diff --git a/configure.ac b/configure.ac index 5b32436..02472d0 100644 --- a/configure.ac +++ b/configure.ac @@ -23,6 +23,7 @@ LT_INIT # Checks for header files. PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus],, [AC_MSG_ERROR([Could not find sdbusplus...openbmc/sdbusplus package required])]) +PKG_CHECK_MODULES([PHOSPHOR_DBUS_INTERFACES], [phosphor-dbus-interfaces],, [AC_MSG_ERROR([Could not find phosphor-dbus-interfaces...openbmc/phosphor-dbus-interfaces package required])]) # Check/set gtest specific functions. AX_PTHREAD([GTEST_CPPFLAGS="-DGTEST_HAS_PTHREAD=1"],[GTEST_CPPFLAGS="-DGTEST_HAS_PTHREAD=0"]) diff --git a/controller.cpp b/controller.cpp index 656c9bf..4e83f58 100644 --- a/controller.cpp +++ b/controller.cpp @@ -62,7 +62,7 @@ int main(int argc, char** argv) // Create the Physical LED objects for directing actions. // Need to save this else sdbusplus destructor will wipe this off. - auto obj = phosphor::led::Physical(bus, objPath, path); + phosphor::led::Physical led(bus, objPath, path); /** @brief Claim the bus */ bus.request_name(busName.c_str()); diff --git a/physical.hpp b/physical.hpp index c24d3f2..36fbedc 100644 --- a/physical.hpp +++ b/physical.hpp @@ -4,7 +4,7 @@ #include <fstream> #include <sdbusplus/bus.hpp> #include <sdbusplus/server/object.hpp> -#include "xyz/openbmc_project/Led/Physical/server.hpp" +#include <xyz/openbmc_project/Led/Physical/server.hpp> namespace phosphor { namespace led @@ -57,8 +57,8 @@ class Physical : public sdbusplus::server::object::object< ~Physical() = default; Physical(const Physical&) = delete; Physical& operator=(const Physical&) = delete; - Physical(Physical&&) = default; - Physical& operator=(Physical&&) = default; + Physical(Physical&&) = delete; + Physical& operator=(Physical&&) = delete; /** @brief Constructs LED object. Argument 'true' says that we hold off * from sending the signals since we need to do some house keeping and diff --git a/xyz.openbmc_project.Led.Physical.cpp b/xyz.openbmc_project.Led.Physical.cpp deleted file mode 100644 index 6b96e81..0000000 --- a/xyz.openbmc_project.Led.Physical.cpp +++ /dev/null @@ -1,355 +0,0 @@ -#include <algorithm> -#include <sdbusplus/server.hpp> -#include <sdbusplus/exception.hpp> -#include "xyz/openbmc_project/Led/Physical/server.hpp" - -namespace sdbusplus -{ -namespace xyz -{ -namespace openbmc_project -{ -namespace Led -{ -namespace server -{ - -Physical::Physical(bus::bus& bus, const char* path) - : _xyz_openbmc_project_Led_Physical_interface( - bus, path, _interface, _vtable, this) -{ -} - - - -auto Physical::state() const -> - Action -{ - return _state; -} - -int Physical::_callback_get_State( - sd_bus* bus, const char* path, const char* interface, - const char* property, sd_bus_message* reply, void* context, - sd_bus_error* error) -{ - using sdbusplus::server::binding::details::convertForMessage; - - try - { - auto m = message::message(sd_bus_message_ref(reply)); - - auto o = static_cast<Physical*>(context); - m.append(convertForMessage(o->state())); - } - catch(sdbusplus::internal_exception_t& e) - { - sd_bus_error_set_const(error, e.name(), e.description()); - return -EINVAL; - } - - return true; -} - -auto Physical::state(Action value) -> - Action -{ - if (_state != value) - { - _state = value; - _xyz_openbmc_project_Led_Physical_interface.property_changed("State"); - } - - return _state; -} - -int Physical::_callback_set_State( - sd_bus* bus, const char* path, const char* interface, - const char* property, sd_bus_message* value, void* context, - sd_bus_error* error) -{ - try - { - auto m = message::message(sd_bus_message_ref(value)); - - auto o = static_cast<Physical*>(context); - - std::string v{}; - m.read(v); - o->state(convertActionFromString(v)); - } - catch(sdbusplus::internal_exception_t& e) - { - sd_bus_error_set_const(error, e.name(), e.description()); - return -EINVAL; - } - - return true; -} - -namespace details -{ -namespace Physical -{ -static const auto _property_State = - utility::tuple_to_array(message::types::type_id< - std::string>()); -} -} -auto Physical::dutyOn() const -> - uint8_t -{ - return _dutyOn; -} - -int Physical::_callback_get_DutyOn( - sd_bus* bus, const char* path, const char* interface, - const char* property, sd_bus_message* reply, void* context, - sd_bus_error* error) -{ - using sdbusplus::server::binding::details::convertForMessage; - - try - { - auto m = message::message(sd_bus_message_ref(reply)); - - auto o = static_cast<Physical*>(context); - m.append(convertForMessage(o->dutyOn())); - } - catch(sdbusplus::internal_exception_t& e) - { - sd_bus_error_set_const(error, e.name(), e.description()); - return -EINVAL; - } - - return true; -} - -auto Physical::dutyOn(uint8_t value) -> - uint8_t -{ - if (_dutyOn != value) - { - _dutyOn = value; - _xyz_openbmc_project_Led_Physical_interface.property_changed("DutyOn"); - } - - return _dutyOn; -} - -int Physical::_callback_set_DutyOn( - sd_bus* bus, const char* path, const char* interface, - const char* property, sd_bus_message* value, void* context, - sd_bus_error* error) -{ - try - { - auto m = message::message(sd_bus_message_ref(value)); - - auto o = static_cast<Physical*>(context); - - uint8_t v{}; - m.read(v); - o->dutyOn(v); - } - catch(sdbusplus::internal_exception_t& e) - { - sd_bus_error_set_const(error, e.name(), e.description()); - return -EINVAL; - } - - return true; -} - -namespace details -{ -namespace Physical -{ -static const auto _property_DutyOn = - utility::tuple_to_array(message::types::type_id< - uint8_t>()); -} -} -auto Physical::color() const -> - Palette -{ - return _color; -} - -int Physical::_callback_get_Color( - sd_bus* bus, const char* path, const char* interface, - const char* property, sd_bus_message* reply, void* context, - sd_bus_error* error) -{ - using sdbusplus::server::binding::details::convertForMessage; - - try - { - auto m = message::message(sd_bus_message_ref(reply)); - - auto o = static_cast<Physical*>(context); - m.append(convertForMessage(o->color())); - } - catch(sdbusplus::internal_exception_t& e) - { - sd_bus_error_set_const(error, e.name(), e.description()); - return -EINVAL; - } - - return true; -} - -auto Physical::color(Palette value) -> - Palette -{ - if (_color != value) - { - _color = value; - _xyz_openbmc_project_Led_Physical_interface.property_changed("Color"); - } - - return _color; -} - -int Physical::_callback_set_Color( - sd_bus* bus, const char* path, const char* interface, - const char* property, sd_bus_message* value, void* context, - sd_bus_error* error) -{ - try - { - auto m = message::message(sd_bus_message_ref(value)); - - auto o = static_cast<Physical*>(context); - - std::string v{}; - m.read(v); - o->color(convertPaletteFromString(v)); - } - catch(sdbusplus::internal_exception_t& e) - { - sd_bus_error_set_const(error, e.name(), e.description()); - return -EINVAL; - } - - return true; -} - -namespace details -{ -namespace Physical -{ -static const auto _property_Color = - utility::tuple_to_array(message::types::type_id< - std::string>()); -} -} - - -namespace -{ -/** String to enum mapping for Physical::Action */ -static const std::tuple<const char*, Physical::Action> mappingPhysicalAction[] = - { - std::make_tuple( "xyz.openbmc_project.Led.Physical.Action.Off", Physical::Action::Off ), - std::make_tuple( "xyz.openbmc_project.Led.Physical.Action.On", Physical::Action::On ), - std::make_tuple( "xyz.openbmc_project.Led.Physical.Action.Blink", Physical::Action::Blink ), - }; - -} // anonymous namespace - -auto Physical::convertActionFromString(std::string& s) -> - Action -{ - auto i = std::find_if( - std::begin(mappingPhysicalAction), - std::end(mappingPhysicalAction), - [&s](auto& e){ return 0 == strcmp(s.c_str(), std::get<0>(e)); } ); - if (std::end(mappingPhysicalAction) == i) - { - throw sdbusplus::exception::InvalidEnumString(); - } - else - { - return std::get<1>(*i); - } -} - -std::string convertForMessage(Physical::Action v) -{ - auto i = std::find_if( - std::begin(mappingPhysicalAction), - std::end(mappingPhysicalAction), - [v](auto& e){ return v == std::get<1>(e); }); - return std::get<0>(*i); -} - -namespace -{ -/** String to enum mapping for Physical::Palette */ -static const std::tuple<const char*, Physical::Palette> mappingPhysicalPalette[] = - { - std::make_tuple( "xyz.openbmc_project.Led.Physical.Palette.Unknown", Physical::Palette::Unknown ), - std::make_tuple( "xyz.openbmc_project.Led.Physical.Palette.Red", Physical::Palette::Red ), - std::make_tuple( "xyz.openbmc_project.Led.Physical.Palette.Green", Physical::Palette::Green ), - std::make_tuple( "xyz.openbmc_project.Led.Physical.Palette.Blue", Physical::Palette::Blue ), - std::make_tuple( "xyz.openbmc_project.Led.Physical.Palette.Yellow", Physical::Palette::Yellow ), - }; - -} // anonymous namespace - -auto Physical::convertPaletteFromString(std::string& s) -> - Palette -{ - auto i = std::find_if( - std::begin(mappingPhysicalPalette), - std::end(mappingPhysicalPalette), - [&s](auto& e){ return 0 == strcmp(s.c_str(), std::get<0>(e)); } ); - if (std::end(mappingPhysicalPalette) == i) - { - throw sdbusplus::exception::InvalidEnumString(); - } - else - { - return std::get<1>(*i); - } -} - -std::string convertForMessage(Physical::Palette v) -{ - auto i = std::find_if( - std::begin(mappingPhysicalPalette), - std::end(mappingPhysicalPalette), - [v](auto& e){ return v == std::get<1>(e); }); - return std::get<0>(*i); -} - -const vtable::vtable_t Physical::_vtable[] = { - vtable::start(), - vtable::property("State", - details::Physical::_property_State - .data(), - _callback_get_State, - _callback_set_State, - vtable::property_::emits_change), - vtable::property("DutyOn", - details::Physical::_property_DutyOn - .data(), - _callback_get_DutyOn, - _callback_set_DutyOn, - vtable::property_::emits_change), - vtable::property("Color", - details::Physical::_property_Color - .data(), - _callback_get_Color, - _callback_set_Color, - vtable::property_::emits_change), - vtable::end() -}; - -} // namespace server -} // namespace Led -} // namespace openbmc_project -} // namespace xyz -} // namespace sdbusplus - diff --git a/xyz/openbmc_project/Led/Physical/server.hpp b/xyz/openbmc_project/Led/Physical/server.hpp deleted file mode 100644 index 2269f42..0000000 --- a/xyz/openbmc_project/Led/Physical/server.hpp +++ /dev/null @@ -1,149 +0,0 @@ -#pragma once -#include <tuple> -#include <systemd/sd-bus.h> -#include <sdbusplus/server.hpp> - -namespace sdbusplus -{ -namespace xyz -{ -namespace openbmc_project -{ -namespace Led -{ -namespace server -{ - -class Physical -{ - public: - /* Define all of the basic class operations: - * Not allowed: - * - Default constructor to avoid nullptrs. - * - Copy operations due to internal unique_ptr. - * Allowed: - * - Move operations. - * - Destructor. - */ - Physical() = delete; - Physical(const Physical&) = delete; - Physical& operator=(const Physical&) = delete; - Physical(Physical&&) = default; - Physical& operator=(Physical&&) = default; - virtual ~Physical() = default; - - /** @brief Constructor to put object onto bus at a dbus path. - * @param[in] bus - Bus to attach to. - * @param[in] path - Path to attach at. - */ - Physical(bus::bus& bus, const char* path); - - enum class Action - { - Off, - On, - Blink, - }; - enum class Palette - { - Unknown, - Red, - Green, - Blue, - Yellow, - }; - - - - /** Get value of State */ - virtual Action state() const; - /** Set value of State */ - virtual Action state(Action value); - /** Get value of DutyOn */ - virtual uint8_t dutyOn() const; - /** Set value of DutyOn */ - virtual uint8_t dutyOn(uint8_t value); - /** Get value of Color */ - virtual Palette color() const; - /** Set value of Color */ - virtual Palette color(Palette value); - - /** @brief Convert a string to an appropriate enum value. - * @param[in] s - The string to convert in the form of - * "xyz.openbmc_project.Led.Physical.<value name>" - * @return - The enum value. - */ - static Action convertActionFromString(std::string& s); - /** @brief Convert a string to an appropriate enum value. - * @param[in] s - The string to convert in the form of - * "xyz.openbmc_project.Led.Physical.<value name>" - * @return - The enum value. - */ - static Palette convertPaletteFromString(std::string& s); - - private: - - /** @brief sd-bus callback for get-property 'State' */ - static int _callback_get_State( - sd_bus*, const char*, const char*, const char*, - sd_bus_message*, void*, sd_bus_error*); - /** @brief sd-bus callback for set-property 'State' */ - static int _callback_set_State( - sd_bus*, const char*, const char*, const char*, - sd_bus_message*, void*, sd_bus_error*); - - /** @brief sd-bus callback for get-property 'DutyOn' */ - static int _callback_get_DutyOn( - sd_bus*, const char*, const char*, const char*, - sd_bus_message*, void*, sd_bus_error*); - /** @brief sd-bus callback for set-property 'DutyOn' */ - static int _callback_set_DutyOn( - sd_bus*, const char*, const char*, const char*, - sd_bus_message*, void*, sd_bus_error*); - - /** @brief sd-bus callback for get-property 'Color' */ - static int _callback_get_Color( - sd_bus*, const char*, const char*, const char*, - sd_bus_message*, void*, sd_bus_error*); - /** @brief sd-bus callback for set-property 'Color' */ - static int _callback_set_Color( - sd_bus*, const char*, const char*, const char*, - sd_bus_message*, void*, sd_bus_error*); - - - static constexpr auto _interface = "xyz.openbmc_project.Led.Physical"; - static const vtable::vtable_t _vtable[]; - sdbusplus::server::interface::interface - _xyz_openbmc_project_Led_Physical_interface; - - Action _state = Action::Off; - uint8_t _dutyOn = 50; - Palette _color = Palette::Unknown; - -}; - -/* Specialization of sdbusplus::server::bindings::details::convertForMessage - * for enum-type Physical::Action. - * - * This converts from the enum to a constant c-string representing the enum. - * - * @param[in] e - Enum value to convert. - * @return C-string representing the name for the enum value. - */ -std::string convertForMessage(Physical::Action e); -/* Specialization of sdbusplus::server::bindings::details::convertForMessage - * for enum-type Physical::Palette. - * - * This converts from the enum to a constant c-string representing the enum. - * - * @param[in] e - Enum value to convert. - * @return C-string representing the name for the enum value. - */ -std::string convertForMessage(Physical::Palette e); - -} // namespace server -} // namespace Led -} // namespace openbmc_project -} // namespace xyz -} // namespace sdbusplus - |