tools: put all host-side code into host_tool namespace
To avoid confusion and organize the code itself more cleanly, place the
host-side code into its own namespace.
Change-Id: I573eb0494eb59874adb1d1eadc502499e928e396
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/test/blob_interface_mock.hpp b/test/blob_interface_mock.hpp
index fc1b284..c3b4f4c 100644
--- a/test/blob_interface_mock.hpp
+++ b/test/blob_interface_mock.hpp
@@ -2,6 +2,9 @@
#include <gmock/gmock.h>
+namespace host_tool
+{
+
class BlobInterfaceMock : public BlobInterface
{
public:
@@ -12,3 +15,5 @@
std::uint16_t(const std::string&,
blobs::FirmwareBlobHandler::UpdateFlags));
};
+
+} // namespace host_tool
diff --git a/test/data_interface_mock.hpp b/test/data_interface_mock.hpp
index 6335ad2..3e8f24a 100644
--- a/test/data_interface_mock.hpp
+++ b/test/data_interface_mock.hpp
@@ -4,6 +4,9 @@
#include <gmock/gmock.h>
+namespace host_tool
+{
+
class DataInterfaceMock : public DataInterface
{
@@ -14,3 +17,5 @@
MOCK_CONST_METHOD0(supportedType,
blobs::FirmwareBlobHandler::UpdateFlags());
};
+
+} // namespace host_tool
diff --git a/test/ipmi_interface_mock.hpp b/test/ipmi_interface_mock.hpp
index 2fac71d..409ef44 100644
--- a/test/ipmi_interface_mock.hpp
+++ b/test/ipmi_interface_mock.hpp
@@ -4,6 +4,9 @@
#include <gmock/gmock.h>
+namespace host_tool
+{
+
class IpmiInterfaceMock : public IpmiInterface
{
public:
@@ -11,3 +14,5 @@
MOCK_METHOD1(sendPacket,
std::vector<std::uint8_t>(const std::vector<std::uint8_t>&));
};
+
+} // namespace host_tool
diff --git a/test/tools_blob_unittest.cpp b/test/tools_blob_unittest.cpp
index f3a01c1..8205d3a 100644
--- a/test/tools_blob_unittest.cpp
+++ b/test/tools_blob_unittest.cpp
@@ -4,6 +4,8 @@
#include <gtest/gtest.h>
+namespace host_tool
+{
CrcInterface* crcIntf = nullptr;
std::uint16_t generateCrc(const std::vector<std::uint8_t>& data)
@@ -211,3 +213,5 @@
blob.openBlob("abcd", blobs::FirmwareBlobHandler::UpdateFlags::lpc);
EXPECT_EQ(0xedfe, session);
}
+
+} // namespace host_tool
diff --git a/test/tools_updater_unittest.cpp b/test/tools_updater_unittest.cpp
index bc7417c..0f49494 100644
--- a/test/tools_updater_unittest.cpp
+++ b/test/tools_updater_unittest.cpp
@@ -6,6 +6,9 @@
#include <gtest/gtest.h>
+namespace host_tool
+{
+
using ::testing::Eq;
using ::testing::Return;
using ::testing::StrEq;
@@ -43,3 +46,5 @@
updaterMain(&blobMock, &handlerMock, firmwareImage, signatureFile);
}
+
+} // namespace host_tool
diff --git a/tools/blob_errors.hpp b/tools/blob_errors.hpp
index b737b7b..45f0e46 100644
--- a/tools/blob_errors.hpp
+++ b/tools/blob_errors.hpp
@@ -3,6 +3,9 @@
#include <exception>
#include <string>
+namespace host_tool
+{
+
class BlobException : public std::exception
{
public:
@@ -16,3 +19,5 @@
private:
std::string message;
};
+
+} // namespace host_tool
diff --git a/tools/blob_handler.cpp b/tools/blob_handler.cpp
index 62bbb4d..42098cc 100644
--- a/tools/blob_handler.cpp
+++ b/tools/blob_handler.cpp
@@ -23,7 +23,13 @@
#include <array>
#include <cstring>
+namespace host_tool
+{
+
+namespace
+{
const std::array<std::uint8_t, 3> ipmiPhosphorOen = {0xcf, 0xc2, 0x00};
+}
std::vector<std::uint8_t>
BlobHandler::sendIpmiPayload(BlobOEMCommands command,
@@ -231,3 +237,5 @@
std::memcpy(&session, resp.data(), sizeof(session));
return session;
}
+
+} // namespace host_tool
diff --git a/tools/blob_handler.hpp b/tools/blob_handler.hpp
index 73f0d94..c22d326 100644
--- a/tools/blob_handler.hpp
+++ b/tools/blob_handler.hpp
@@ -3,6 +3,9 @@
#include "blob_interface.hpp"
#include "ipmi_interface.hpp"
+namespace host_tool
+{
+
class BlobHandler : public BlobInterface
{
public:
@@ -68,3 +71,5 @@
private:
IpmiInterface* ipmi;
};
+
+} // namespace host_tool
diff --git a/tools/blob_interface.hpp b/tools/blob_interface.hpp
index 012550e..7e22849 100644
--- a/tools/blob_interface.hpp
+++ b/tools/blob_interface.hpp
@@ -6,6 +6,9 @@
#include <string>
#include <vector>
+namespace host_tool
+{
+
struct StatResponse
{
std::uint16_t blob_state;
@@ -45,3 +48,5 @@
openBlob(const std::string& id,
blobs::FirmwareBlobHandler::UpdateFlags handlerFlags) = 0;
};
+
+} // namespace host_tool
diff --git a/tools/bt.cpp b/tools/bt.cpp
index de26b27..da582d4 100644
--- a/tools/bt.cpp
+++ b/tools/bt.cpp
@@ -1,7 +1,12 @@
#include "bt.hpp"
+namespace host_tool
+{
+
bool BtDataHandler::sendContents(const std::string& input,
std::uint16_t session)
{
return false;
}
+
+} // namespace host_tool
diff --git a/tools/bt.hpp b/tools/bt.hpp
index 10050b6..d4710ce 100644
--- a/tools/bt.hpp
+++ b/tools/bt.hpp
@@ -3,6 +3,9 @@
#include "blob_interface.hpp"
#include "interface.hpp"
+namespace host_tool
+{
+
class BtDataHandler : public DataInterface
{
public:
@@ -19,3 +22,5 @@
blobs::FirmwareBlobHandler::UpdateFlags flags =
blobs::FirmwareBlobHandler::UpdateFlags::ipmi;
};
+
+} // namespace host_tool
diff --git a/tools/crc.cpp b/tools/crc.cpp
index 4ed307b..e8083eb 100644
--- a/tools/crc.cpp
+++ b/tools/crc.cpp
@@ -1,5 +1,8 @@
#include "crc.hpp"
+namespace host_tool
+{
+
/*
* This implementation tracks the specification given at
* http://srecord.sourceforge.net/crc16-ccitt.html
@@ -37,3 +40,5 @@
return crc;
}
+
+} // namespace host_tool
diff --git a/tools/crc.hpp b/tools/crc.hpp
index f377a20..c335ed2 100644
--- a/tools/crc.hpp
+++ b/tools/crc.hpp
@@ -3,6 +3,9 @@
#include <cstdint>
#include <vector>
+namespace host_tool
+{
+
/**
* Generate the CRC for a payload (really any bytes).
*
@@ -13,3 +16,5 @@
* @return the CRC value
*/
std::uint16_t generateCrc(const std::vector<std::uint8_t>& data);
+
+} // namespace host_tool
diff --git a/tools/interface.hpp b/tools/interface.hpp
index 0294c1d..4a72313 100644
--- a/tools/interface.hpp
+++ b/tools/interface.hpp
@@ -5,6 +5,9 @@
#include <cstdint>
#include <string>
+namespace host_tool
+{
+
class DataInterface
{
public:
@@ -29,3 +32,5 @@
*/
virtual blobs::FirmwareBlobHandler::UpdateFlags supportedType() const = 0;
};
+
+} // namespace host_tool
diff --git a/tools/ipmi_errors.hpp b/tools/ipmi_errors.hpp
index fd1f032..994f837 100644
--- a/tools/ipmi_errors.hpp
+++ b/tools/ipmi_errors.hpp
@@ -4,6 +4,9 @@
#include <sstream>
#include <string>
+namespace host_tool
+{
+
class IpmiException : public std::exception
{
public:
@@ -22,3 +25,5 @@
private:
std::string message;
};
+
+} // namespace host_tool
diff --git a/tools/ipmi_handler.cpp b/tools/ipmi_handler.cpp
index 76bd3e0..a0c1198 100644
--- a/tools/ipmi_handler.cpp
+++ b/tools/ipmi_handler.cpp
@@ -16,8 +16,13 @@
#include "ipmi_handler.hpp"
+namespace host_tool
+{
+
std::vector<std::uint8_t>
IpmiHandler::sendPacket(const std::vector<std::uint8_t>& data)
{
return {};
}
+
+} // namespace host_tool
diff --git a/tools/ipmi_handler.hpp b/tools/ipmi_handler.hpp
index 9e86f42..144fc22 100644
--- a/tools/ipmi_handler.hpp
+++ b/tools/ipmi_handler.hpp
@@ -2,6 +2,9 @@
#include "ipmi_interface.hpp"
+namespace host_tool
+{
+
class IpmiHandler : public IpmiInterface
{
public:
@@ -10,3 +13,5 @@
std::vector<std::uint8_t>
sendPacket(const std::vector<std::uint8_t>& data) override;
};
+
+} // namespace host_tool
diff --git a/tools/ipmi_interface.hpp b/tools/ipmi_interface.hpp
index 082af9c..8be624c 100644
--- a/tools/ipmi_interface.hpp
+++ b/tools/ipmi_interface.hpp
@@ -3,6 +3,9 @@
#include <cstdint>
#include <vector>
+namespace host_tool
+{
+
class IpmiInterface
{
public:
@@ -18,3 +21,5 @@
virtual std::vector<std::uint8_t>
sendPacket(const std::vector<std::uint8_t>& data) = 0;
};
+
+} // namespace host_tool
diff --git a/tools/lpc.cpp b/tools/lpc.cpp
index 9e8e01d..97b7902 100644
--- a/tools/lpc.cpp
+++ b/tools/lpc.cpp
@@ -16,8 +16,13 @@
#include "lpc.hpp"
+namespace host_tool
+{
+
bool LpcDataHandler::sendContents(const std::string& input,
std::uint16_t session)
{
return false;
}
+
+} // namespace host_tool
diff --git a/tools/lpc.hpp b/tools/lpc.hpp
index 4b53f26..913fc5d 100644
--- a/tools/lpc.hpp
+++ b/tools/lpc.hpp
@@ -3,6 +3,9 @@
#include "blob_interface.hpp"
#include "interface.hpp"
+namespace host_tool
+{
+
class LpcDataHandler : public DataInterface
{
public:
@@ -19,3 +22,5 @@
blobs::FirmwareBlobHandler::UpdateFlags flags =
blobs::FirmwareBlobHandler::UpdateFlags::lpc;
};
+
+} // namespace host_tool
diff --git a/tools/main.cpp b/tools/main.cpp
index cc0c707..547d50e 100644
--- a/tools/main.cpp
+++ b/tools/main.cpp
@@ -136,19 +136,19 @@
exit(EXIT_FAILURE);
}
- IpmiHandler ipmi;
- BlobHandler blob(&ipmi);
+ host_tool::IpmiHandler ipmi;
+ host_tool::BlobHandler blob(&ipmi);
- std::unique_ptr<DataInterface> handler;
+ std::unique_ptr<host_tool::DataInterface> handler;
/* Input has already been validated in this case. */
if (interface == IPMIBT)
{
- handler = std::make_unique<BtDataHandler>(&blob);
+ handler = std::make_unique<host_tool::BtDataHandler>(&blob);
}
else if (interface == IPMILPC)
{
- handler = std::make_unique<LpcDataHandler>(&blob);
+ handler = std::make_unique<host_tool::LpcDataHandler>(&blob);
}
if (!handler)
@@ -162,9 +162,10 @@
/* The parameters are all filled out. */
try
{
- updaterMain(&blob, handler.get(), imagePath, signaturePath);
+ host_tool::updaterMain(&blob, handler.get(), imagePath,
+ signaturePath);
}
- catch (const ToolException& e)
+ catch (const host_tool::ToolException& e)
{
std::fprintf(stderr, "Exception received: %s\n", e.what());
return -1;
diff --git a/tools/tool_errors.hpp b/tools/tool_errors.hpp
index af99c2c..cf898e6 100644
--- a/tools/tool_errors.hpp
+++ b/tools/tool_errors.hpp
@@ -3,6 +3,9 @@
#include <exception>
#include <string>
+namespace host_tool
+{
+
class ToolException : public std::exception
{
public:
@@ -16,3 +19,5 @@
private:
std::string message;
};
+
+} // namespace host_tool
diff --git a/tools/updater.cpp b/tools/updater.cpp
index b7ea191..6fed1d6 100644
--- a/tools/updater.cpp
+++ b/tools/updater.cpp
@@ -23,6 +23,9 @@
#include <cstring>
#include <memory>
+namespace host_tool
+{
+
void updaterMain(BlobInterface* blob, DataInterface* handler,
const std::string& imagePath, const std::string& signaturePath)
{
@@ -95,3 +98,5 @@
return;
}
+
+} // namespace host_tool
diff --git a/tools/updater.hpp b/tools/updater.hpp
index 886ff67..adee496 100644
--- a/tools/updater.hpp
+++ b/tools/updater.hpp
@@ -5,6 +5,9 @@
#include <string>
+namespace host_tool
+{
+
/**
* Attempt to update the BMC's firmware using the interface provided.
*
@@ -17,3 +20,5 @@
void updaterMain(BlobInterface* blob, DataInterface* handler,
const std::string& imagePath,
const std::string& signaturePath);
+
+} // namespace host_tool