summaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
authorMao, Andy <andy.mao@intel.com>2018-04-17 20:53:45 +0300
committerGerrit Code Review <gerrit@fmygit6002.fm.intel.com>2018-04-17 20:53:45 +0300
commit104dc9539690a7343df38b80130af3d82bcbb349 (patch)
treee224881d91e57886623786588ce8d6a6a7c7f2a4 /services
parent7b96082fa3b11f5f79889e4ac5e734da3afddda6 (diff)
parent3df08f960374ca516fa61f6193e3b587cd157393 (diff)
downloadprovingground-104dc9539690a7343df38b80130af3d82bcbb349.tar.xz
Merge "[ChassisPowerControl] Chassis control process is ready for powerOn and getPowerState"
Diffstat (limited to 'services')
-rw-r--r--services/chassis/CMakeLists.txt3
-rw-r--r--services/chassis/ChassisControl/CMakeLists.txt87
-rw-r--r--services/chassis/ChassisControl/inc/ChassisControl.hpp46
-rw-r--r--services/chassis/ChassisControl/src/ChassisControl.cpp91
-rw-r--r--services/chassis/ChassisControl/src/main.cpp79
-rw-r--r--services/chassis/ChassisControl/xyz/openbmc_project/Chassis/Control/Chassis.errors.yaml9
-rw-r--r--services/chassis/ChassisControl/xyz/openbmc_project/Chassis/Control/Chassis.interface.yaml94
7 files changed, 408 insertions, 1 deletions
diff --git a/services/chassis/CMakeLists.txt b/services/chassis/CMakeLists.txt
index 6404467..5f2ba7e 100644
--- a/services/chassis/CMakeLists.txt
+++ b/services/chassis/CMakeLists.txt
@@ -5,4 +5,5 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Gpio/inc)
add_subdirectory(Gpio)
-add_subdirectory(Buttons) \ No newline at end of file
+add_subdirectory(Buttons)
+add_subdirectory(ChassisControl)
diff --git a/services/chassis/ChassisControl/CMakeLists.txt b/services/chassis/ChassisControl/CMakeLists.txt
new file mode 100644
index 0000000..8265e8e
--- /dev/null
+++ b/services/chassis/ChassisControl/CMakeLists.txt
@@ -0,0 +1,87 @@
+cmake_minimum_required(VERSION 2.8.10 FATAL_ERROR)
+project(ChassisControl CXX)
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH} ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
+set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+
+include(GNUInstallDirs)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc)
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+set(DBUS_OBJECT_NAME "xyz/openbmc_project/Chassis/Control/Chassis")
+set(DBUS_INTF_NAME "xyz.openbmc_project.Chassis.Control.Chassis")
+
+add_definitions(-DDBUS_OBJECT_NAME="/${DBUS_OBJECT_NAME}")
+add_definitions(-DDBUS_INTF_NAME="${DBUS_INTF_NAME}")
+
+set(SRC_FILES
+ src/ChassisControl.cpp
+ src/main.cpp
+)
+set(GENERATED_SRC_FILES
+ ${DBUS_OBJECT_NAME}/error.cpp
+ ${DBUS_OBJECT_NAME}/server.cpp
+)
+
+# import libsystemd
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(SYSTEMD libsystemd REQUIRED)
+include_directories(${SYSTEMD_INCLUDE_DIRS})
+link_directories(${SYSTEMD_LIBRARY_DIRS})
+
+# import sdbusplus
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(SDBUSPLUSPLUS sdbusplus REQUIRED)
+include_directories(${SDBUSPLUSPLUS_INCLUDE_DIRS})
+link_directories(${SDBUSPLUSPLUS_LIBRARY_DIRS})
+find_program(SDBUSPLUSPLUS sdbus++)
+
+# import phosphor-logging
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(LOGGING phosphor-logging REQUIRED)
+include_directories(${LOGGING_INCLUDE_DIRS})
+link_directories(${LOGGING_LIBRARY_DIRS})
+
+# phosphor-dbus-interfaces
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(DBUSINTERFACE phosphor-dbus-interfaces REQUIRED)
+include_directories(${DBUSINTERFACE_INCLUDE_DIRS})
+link_directories(${DBUSINTERFACE_LIBRARY_DIRS})
+
+#include_directories(${CMAKE_CURRENT_BINARY_DIR}/${DBUS_OBJECT_NAME})
+
+add_custom_command(
+ OUTPUT ${DBUS_OBJECT_NAME}/error.hpp
+ OUTPUT ${DBUS_OBJECT_NAME}/error.cpp
+ COMMAND mkdir -p ${DBUS_OBJECT_NAME}
+ COMMAND ${SDBUSPLUSPLUS} -r ${CMAKE_CURRENT_SOURCE_DIR} error exception-header ${DBUS_INTF_NAME} > ${DBUS_OBJECT_NAME}/error.hpp
+ COMMAND ${SDBUSPLUSPLUS} -r ${CMAKE_CURRENT_SOURCE_DIR} error exception-cpp ${DBUS_INTF_NAME} > ${DBUS_OBJECT_NAME}/error.cpp
+ DEPENDS ${DBUS_OBJECT_NAME}.errors.yaml
+)
+set_source_files_properties(
+ ${DBUS_OBJECT_NAME}/error.hpp
+ ${DBUS_OBJECT_NAME}/error.cpp
+ PROPERTIES GENERATED TRUE)
+
+
+add_custom_command(
+ OUTPUT ${DBUS_OBJECT_NAME}/server.hpp
+ OUTPUT ${DBUS_OBJECT_NAME}/server.cpp
+ COMMAND mkdir -p ${DBUS_OBJECT_NAME}
+ COMMAND ${SDBUSPLUSPLUS} -r ${CMAKE_CURRENT_SOURCE_DIR} interface server-header ${DBUS_INTF_NAME} > ${DBUS_OBJECT_NAME}/server.hpp
+ COMMAND ${SDBUSPLUSPLUS} -r ${CMAKE_CURRENT_SOURCE_DIR} interface server-cpp ${DBUS_INTF_NAME} > ${DBUS_OBJECT_NAME}/server.cpp
+ DEPENDS ${DBUS_OBJECT_NAME}.interface.yaml
+)
+set_source_files_properties(
+ ${DBUS_OBJECT_NAME}/server.hpp
+ ${DBUS_OBJECT_NAME}/server.cpp
+ PROPERTIES GENERATED TRUE)
+
+
+add_executable(${PROJECT_NAME} ${SRC_FILES} ${GENERATED_SRC_FILES})
+target_link_libraries(${PROJECT_NAME} "${SDBUSPLUSPLUS_LIBRARIES} -lstdc++fs")
+
+install (TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
diff --git a/services/chassis/ChassisControl/inc/ChassisControl.hpp b/services/chassis/ChassisControl/inc/ChassisControl.hpp
new file mode 100644
index 0000000..982b72f
--- /dev/null
+++ b/services/chassis/ChassisControl/inc/ChassisControl.hpp
@@ -0,0 +1,46 @@
+#pragma once
+#include "xyz/openbmc_project/Chassis/Control/Chassis/error.hpp"
+#include "xyz/openbmc_project/Chassis/Control/Chassis/server.hpp"
+
+const static int32_t POWER_OFF = 0;
+const static int32_t POWER_ON = 1;
+
+struct EventDeleter
+{
+ void operator()(sd_event *event) const
+ {
+ event = sd_event_unref(event);
+ }
+};
+
+using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
+
+struct ChassisControl
+ : sdbusplus::server::object_t<
+ sdbusplus::xyz::openbmc_project::Chassis::Control::server::Chassis>
+{
+ ChassisControl(sdbusplus::bus::bus& bus, const char* path, EventPtr &event)
+ : sdbusplus::server::object_t<
+ sdbusplus::xyz::openbmc_project::Chassis::Control::server::Chassis>(
+ bus, path),
+ mBus(bus),
+ mState(POWER_OFF)
+ {
+ phosphor::logging::log<phosphor::logging::level::DEBUG>("ChassisControl is created.");
+ }
+
+ int32_t powerOn() override;
+ int32_t powerOff() override;
+ int32_t softPowerOff() override;
+ int32_t reboot() override;
+ int32_t softReboot() override;
+ int32_t quiesce() override;
+ int32_t getPowerState() override;
+
+
+
+ private:
+ sdbusplus::bus::bus& mBus;
+ int32_t mState;
+};
+
diff --git a/services/chassis/ChassisControl/src/ChassisControl.cpp b/services/chassis/ChassisControl/src/ChassisControl.cpp
new file mode 100644
index 0000000..7dbfcee
--- /dev/null
+++ b/services/chassis/ChassisControl/src/ChassisControl.cpp
@@ -0,0 +1,91 @@
+/*
+// Copyright (c) 2018 Intel 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 <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/log.hpp>
+#include <server.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
+#include <chrono>
+#include "ChassisControl.hpp"
+
+constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
+constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1";
+constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager";
+constexpr auto HOST_START_TARGET = "obmc-intel-host-start@.target";
+
+constexpr auto POWER_CONTROL_SERVICE = "xyz.openbmc_project.Chassis.Control.Power";
+constexpr auto POWER_CONTROL_OBJ_PATH = "/xyz/openbmc_project/Chassis/Control/Power";
+constexpr auto POWER_CONTROL_INTERFACE = "xyz.openbmc_project.Chassis.Control.Power";
+
+int32_t ChassisControl::powerOn()
+{
+ auto method = mBus.new_method_call(SYSTEMD_SERVICE,
+ SYSTEMD_OBJ_PATH,
+ SYSTEMD_INTERFACE,
+ "StartUnit");
+ method.append(HOST_START_TARGET);
+ method.append("replace");
+ auto response = mBus.call(method);
+ if (response.is_method_error())
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>
+ ("ERROR: Failed to run host start target");
+ return -1;
+ }
+
+ return 0;
+}
+int32_t ChassisControl::powerOff()
+{
+ //TODO
+ return 0;
+}
+
+int32_t ChassisControl::softPowerOff()
+{
+ //TODO
+ return 0;
+}
+int32_t ChassisControl::reboot()
+{
+ //TODO
+ return 0;
+}
+int32_t ChassisControl::softReboot()
+{
+ //TODO
+ return 0;
+}
+int32_t ChassisControl::quiesce()
+{
+ //TODO
+ return 0;
+}
+int32_t ChassisControl::getPowerState()
+{
+ auto method = mBus.new_method_call(POWER_CONTROL_SERVICE, POWER_CONTROL_OBJ_PATH,
+ POWER_CONTROL_INTERFACE, "getPowerState");
+ auto result = mBus.call(method);
+ if (result.is_method_error())
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>
+ ("ERROR: Failed to call power control method getPowerState");
+ return -1;
+ }
+ result.read(mState);
+
+ return mState;
+}
diff --git a/services/chassis/ChassisControl/src/main.cpp b/services/chassis/ChassisControl/src/main.cpp
new file mode 100644
index 0000000..d426c36
--- /dev/null
+++ b/services/chassis/ChassisControl/src/main.cpp
@@ -0,0 +1,79 @@
+/*
+// Copyright (c) 2018 Intel 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 <chrono>
+#include <experimental/filesystem>
+#include <fcntl.h>
+#include <fstream>
+#include <iostream>
+#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/log.hpp>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <systemd/sd-event.h>
+#include <unistd.h>
+#include <xyz/openbmc_project/Common/error.hpp>
+#include "ChassisControl.hpp"
+
+int main(int argc, char *argv[])
+{
+ int ret = 0;
+
+ phosphor::logging::log<phosphor::logging::level::INFO>(
+ "Start Chassis Control service...");
+
+ sd_event *event = nullptr;
+ ret = sd_event_default(&event);
+ if (ret < 0)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Error creating a default sd_event handler");
+ return ret;
+ }
+ EventPtr eventP{event};
+ event = nullptr;
+
+ auto bus = sdbusplus::bus::new_default();
+ sdbusplus::server::manager::manager objManager{
+ bus, "/xyz/openbmc_project/Chassis/Control/Chassis"};
+
+ bus.request_name("xyz.openbmc_project.Chassis.Control.Chassis");
+
+ ChassisControl chassisControl{bus, DBUS_OBJECT_NAME, eventP};
+
+ try
+ {
+ bus.attach_event(eventP.get(), SD_EVENT_PRIORITY_NORMAL);
+
+ while (true)
+ {
+ ret = sd_event_run(eventP.get(), (uint64_t)-1);
+ if (ret < 0)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Error waiting for events");
+ break;
+ }
+ }
+ }
+
+ catch (std::exception &e)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
+ ret = -1;
+ }
+ return ret;
+}
diff --git a/services/chassis/ChassisControl/xyz/openbmc_project/Chassis/Control/Chassis.errors.yaml b/services/chassis/ChassisControl/xyz/openbmc_project/Chassis/Control/Chassis.errors.yaml
new file mode 100644
index 0000000..9de4b9d
--- /dev/null
+++ b/services/chassis/ChassisControl/xyz/openbmc_project/Chassis/Control/Chassis.errors.yaml
@@ -0,0 +1,9 @@
+- name: UnsupportedCommand
+ description: >
+ An unsupported command was attempted.
+- name: InvalidParameter
+ description: >
+ An invalid parameter was attempted.
+- name: IOError
+ description: >
+ An IO error occurred.
diff --git a/services/chassis/ChassisControl/xyz/openbmc_project/Chassis/Control/Chassis.interface.yaml b/services/chassis/ChassisControl/xyz/openbmc_project/Chassis/Control/Chassis.interface.yaml
new file mode 100644
index 0000000..eda4bc0
--- /dev/null
+++ b/services/chassis/ChassisControl/xyz/openbmc_project/Chassis/Control/Chassis.interface.yaml
@@ -0,0 +1,94 @@
+description: >
+ chassis control service
+methods:
+ - name: powerOn
+ description: >
+ Power on system.
+ returns:
+ - name: state
+ type: int32
+ description: >
+ The result of command.
+ errors:
+ - self.Error.UnsupportedCommand
+ - self.Error.InvalidParameter
+ - self.Error.IOError
+
+ - name: powerOff
+ description: >
+ Power Off system.
+ returns:
+ - name: state
+ type: int32
+ description: >
+ The result of command.
+ errors:
+ - self.Error.UnsupportedCommand
+ - self.Error.InvalidParameter
+ - self.Error.IOError
+
+ - name: softPowerOff
+ description: >
+ Soft Power off system.
+ returns:
+ - name: state
+ type: int32
+ description: >
+ The result of command.
+ errors:
+ - self.Error.UnsupportedCommand
+ - self.Error.InvalidParameter
+ - self.Error.IOError
+
+ - name: reboot
+ description: >
+ reboot system.
+ returns:
+ - name: state
+ type: int32
+ description: >
+ The result of command.
+ errors:
+ - self.Error.UnsupportedCommand
+ - self.Error.InvalidParameter
+ - self.Error.IOError
+
+ - name: softReboot
+ description: >
+ Soft Reboot system.
+ returns:
+ - name: state
+ type: int32
+ description: >
+ The result of command.
+ errors:
+ - self.Error.UnsupportedCommand
+ - self.Error.InvalidParameter
+ - self.Error.IOError
+
+ - name: quiesce
+ description: >
+ Quiesce system.
+ returns:
+ - name: state
+ type: int32
+ description: >
+ The result of command.
+ errors:
+ - self.Error.UnsupportedCommand
+ - self.Error.InvalidParameter
+ - self.Error.IOError
+
+ - name: getPowerState
+ description: >
+ Get system power state.
+ returns:
+ - name: state
+ type: int32
+ description: >
+ The result of command.
+ errors:
+ - self.Error.UnsupportedCommand
+ - self.Error.InvalidParameter
+ - self.Error.IOError
+