treewide: remove 'using namespace' from headers
Using namespace at global scope in a header file violates the cpp core
guidelines. Quoting the guidelines:
"Doing so takes away an #includer’s ability to effectively
disambiguate and to use alternatives. It also makes #included headers
order-dependent as they might have different meaning when included in
different orders."
For further reading:
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rs-using-directive
The guidelines don't call out using using namespace from namespace
scope, but it is only marginally less problematic and still unexpected,
so this patch removes those as well.
The process used to do the update is roughly:
1 - git grep 'using namespace' **.hpp
2 - For each instance, remove the offending 'using namespace' line
3 - build
4 - add 'using namespace' to cpp files or fully resolve types in hpp
files until the project builds again.
Further cleanup is possible - for example cpp files could be scrubbed
for unnecessary namespace qualification - this was not done here to make
review as simple as possible.
Change-Id: I4931f5e78a1b5b74b4a4774c035a549f4d59b91a
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/host-bmc/dbus_to_event_handler.cpp b/host-bmc/dbus_to_event_handler.cpp
index bb38cb8..69faa1a 100644
--- a/host-bmc/dbus_to_event_handler.cpp
+++ b/host-bmc/dbus_to_event_handler.cpp
@@ -7,7 +7,10 @@
namespace pldm
{
+using namespace pldm::dbus_api;
+using namespace pldm::responder;
using namespace pldm::responder::pdr;
+using namespace pldm::responder::pdr_utils;
using namespace pldm::utils;
using namespace sdbusplus::bus::match::rules;
diff --git a/host-bmc/dbus_to_event_handler.hpp b/host-bmc/dbus_to_event_handler.hpp
index 2a25243..8818d67 100644
--- a/host-bmc/dbus_to_event_handler.hpp
+++ b/host-bmc/dbus_to_event_handler.hpp
@@ -8,16 +8,13 @@
#include <map>
-using namespace pldm::dbus_api;
-using namespace pldm::responder;
-
namespace pldm
{
using SensorId = uint16_t;
using DbusObjMaps =
- std::map<SensorId,
- std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>>;
+ std::map<SensorId, std::tuple<pldm::responder::pdr_utils::DbusMappings,
+ pldm::responder::pdr_utils::DbusValMaps>>;
using sensorEvent =
std::function<void(SensorId sensorId, const DbusObjMaps& dbusMaps)>;
@@ -44,7 +41,7 @@
* @param[in] handler - PLDM request handler
*/
explicit DbusToPLDMEvent(
- int mctp_fd, uint8_t mctp_eid, Requester& requester,
+ int mctp_fd, uint8_t mctp_eid, pldm::dbus_api::Requester& requester,
pldm::requester::Handler<pldm::requester::Request>* handler);
public:
@@ -52,7 +49,7 @@
* @param[in] repo - pdr utils repo object
* @param[in] dbusMaps - The map of D-Bus mapping and value
*/
- void listenSensorEvent(const pdr_utils::Repo& repo,
+ void listenSensorEvent(const pldm::responder::pdr_utils::Repo& repo,
const DbusObjMaps& dbusMaps);
private:
@@ -77,7 +74,7 @@
/** @brief reference to Requester object, primarily used to access API to
* obtain PLDM instance id.
*/
- Requester& requester;
+ pldm::dbus_api::Requester& requester;
/** @brief D-Bus property changed signal match */
std::vector<std::unique_ptr<sdbusplus::bus::match::match>>
diff --git a/host-bmc/dbus_to_host_effecters.cpp b/host-bmc/dbus_to_host_effecters.cpp
index 6dff8af..ff74788 100644
--- a/host-bmc/dbus_to_host_effecters.cpp
+++ b/host-bmc/dbus_to_host_effecters.cpp
@@ -10,6 +10,8 @@
#include <fstream>
#include <iostream>
+using namespace pldm::utils;
+
namespace pldm
{
namespace host_effecters
diff --git a/host-bmc/dbus_to_host_effecters.hpp b/host-bmc/dbus_to_host_effecters.hpp
index 9c0314d..e274540 100644
--- a/host-bmc/dbus_to_host_effecters.hpp
+++ b/host-bmc/dbus_to_host_effecters.hpp
@@ -12,13 +12,11 @@
namespace pldm
{
-using namespace utils;
-using namespace dbus_api;
-
namespace host_effecters
{
-using DbusChgHostEffecterProps = std::map<dbus::Property, PropertyValue>;
+using DbusChgHostEffecterProps =
+ std::map<dbus::Property, pldm::utils::PropertyValue>;
/** @struct State
* Contains the state set id and the possible states for
@@ -35,8 +33,9 @@
*/
struct DBusEffecterMapping
{
- DBusMapping dbusMap;
- std::vector<PropertyValue> propertyValues; //!< D-Bus property values
+ pldm::utils::DBusMapping dbusMap;
+ std::vector<pldm::utils::PropertyValue>
+ propertyValues; //!< D-Bus property values
PossibleState state; //!< Corresponding effecter states
};
@@ -80,8 +79,9 @@
* @param[in] verbose - verbosity
*/
explicit HostEffecterParser(
- Requester* requester, int fd, const pldm_pdr* repo,
- DBusHandler* const dbusHandler, const std::string& jsonPath,
+ pldm::dbus_api::Requester* requester, int fd, const pldm_pdr* repo,
+ pldm::utils::DBusHandler* const dbusHandler,
+ const std::string& jsonPath,
pldm::requester::Handler<pldm::requester::Request>* handler,
bool verbose = false) :
requester(requester),
@@ -125,9 +125,10 @@
* @param[in] propertyType - type of the D-Bus property
* @return - none
*/
- void populatePropVals(const Json& dBusValues,
- std::vector<PropertyValue>& propertyValues,
- const std::string& propertyType);
+ void populatePropVals(
+ const pldm::utils::Json& dBusValues,
+ std::vector<pldm::utils::PropertyValue>& propertyValues,
+ const std::string& propertyType);
/* @brief Set a host state effecter
*
@@ -151,7 +152,7 @@
* @return - the new state value
*/
uint8_t findNewStateValue(size_t effecterInfoIndex, size_t dbusInfoIndex,
- const PropertyValue& propertyValue);
+ const pldm::utils::PropertyValue& propertyValue);
/* @brief Subscribes for D-Bus property change signal on the specified
* object
@@ -170,14 +171,15 @@
uint16_t effecterId);
protected:
- Requester* requester; //!< Reference to Requester to obtain instance id
+ pldm::dbus_api::Requester*
+ requester; //!< Reference to Requester to obtain instance id
int sockFd; //!< Socket fd to send message to host
const pldm_pdr* pdrRepo; //!< Reference to PDR repo
std::vector<EffecterInfo> hostEffecterInfo; //!< Parsed effecter information
std::vector<std::unique_ptr<sdbusplus::bus::match::match>>
effecterInfoMatch; //!< vector to catch the D-Bus property change
//!< signals for the effecters
- const DBusHandler* dbusHandler; //!< D-bus Handler
+ const pldm::utils::DBusHandler* dbusHandler; //!< D-bus Handler
/** @brief PLDM request handler */
pldm::requester::Handler<pldm::requester::Request>* handler;
bool verbose; //!< verbose flag
diff --git a/host-bmc/host_pdr_handler.cpp b/host-bmc/host_pdr_handler.cpp
index 8941d94..d5df188 100644
--- a/host-bmc/host_pdr_handler.cpp
+++ b/host-bmc/host_pdr_handler.cpp
@@ -17,6 +17,8 @@
namespace pldm
{
+using namespace pldm::dbus_api;
+using namespace pldm::responder::events;
using namespace pldm::utils;
using namespace sdbusplus::bus::match::rules;
using Json = nlohmann::json;
diff --git a/host-bmc/host_pdr_handler.hpp b/host-bmc/host_pdr_handler.hpp
index dc539ce..4629f5a 100644
--- a/host-bmc/host_pdr_handler.hpp
+++ b/host-bmc/host_pdr_handler.hpp
@@ -18,9 +18,6 @@
#include <memory>
#include <vector>
-using namespace pldm::dbus_api;
-using namespace pldm::responder::events;
-
namespace pldm
{
@@ -104,7 +101,8 @@
int mctp_fd, uint8_t mctp_eid, sdeventplus::Event& event,
pldm_pdr* repo, const std::string& eventsJsonsDir,
pldm_entity_association_tree* entityTree,
- pldm_entity_association_tree* bmcEntityTree, Requester& requester,
+ pldm_entity_association_tree* bmcEntityTree,
+ pldm::dbus_api::Requester& requester,
pldm::requester::Handler<pldm::requester::Request>* handler,
bool verbose = false);
@@ -143,8 +141,9 @@
*
* @return PLDM completion code
*/
- int handleStateSensorEvent(const StateSensorEntry& entry,
- pdr::EventState state);
+ int handleStateSensorEvent(
+ const pldm::responder::events::StateSensorEntry& entry,
+ pdr::EventState state);
/** @brief Parse state sensor PDRs and populate the sensorMap lookup data
* structure
@@ -232,7 +231,7 @@
/** @brief pointer to BMC's primary PDR repo, host PDRs are added here */
pldm_pdr* repo;
- StateSensorHandler stateSensorHandler;
+ pldm::responder::events::StateSensorHandler stateSensorHandler;
/** @brief Pointer to BMC's and Host's entity association tree */
pldm_entity_association_tree* entityTree;
@@ -242,7 +241,7 @@
/** @brief reference to Requester object, primarily used to access API to
* obtain PLDM instance id.
*/
- Requester& requester;
+ pldm::dbus_api::Requester& requester;
/** @brief PLDM request handler */
pldm::requester::Handler<pldm::requester::Request>* handler;