move implementation to ipmi file
Move the entrance point for the IPMI OEM handling to a separate file and
pass in the handler pointer via binding.
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I4371ebee1c252ab6e9d8a7ff2389583919ecc996
diff --git a/Makefile.am b/Makefile.am
index 59adc1d..43f65aa 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -48,7 +48,8 @@
pcie_i2c.cpp \
entity_name.cpp \
handler.cpp \
- util.cpp
+ util.cpp \
+ ipmi.cpp
libsyscmds_common_la_CXXFLAGS = \
$(SDBUSPLUS_CFLAGS) \
$(PHOSPHOR_LOGGING_CFLAGS) \
diff --git a/cable.cpp b/cable.cpp
index c0eac48..aaf876e 100644
--- a/cable.cpp
+++ b/cable.cpp
@@ -18,7 +18,7 @@
#include "errors.hpp"
#include "handler.hpp"
-#include "main.hpp"
+#include "ipmi.hpp"
#include <cstdint>
#include <cstring>
diff --git a/cpld.cpp b/cpld.cpp
index 77d55d6..5e4fede 100644
--- a/cpld.cpp
+++ b/cpld.cpp
@@ -18,7 +18,7 @@
#include "errors.hpp"
#include "handler.hpp"
-#include "main.hpp"
+#include "ipmi.hpp"
#include <cstring>
diff --git a/entity_name.cpp b/entity_name.cpp
index 9a62f81..8b03acd 100644
--- a/entity_name.cpp
+++ b/entity_name.cpp
@@ -18,7 +18,7 @@
#include "errors.hpp"
#include "handler.hpp"
-#include "main.hpp"
+#include "ipmi.hpp"
#include <cstdint>
#include <cstring>
diff --git a/eth.cpp b/eth.cpp
index 2d21c57..2b38939 100644
--- a/eth.cpp
+++ b/eth.cpp
@@ -17,7 +17,7 @@
#include "eth.hpp"
#include "handler.hpp"
-#include "main.hpp"
+#include "ipmi.hpp"
#include <cstdint>
#include <cstring>
diff --git a/ipmi.cpp b/ipmi.cpp
new file mode 100644
index 0000000..8ee9c42
--- /dev/null
+++ b/ipmi.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * 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 "ipmi.hpp"
+
+#include "cable.hpp"
+#include "cpld.hpp"
+#include "entity_name.hpp"
+#include "eth.hpp"
+#include "handler_impl.hpp"
+#include "pcie_i2c.hpp"
+#include "psu.hpp"
+
+#include <ipmid/api.h>
+
+#include <cstdint>
+#include <cstdio>
+
+namespace google
+{
+namespace ipmi
+{
+
+ipmi_ret_t handleSysCommand(HandlerInterface* handler, ipmi_cmd_t cmd,
+ const uint8_t* reqBuf, uint8_t* replyCmdBuf,
+ size_t* dataLen)
+{
+ // Verify it's at least as long as it needs to be for a subcommand.
+ if ((*dataLen) < 1)
+ {
+ std::fprintf(stderr, "*dataLen too small: %u\n",
+ static_cast<uint32_t>(*dataLen));
+ return IPMI_CC_REQ_DATA_LEN_INVALID;
+ }
+
+ switch (reqBuf[0])
+ {
+ case SysCableCheck:
+ return cableCheck(reqBuf, replyCmdBuf, dataLen, handler);
+ case SysCpldVersion:
+ return cpldVersion(reqBuf, replyCmdBuf, dataLen, handler);
+ case SysGetEthDevice:
+ return getEthDevice(reqBuf, replyCmdBuf, dataLen, handler);
+ case SysPsuHardReset:
+ return psuHardReset(reqBuf, replyCmdBuf, dataLen, handler);
+ case SysPcieSlotCount:
+ return pcieSlotCount(reqBuf, replyCmdBuf, dataLen, handler);
+ case SysPcieSlotI2cBusMapping:
+ return pcieSlotI2cBusMapping(reqBuf, replyCmdBuf, dataLen, handler);
+ case SysEntityName:
+ return getEntityName(reqBuf, replyCmdBuf, dataLen, handler);
+ default:
+ std::fprintf(stderr, "Invalid subcommand: 0x%x\n", reqBuf[0]);
+ return IPMI_CC_INVALID;
+ }
+}
+
+} // namespace ipmi
+} // namespace google
diff --git a/main.hpp b/ipmi.hpp
similarity index 68%
rename from main.hpp
rename to ipmi.hpp
index dfe8f29..0291949 100644
--- a/main.hpp
+++ b/ipmi.hpp
@@ -1,5 +1,9 @@
#pragma once
+#include "handler.hpp"
+
+#include <ipmid/api.h>
+
namespace google
{
namespace ipmi
@@ -23,5 +27,10 @@
SysEntityName = 6,
};
+// Handle the google-ipmi-sys IPMI OEM commands.
+ipmi_ret_t handleSysCommand(HandlerInterface* handler, ipmi_cmd_t cmd,
+ const uint8_t* reqBuf, uint8_t* replyCmdBuf,
+ size_t* dataLen);
+
} // namespace ipmi
} // namespace google
diff --git a/main.cpp b/main.cpp
index f1cb516..030f56c 100644
--- a/main.cpp
+++ b/main.cpp
@@ -14,20 +14,14 @@
* limitations under the License.
*/
-#include "main.hpp"
-
-#include "cable.hpp"
-#include "cpld.hpp"
-#include "entity_name.hpp"
-#include "eth.hpp"
#include "handler_impl.hpp"
-#include "pcie_i2c.hpp"
-#include "psu.hpp"
+#include "ipmi.hpp"
#include <ipmid/api.h>
#include <cstdint>
#include <cstdio>
+#include <functional>
#include <ipmid/iana.hpp>
#include <ipmid/oemrouter.hpp>
@@ -46,40 +40,6 @@
Handler handlerImpl;
-static ipmi_ret_t handleSysCommand(ipmi_cmd_t cmd, const uint8_t* reqBuf,
- uint8_t* replyCmdBuf, size_t* dataLen)
-{
- // Verify it's at least as long as it needs to be for a subcommand.
- if ((*dataLen) < 1)
- {
- std::fprintf(stderr, "*dataLen too small: %u\n",
- static_cast<uint32_t>(*dataLen));
- return IPMI_CC_REQ_DATA_LEN_INVALID;
- }
-
- switch (reqBuf[0])
- {
- case SysCableCheck:
- return cableCheck(reqBuf, replyCmdBuf, dataLen, &handlerImpl);
- case SysCpldVersion:
- return cpldVersion(reqBuf, replyCmdBuf, dataLen, &handlerImpl);
- case SysGetEthDevice:
- return getEthDevice(reqBuf, replyCmdBuf, dataLen, &handlerImpl);
- case SysPsuHardReset:
- return psuHardReset(reqBuf, replyCmdBuf, dataLen, &handlerImpl);
- case SysPcieSlotCount:
- return pcieSlotCount(reqBuf, replyCmdBuf, dataLen, &handlerImpl);
- case SysPcieSlotI2cBusMapping:
- return pcieSlotI2cBusMapping(reqBuf, replyCmdBuf, dataLen,
- &handlerImpl);
- case SysEntityName:
- return getEntityName(reqBuf, replyCmdBuf, dataLen, &handlerImpl);
- default:
- std::fprintf(stderr, "Invalid subcommand: 0x%x\n", reqBuf[0]);
- return IPMI_CC_INVALID;
- }
-}
-
void setupGoogleOemSysCommands() __attribute__((constructor));
void setupGoogleOemSysCommands()
@@ -90,8 +50,10 @@
"Registering OEM:[%#08X], Cmd:[%#04X] for Sys Commands\n",
oem::googOemNumber, oem::google::sysCmd);
- oemRouter->registerHandler(oem::googOemNumber, oem::google::sysCmd,
- handleSysCommand);
+ using namespace std::placeholders;
+ oemRouter->registerHandler(
+ oem::googOemNumber, oem::google::sysCmd,
+ std::bind(handleSysCommand, &handlerImpl, _1, _2, _3, _4));
}
} // namespace ipmi
diff --git a/pcie_i2c.cpp b/pcie_i2c.cpp
index 625c063..989ef41 100644
--- a/pcie_i2c.cpp
+++ b/pcie_i2c.cpp
@@ -16,7 +16,7 @@
#include "pcie_i2c.hpp"
-#include "main.hpp"
+#include "ipmi.hpp"
#include <cstdint>
#include <cstring>
diff --git a/psu.cpp b/psu.cpp
index a5abda5..3876fcf 100644
--- a/psu.cpp
+++ b/psu.cpp
@@ -18,7 +18,7 @@
#include "errors.hpp"
#include "handler.hpp"
-#include "main.hpp"
+#include "ipmi.hpp"
#include <cstdint>
#include <cstring>
diff --git a/test/cable_unittest.cpp b/test/cable_unittest.cpp
index b181584..39384f8 100644
--- a/test/cable_unittest.cpp
+++ b/test/cable_unittest.cpp
@@ -1,6 +1,6 @@
#include "cable.hpp"
#include "handler_mock.hpp"
-#include "main.hpp"
+#include "ipmi.hpp"
#include <cstdint>
#include <cstring>
diff --git a/test/cpld_unittest.cpp b/test/cpld_unittest.cpp
index 12a0444..8b22ff1 100644
--- a/test/cpld_unittest.cpp
+++ b/test/cpld_unittest.cpp
@@ -1,6 +1,6 @@
#include "cpld.hpp"
#include "handler_mock.hpp"
-#include "main.hpp"
+#include "ipmi.hpp"
#include <cstdint>
#include <tuple>
diff --git a/test/entity_unittest.cpp b/test/entity_unittest.cpp
index 0a76d86..5ef6d82 100644
--- a/test/entity_unittest.cpp
+++ b/test/entity_unittest.cpp
@@ -1,6 +1,6 @@
#include "entity_name.hpp"
#include "handler_mock.hpp"
-#include "main.hpp"
+#include "ipmi.hpp"
#include <cstdint>
#include <cstring>
diff --git a/test/eth_unittest.cpp b/test/eth_unittest.cpp
index af1a9cc..6c4b98a 100644
--- a/test/eth_unittest.cpp
+++ b/test/eth_unittest.cpp
@@ -1,6 +1,6 @@
#include "eth.hpp"
#include "handler_mock.hpp"
-#include "main.hpp"
+#include "ipmi.hpp"
#include <cstdint>
#include <cstring>
diff --git a/test/pcie_unittest.cpp b/test/pcie_unittest.cpp
index 84bbe5c..796d97a 100644
--- a/test/pcie_unittest.cpp
+++ b/test/pcie_unittest.cpp
@@ -1,5 +1,5 @@
#include "handler_mock.hpp"
-#include "main.hpp"
+#include "ipmi.hpp"
#include "pcie_i2c.hpp"
#include <cstdint>
diff --git a/test/psu_unittest.cpp b/test/psu_unittest.cpp
index 7805370..c2a7a53 100644
--- a/test/psu_unittest.cpp
+++ b/test/psu_unittest.cpp
@@ -1,5 +1,5 @@
#include "handler_mock.hpp"
-#include "main.hpp"
+#include "ipmi.hpp"
#include "psu.hpp"
#include <cstdint>