From 506aa0f33362eee06a8f7a2572519d4053f06e41 Mon Sep 17 00:00:00 2001 From: Vishwanatha Subbanna Date: Tue, 24 Jan 2017 14:58:25 +0530 Subject: Add initial code for IPMI SoftPowerOff functionality This commit puts a skeleton layout for the IPMI Soft Power Off functionality. Change-Id: I7c3ededc9d4038e172d7f6230270ecfe397330e9 Signed-off-by: Vishwanatha Subbanna --- Makefile.am | 3 ++- configure.ac | 39 +++++++++++++++++++++++++++++++++++---- softoff/Makefile.am | 26 ++++++++++++++++++++++++++ softoff/mainapp.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ softoff/softoff.cpp | 22 ++++++++++++++++++++++ softoff/softoff.hpp | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 159 insertions(+), 5 deletions(-) create mode 100644 softoff/Makefile.am create mode 100644 softoff/mainapp.cpp create mode 100644 softoff/softoff.cpp create mode 100644 softoff/softoff.hpp diff --git a/Makefile.am b/Makefile.am index a703a1b..80a2ed5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -57,4 +57,5 @@ libhostservice_la_CXXFLAGS = $(SYSTEMD_CFLAGS) $(libmapper_CFLAGS) nobase_include_HEADERS = \ host-ipmid/ipmid-api.h -SUBDIRS = test +# Forcing the build of self and then subdir +SUBDIRS = . test softoff diff --git a/configure.ac b/configure.ac index b43adaf..68e0dc9 100644 --- a/configure.ac +++ b/configure.ac @@ -12,14 +12,30 @@ AM_PROG_AR AC_PROG_INSTALL AC_PROG_MAKE_SET +# softoff dir specific ones +AC_ARG_ENABLE([softoff], + AS_HELP_STRING([--enable-softoff], [Builds soft power off]) +) +AS_IF([test "x$enable_softoff" != "xno"], + [AC_PROG_MKDIR_P] + [AC_CHECK_PROG([DIRNAME], dirname, dirname)] +) + # Checks for libraries. AC_CHECK_LIB([mapper], [mapper_get_service], ,[AC_MSG_ERROR([Could not find libmapper...openbmc/phosphor-objmgr package required])]) -PKG_CHECK_MODULES([SYSTEMD], [libsystemd >= 221]) +PKG_CHECK_MODULES([SYSTEMD], [libsystemd >= 221], [], [AC_MSG_ERROR(["systemd required and not found"])]) PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging],, [AC_MSG_ERROR([Could not find phosphor-logging...openbmc/phosphor-logging 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])]) -# Checks for header files. -AC_CHECK_HEADER(systemd/sd-bus.h, ,[AC_MSG_ERROR([Could not find systemd/sd-bus.h...systemd developement package required])]) +AS_IF([test "x$enable_softoff" != "xno"], + # Check for sdbusplus + PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus],, [AC_MSG_ERROR(["sdbusplus packaged required and not found"])]) + + # Check for sdbus++ tool + [AC_PATH_PROG([SDBUSPLUSPLUS], [sdbus++])] + AS_IF([test "x$SDBUSPLUSPLUS" == "x"], + AC_MSG_ERROR([Cannot find sdbus++])) +) # Checks for typedefs, structures, and compiler characteristics. AX_CXX_COMPILE_STDCXX_14([noext]) @@ -61,6 +77,21 @@ AS_IF([test "x$SENSOR_YAML_GEN" == "x"], [SENSOR_YAML_GEN="sensor-example.yaml"] SENSORGEN="$PYTHON ${srcdir}/scripts/sensor_gen.py -i $SENSOR_YAML_GEN" AC_SUBST(SENSORGEN) +# Soft Power off related. +AS_IF([test "x$enable_softoff" != "xno"], + # Dbus service name + [AC_ARG_VAR(SOFTOFF_BUSNAME, [The Dbus busname to own])] + AS_IF([test "x$SOFTOFF_BUSNAME" == "x"], + [SOFTOFF_BUSNAME="xyz.openbmc_project.Ipmi.Internal.SoftPowerOff"]) + [AC_DEFINE_UNQUOTED([SOFTOFF_BUSNAME], ["$SOFTOFF_BUSNAME"], [The Dbus busname to own])] + + # Service dbus root + [AC_ARG_VAR(SOFTOFF_OBJPATH, [The SoftPowerOff Dbus root])] + AS_IF([test "x$SOFTOFF_OBJPATH" == "x"], + [SOFTOFF_OBJPATH="/xyz/openbmc_project/ipmi/internal/softpoweroff"]) + [AC_DEFINE_UNQUOTED([SOFTOFF_OBJPATH], ["$SOFTOFF_OBJPATH"], [The SoftPowerOff Dbus root])] +) + # Create configured output -AC_CONFIG_FILES([Makefile test/Makefile]) +AC_CONFIG_FILES([Makefile test/Makefile softoff/Makefile]) AC_OUTPUT diff --git a/softoff/Makefile.am b/softoff/Makefile.am new file mode 100644 index 0000000..66501a5 --- /dev/null +++ b/softoff/Makefile.am @@ -0,0 +1,26 @@ +AM_DEFAULT_SOURCE_EXT = .cpp +AM_CPPFLAGS = -I$(top_srcdir) +sbin_PROGRAMS = phosphor-softpoweroff + +phosphor_softpoweroff_SOURCES = \ + softoff.cpp \ + mainapp.cpp \ + xyz/openbmc_project/Ipmi/Internal/SoftPowerOff/server.cpp + +BUILT_SOURCES = xyz/openbmc_project/Ipmi/Internal/SoftPowerOff/server.cpp \ + xyz/openbmc_project/Ipmi/Internal/SoftPowerOff/server.hpp + +nodist_include_HEADERS = xyz/openbmc_project/Ipmi/Internal/SoftPowerOff/server.hpp +CLEANFILES = xyz/openbmc_project/Ipmi/Internal/SoftPowerOff/server.cpp \ + xyz/openbmc_project/Ipmi/Internal/SoftPowerOff/server.hpp + +phosphor_softpoweroff_LDFLAGS = $(SYSTEMD_LIBS) $(SDBUSPLUS_LIBS) +phosphor_softpoweroff_CXXFLAGS = $(SYSTEMD_CFLAGS) $(SDBUSPLUS_CFLAGS) + +xyz/openbmc_project/Ipmi/Internal/SoftPowerOff/server.cpp: ${top_srcdir}/xyz/openbmc_project/Ipmi/Internal/SoftPowerOff.interface.yaml + @mkdir -p `dirname $@` + $(SDBUSPLUSPLUS) -r $(top_srcdir) interface server-cpp xyz.openbmc_project.Ipmi.Internal.SoftPowerOff > $@ + +xyz/openbmc_project/Ipmi/Internal/SoftPowerOff/server.hpp: ${top_srcdir}/xyz/openbmc_project/Ipmi/Internal/SoftPowerOff.interface.yaml + @mkdir -p `dirname $@` + $(SDBUSPLUSPLUS) -r $(top_srcdir) interface server-header xyz.openbmc_project.Ipmi.Internal.SoftPowerOff > $@ diff --git a/softoff/mainapp.cpp b/softoff/mainapp.cpp new file mode 100644 index 0000000..a974ed7 --- /dev/null +++ b/softoff/mainapp.cpp @@ -0,0 +1,41 @@ +/** + * Copyright © 2016 IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "softoff.hpp" +#include "config.h" + +int main(int argc, char** argv) +{ + // Get a handle to system dbus. + auto bus = sdbusplus::bus::new_default(); + + // Add systemd object manager. + sdbusplus::server::manager::manager(bus, SOFTOFF_OBJPATH); + + // Create the SoftPowerOff object. + phosphor::ipmi::SoftPowerOff obj(bus, SOFTOFF_OBJPATH); + + /** @brief Claim the bus */ + bus.request_name(SOFTOFF_BUSNAME); + + /** @brief Wait for client requests */ + while(true) + { + // Handle dbus message / signals discarding unhandled + bus.process_discard(); + bus.wait(); + } + return 0; +} diff --git a/softoff/softoff.cpp b/softoff/softoff.cpp new file mode 100644 index 0000000..3505e5a --- /dev/null +++ b/softoff/softoff.cpp @@ -0,0 +1,22 @@ +/** + * Copyright © 2016 IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +namespace phosphor +{ +namespace ipmi +{ + // Will be populated in the next patchset. +} // namespace ipmi +} // namespace phosphor diff --git a/softoff/softoff.hpp b/softoff/softoff.hpp new file mode 100644 index 0000000..93dfb26 --- /dev/null +++ b/softoff/softoff.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include +#include +#include +namespace phosphor +{ +namespace ipmi +{ + +namespace Base = sdbusplus::xyz::openbmc_project::Ipmi::Internal::server; + +/** @class SoftPowerOff + * @brief Responsible for coordinating Host SoftPowerOff operation + */ +class SoftPowerOff : public sdbusplus::server::object::object< + Base::SoftPowerOff> +{ + public: + /** @brief Constructs SoftPowerOff object. + * + * @param[in] bus - system dbus handler + * @param[in] objPath - The Dbus path that hosts SoftPowerOff function + */ + SoftPowerOff(sdbusplus::bus::bus& bus, + const char* objPath) : + sdbusplus::server::object::object(bus, objPath) + { + // Nothing to do here + } +}; +} // namespace ipmi +} // namespace phosphor -- cgit v1.2.1