Implement org.open_power.OCC.PassThrough
This d-bus interface is implemented by the
open_power::occ::pass_through::PassThrough class.
Change-Id: I6bce9e609b7b977418bcfee15e97432cb7d9e6b3
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/Makefile.am b/Makefile.am
index 2ee9f0f..2bdbd26 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,10 +1,12 @@
# Build these headers, don't install them
noinst_HEADERS = \
- occ_finder.hpp
+ occ_finder.hpp \
+ occ_pass_through.hpp
sbin_PROGRAMS = openpower-occ-control
openpower_occ_control_SOURCES = \
occ_finder.cpp \
+ occ_pass_through.cpp \
app.cpp
openpower_occ_control_LDFLAGS = \
diff --git a/app.cpp b/app.cpp
index ffedd45..0ffe711 100644
--- a/app.cpp
+++ b/app.cpp
@@ -1,17 +1,18 @@
-#include <sdbusplus/server.hpp>
-#include "config.h"
+#include <phosphor-logging/log.hpp>
+#include <exception>
+#include "occ_pass_through.hpp"
int main(int argc, char* argv[])
{
- auto bus = sdbusplus::bus::new_default();
- sdbusplus::server::manager::manager objManager(bus,
- OCC_PASS_THROUGH_ROOT);
- bus.request_name(OCC_PASS_THROUGH_BUSNAME);
-
- while (true)
+ try
{
- bus.process_discard();
- bus.wait();
+ open_power::occ::pass_through::run();
+ }
+ catch (const std::exception& e)
+ {
+ using namespace phosphor::logging;
+ log<level::ERR>(e.what());
+ return -1;
}
return 0;
diff --git a/occ_pass_through.cpp b/occ_pass_through.cpp
new file mode 100644
index 0000000..aef0e04
--- /dev/null
+++ b/occ_pass_through.cpp
@@ -0,0 +1,53 @@
+#include <memory>
+#include <iostream>
+#include "occ_pass_through.hpp"
+#include "occ_finder.hpp"
+
+namespace open_power
+{
+namespace occ
+{
+namespace pass_through
+{
+
+void run()
+{
+ auto bus = sdbusplus::bus::new_default();
+ sdbusplus::server::manager::manager objManager(bus,
+ OCC_PASS_THROUGH_ROOT);
+
+ std::vector<std::unique_ptr<PassThrough>> objects;
+ auto occs = open_power::occ::finder::get();
+
+ for (const auto& occ : occs)
+ {
+ auto occPassThrough = object(occ);
+ objects.emplace_back(
+ std::make_unique<PassThrough>(bus, occPassThrough.c_str()));
+ }
+ bus.request_name(OCC_PASS_THROUGH_BUSNAME);
+
+ while (true)
+ {
+ bus.process_discard();
+ bus.wait();
+ }
+}
+
+PassThrough::PassThrough(
+ sdbusplus::bus::bus& bus,
+ const char* path) :
+ Iface(bus, path),
+ path(path)
+{
+ this->emit_object_added();
+}
+
+std::vector<int32_t> PassThrough::send(std::vector<int32_t> command)
+{
+ return {};
+}
+
+} // namespace pass_through
+} // namespace occ
+} // namespace open_power
diff --git a/occ_pass_through.hpp b/occ_pass_through.hpp
new file mode 100644
index 0000000..835241f
--- /dev/null
+++ b/occ_pass_through.hpp
@@ -0,0 +1,69 @@
+#pragma once
+
+#include <string>
+#include <vector>
+#include <sdbusplus/bus.hpp>
+#include <sdbusplus/server/object.hpp>
+#include "org/open_power/OCC/PassThrough/server.hpp"
+#include "config.h"
+
+namespace open_power
+{
+namespace occ
+{
+namespace pass_through
+{
+
+/** @brief Make occ pass-through d-bus object pathname
+ * @param[in] occ - occ name
+ * @returns occ pass-through path
+ */
+inline auto object(const std::string& occ)
+{
+ return std::string(OCC_PASS_THROUGH_ROOT) +
+ '/' +
+ occ;
+}
+
+/** @brief Put occ pass through objects on the bus
+ */
+void run();
+
+using Iface = sdbusplus::server::object::object<
+ sdbusplus::org::open_power::OCC::server::PassThrough>;
+
+/** @class PassThrough
+ * @brief Implements org.open_power.OCC.PassThrough
+ */
+class PassThrough : public Iface
+{
+ public:
+ PassThrough() = delete;
+ PassThrough(const PassThrough&) = delete;
+ PassThrough& operator=(const PassThrough&) = delete;
+ PassThrough(PassThrough&&) = default;
+ PassThrough& operator=(PassThrough&&) = default;
+ ~PassThrough() = default;
+
+ /** @brief Ctor to put pass-through d-bus object on the bus
+ * @param[in] bus - Bus to attach to
+ * @param[in] path - Path to attach at
+ */
+ PassThrough(sdbusplus::bus::bus& bus,
+ const char* path);
+
+ /** @brief Pass through command to OCC
+ * @param[in] command - command to pass-through
+ * @returns OCC response as an array
+ */
+ std::vector<std::int32_t>
+ send(std::vector<std::int32_t> command) override;
+
+ private:
+ /** @brief Pass-through occ path on the bus */
+ std::string path;
+};
+
+} // namespace pass_through
+} // namespace occ
+} // namespace open_power