clean up using directives and type alias
Most C++ style guides try to avoid using directives in headers and also
suggest using type alias carefully, according to which, this change does
the following clean up:
1. used Enum class to represent Certificate type
2. removed all using directives: e.g. the phosphor logging namespace;
instead, this change uses using declarations
3. removed unnecessary type alias; in existing codes, we only support
strings as types of UnitToRestart, InstallPath, UploadPath, etc; this
change uses std::string directly
4. moved all alias outside any class scope into source files or an
internal namespace
5. renamed types, constants, classes as per OpenBMC style guide
6. fixed all compilation errors and some warnings after the refactoring;
built with both Clang & GCC
Reference:
https://docs.microsoft.com/en-us/cpp/cpp/header-files-cpp?view=msvc-170#what-to-put-in-a-header-file
https://google.github.io/styleguide/cppguide.html#Namespaces
Tested:
Unit tests
Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: I58e026934a4e969f4d8877801c8f3c671990468a
diff --git a/bmc-vmi-ca/ca_cert_entry.hpp b/bmc-vmi-ca/ca_cert_entry.hpp
index 174daba..1b75fa4 100644
--- a/bmc-vmi-ca/ca_cert_entry.hpp
+++ b/bmc-vmi-ca/ca_cert_entry.hpp
@@ -12,12 +12,14 @@
namespace cert
{
-using Delete = sdbusplus::xyz::openbmc_project::Object::server::Delete;
-
-using CertEntry = sdbusplus::xyz::openbmc_project::Certs::server::Entry;
-using CSREntry = sdbusplus::xyz::openbmc_project::PLDM::Provider::Certs::
- Authority::server::CSR;
-using Ifaces = sdbusplus::server::object::object<CSREntry, CertEntry, Delete>;
+namespace internal
+{
+using EntryInterface = sdbusplus::server::object_t<
+ sdbusplus::xyz::openbmc_project::PLDM::Provider::Certs::Authority::server::
+ CSR,
+ sdbusplus::xyz::openbmc_project::Certs::server::Entry,
+ sdbusplus::xyz::openbmc_project::Object::server::Delete>;
+}
class CACertMgr;
@@ -26,7 +28,7 @@
* @details A concrete implementation for the
* xyz.openbmc_project.Certs.Entry DBus API
*/
-class Entry : public Ifaces
+class Entry : public internal::EntryInterface
{
public:
Entry() = delete;
@@ -46,7 +48,7 @@
Entry(sdbusplus::bus::bus& bus, const std::string& objPath,
uint32_t entryId, std::string& csr, std::string& cert,
CACertMgr& manager) :
- Ifaces(bus, objPath.c_str(), true),
+ internal::EntryInterface(bus, objPath.c_str(), true),
bus(bus), id(entryId), manager(manager)
{
diff --git a/bmc-vmi-ca/ca_certs_manager.cpp b/bmc-vmi-ca/ca_certs_manager.cpp
index bbb8025..f08c1e7 100644
--- a/bmc-vmi-ca/ca_certs_manager.cpp
+++ b/bmc-vmi-ca/ca_certs_manager.cpp
@@ -11,12 +11,17 @@
namespace ca::cert
{
-static constexpr auto maxCertSize = 4096;
namespace fs = std::filesystem;
-using namespace phosphor::logging;
-using InvalidArgument =
- sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
-using Argument = xyz::openbmc_project::Common::InvalidArgument;
+using ::phosphor::logging::elog;
+using ::phosphor::logging::entry;
+using ::phosphor::logging::level;
+using ::phosphor::logging::log;
+
+using ::sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
+using Argument =
+ ::phosphor::logging::xyz::openbmc_project::Common::InvalidArgument;
+
+static constexpr size_t maxCertSize = 4096;
sdbusplus::message::object_path CACertMgr::signCSR(std::string csr)
{
diff --git a/bmc-vmi-ca/ca_certs_manager.hpp b/bmc-vmi-ca/ca_certs_manager.hpp
index 21088b6..951c0cf 100644
--- a/bmc-vmi-ca/ca_certs_manager.hpp
+++ b/bmc-vmi-ca/ca_certs_manager.hpp
@@ -11,18 +11,20 @@
namespace ca::cert
{
-class CACertMgr;
-
-using CreateIface = sdbusplus::server::object::object<
+namespace internal
+{
+using ManagerInterface = sdbusplus::server::object_t<
sdbusplus::xyz::openbmc_project::Certs::server::Authority,
sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>;
-using Mgr = ca::cert::CACertMgr;
+}
+
+class CACertMgr;
/** @class Manager
* @brief Implementation for the
* xyz.openbmc_project.Certs.ca.authority.Manager DBus API.
*/
-class CACertMgr : public CreateIface
+class CACertMgr : public internal::ManagerInterface
{
public:
CACertMgr() = delete;
@@ -36,10 +38,9 @@
* @param[in] bus - Bus to attach to.
* @param[in] path - Path to attach at.
*/
- CACertMgr(sdbusplus::bus::bus& bus, sdeventplus::Event& event,
- const char* path) :
- CreateIface(bus, path),
- bus(bus), event(event), objectPath(path), lastEntryId(0){};
+ CACertMgr(sdbusplus::bus::bus& bus, const char* path) :
+ internal::ManagerInterface(bus, path), bus(bus), objectPath(path),
+ lastEntryId(0){};
/** @brief This method provides signing authority functionality.
It signs the certificate and creates the CSR request entry Dbus
@@ -64,8 +65,6 @@
private:
/** @brief sdbusplus DBus bus connection. */
sdbusplus::bus::bus& bus;
- // sdevent Event handle
- sdeventplus::Event& event;
/** @brief object path */
std::string objectPath;
/** @brief Id of the last certificate entry */
diff --git a/bmc-vmi-ca/mainapp.cpp b/bmc-vmi-ca/mainapp.cpp
index 4c6ef1e..c33a69d 100644
--- a/bmc-vmi-ca/mainapp.cpp
+++ b/bmc-vmi-ca/mainapp.cpp
@@ -19,7 +19,7 @@
// Attach the bus to sd_event to service user requests
bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
- ca::cert::CACertMgr manager(bus, event, objPath);
+ ca::cert::CACertMgr manager(bus, objPath);
std::string busName = "xyz.openbmc_project.Certs.ca.authority.Manager";
bus.request_name(busName.c_str());