sched-host-tran: add base interfaces for Scheduled Host Transition
Implement interfaces to get/set scheduledTime and requestedTransition.
Tested:
1. Check scheduledTime
# busctl get-property xyz.openbmc_project.State.ScheduledHostTransition \
/xyz/openbmc_project/state/host0 \
xyz.openbmc_project.State.ScheduledHostTransition ScheduledTime
t 0
# busctl set-property xyz.openbmc_project.State.ScheduledHostTransition \
/xyz/openbmc_project/state/host0 \
xyz.openbmc_project.State.ScheduledHostTransition ScheduledTime t 1
# busctl get-property xyz.openbmc_project.State.ScheduledHostTransition \
/xyz/openbmc_project/state/host0 \
xyz.openbmc_project.State.ScheduledHostTransition ScheduledTime
t 1
2. Check requestedTransition
# busctl get-property xyz.openbmc_project.State.ScheduledHostTransition \
/xyz/openbmc_project/state/host0 \
xyz.openbmc_project.State.ScheduledHostTransition RequestedTransition
s "xyz.openbmc_project.State.Host.Transition.On"
# busctl set-property xyz.openbmc_project.State.ScheduledHostTransition \
/xyz/openbmc_project/state/host0 \
xyz.openbmc_project.State.ScheduledHostTransition RequestedTransition \
s "xyz.openbmc_project.State.Host.Transition.Off"
# busctl get-property xyz.openbmc_project.State.ScheduledHostTransition \
/xyz/openbmc_project/state/host0 \
xyz.openbmc_project.State.ScheduledHostTransition RequestedTransition
s "xyz.openbmc_project.State.Host.Transition.Off"
Change-Id: Ie7da8034d37c1069db043772f35982ca821826ae
Signed-off-by: Carol Wang <wangkair@cn.ibm.com>
diff --git a/meson.build b/meson.build
index f4eb4bb..5359c5e 100644
--- a/meson.build
+++ b/meson.build
@@ -31,6 +31,8 @@
'POH_COUNTER_PERSIST_PATH', get_option('poh-counter-persist-path'))
conf.set_quoted(
'CHASSIS_STATE_CHANGE_PERSIST_PATH', get_option('chassis-state-change-persist-path'))
+conf.set_quoted(
+ 'SCHEDULED_HOST_TRANSITION_BUSNAME', get_option('scheduled-host-transition-busname'))
conf.set(
'BOOT_COUNT_MAX_ALLOWED', get_option('boot-count-max-allowed'))
conf.set(
@@ -109,6 +111,16 @@
install: true
)
+executable('phosphor-scheduled-host-transition',
+ 'scheduled_host_transition_main.cpp',
+ 'scheduled_host_transition.cpp',
+ dependencies: [
+ sdbusplus, sdeventplus, phosphorlogging
+ ],
+ implicit_include_directories: true,
+ install: true
+)
+
install_data('obmcutil',
install_mode: 'rwxr-xr-x',
install_dir: get_option('bindir')
diff --git a/meson_options.txt b/meson_options.txt
index 0de6b75..443e85c 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -71,3 +71,9 @@
value: 1,
description: 'Class version to register with Cereal.',
)
+
+option(
+ 'scheduled-host-transition-busname', type: 'string',
+ value: 'xyz.openbmc_project.State.ScheduledHostTransition',
+ description: 'The scheduled host transition Dbus busname to own.',
+)
diff --git a/scheduled_host_transition.cpp b/scheduled_host_transition.cpp
new file mode 100644
index 0000000..e636579
--- /dev/null
+++ b/scheduled_host_transition.cpp
@@ -0,0 +1,20 @@
+#include "scheduled_host_transition.hpp"
+
+namespace phosphor
+{
+namespace state
+{
+namespace manager
+{
+
+using HostTransition =
+ sdbusplus::xyz::openbmc_project::State::server::ScheduledHostTransition;
+
+uint64_t ScheduledHostTransition::scheduledTime(uint64_t value)
+{
+ return HostTransition::scheduledTime(value);
+}
+
+} // namespace manager
+} // namespace state
+} // namespace phosphor
diff --git a/scheduled_host_transition.hpp b/scheduled_host_transition.hpp
new file mode 100644
index 0000000..ebf3fba
--- /dev/null
+++ b/scheduled_host_transition.hpp
@@ -0,0 +1,44 @@
+#pragma once
+
+#include <sdbusplus/bus.hpp>
+#include <phosphor-logging/log.hpp>
+#include <xyz/openbmc_project/State/ScheduledHostTransition/server.hpp>
+
+namespace phosphor
+{
+namespace state
+{
+namespace manager
+{
+
+using ScheduledHostTransitionInherit = sdbusplus::server::object::object<
+ sdbusplus::xyz::openbmc_project::State::server::ScheduledHostTransition>;
+
+/** @class ScheduledHostTransition
+ * @brief Scheduled host transition implementation.
+ * @details A concrete implementation for
+ * xyz.openbmc_project.State.ScheduledHostTransition
+ */
+class ScheduledHostTransition : public ScheduledHostTransitionInherit
+{
+ public:
+ ScheduledHostTransition(sdbusplus::bus::bus& bus, const char* objPath) :
+ ScheduledHostTransitionInherit(bus, objPath)
+ {
+ }
+
+ ~ScheduledHostTransition() = default;
+
+ /**
+ * @brief Handle with scheduled time
+ *
+ * @param[in] value - The seconds since epoch
+ * @return The time for the transition. It is the same as the input value if
+ * it is set successfully. Otherwise, it won't return value, but throw an
+ * error.
+ **/
+ uint64_t scheduledTime(uint64_t value) override;
+};
+} // namespace manager
+} // namespace state
+} // namespace phosphor
\ No newline at end of file
diff --git a/scheduled_host_transition_main.cpp b/scheduled_host_transition_main.cpp
new file mode 100644
index 0000000..40a3d4d
--- /dev/null
+++ b/scheduled_host_transition_main.cpp
@@ -0,0 +1,29 @@
+#include <cstdlib>
+#include <iostream>
+#include <exception>
+#include <sdbusplus/bus.hpp>
+#include "config.h"
+#include "scheduled_host_transition.hpp"
+
+int main()
+{
+ auto bus = sdbusplus::bus::new_default();
+
+ // For now, we only have one instance of the host
+ auto objPathInst = std::string{HOST_OBJPATH} + '0';
+
+ // Add sdbusplus ObjectManager.
+ sdbusplus::server::manager::manager objManager(bus, objPathInst.c_str());
+
+ phosphor::state::manager::ScheduledHostTransition manager(
+ bus, objPathInst.c_str());
+
+ bus.request_name(SCHEDULED_HOST_TRANSITION_BUSNAME);
+
+ while (true)
+ {
+ bus.process_discard();
+ bus.wait();
+ }
+ return 0;
+}