sensors/zones: place in namespace and cleanup

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I527dbc8477a232945f696227a7b0b2adbee45175
diff --git a/conf.hpp b/conf.hpp
index 559afaa..428d446 100644
--- a/conf.hpp
+++ b/conf.hpp
@@ -7,6 +7,8 @@
 #include <string>
 #include <vector>
 
+namespace pid_control
+{
 namespace conf
 {
 
@@ -59,3 +61,4 @@
 using PIDConf = std::map<std::string, struct ControllerInfo>;
 
 } // namespace conf
+} // namespace pid_control
diff --git a/dbus/dbusactiveread.cpp b/dbus/dbusactiveread.cpp
index 406b391..21f6c4d 100644
--- a/dbus/dbusactiveread.cpp
+++ b/dbus/dbusactiveread.cpp
@@ -22,6 +22,9 @@
 #include <cmath>
 #include <iostream>
 
+namespace pid_control
+{
+
 ReadReturn DbusActiveRead::read(void)
 {
     struct SensorProperties settings;
@@ -39,3 +42,5 @@
 
     return r;
 }
+
+} // namespace pid_control
diff --git a/dbus/dbusactiveread.hpp b/dbus/dbusactiveread.hpp
index 37ff9bc..adf091d 100644
--- a/dbus/dbusactiveread.hpp
+++ b/dbus/dbusactiveread.hpp
@@ -8,6 +8,9 @@
 #include <memory>
 #include <string>
 
+namespace pid_control
+{
+
 /*
  * This ReadInterface will actively reach out over dbus upon calling read to
  * get the value from whomever owns the associated dbus path.
@@ -29,3 +32,5 @@
     const std::string _service; // the sensor service.
     DbusHelperInterface* _helper;
 };
+
+} // namespace pid_control
diff --git a/dbus/dbusconfiguration.cpp b/dbus/dbusconfiguration.cpp
index c1279a4..c3c72bd 100644
--- a/dbus/dbusconfiguration.cpp
+++ b/dbus/dbusconfiguration.cpp
@@ -32,6 +32,9 @@
 #include <unordered_map>
 #include <variant>
 
+namespace pid_control
+{
+
 static constexpr bool DEBUG = false; // enable to print found configuration
 
 extern std::map<std::string, struct conf::SensorConfig> sensorConfig;
@@ -957,4 +960,6 @@
     }
     return true;
 }
+
 } // namespace dbus_configuration
+} // namespace pid_control
diff --git a/dbus/dbusconfiguration.hpp b/dbus/dbusconfiguration.hpp
index a9b12a9..f9c3bcf 100644
--- a/dbus/dbusconfiguration.hpp
+++ b/dbus/dbusconfiguration.hpp
@@ -19,7 +19,10 @@
 
 #include <sdbusplus/bus.hpp>
 
+namespace pid_control
+{
 namespace dbus_configuration
 {
 bool init(sdbusplus::bus::bus& bus, boost::asio::steady_timer& timer);
 } // namespace dbus_configuration
+} // namespace pid_control
diff --git a/dbus/dbuspassive.cpp b/dbus/dbuspassive.cpp
index 5cd8ca4..815ed49 100644
--- a/dbus/dbuspassive.cpp
+++ b/dbus/dbuspassive.cpp
@@ -27,6 +27,9 @@
 #include <string>
 #include <variant>
 
+namespace pid_control
+{
+
 std::unique_ptr<ReadInterface> DbusPassive::createDbusPassive(
     sdbusplus::bus::bus& bus, const std::string& type, const std::string& id,
     DbusHelperInterface* helper, const conf::SensorConfig* info,
@@ -220,3 +223,5 @@
 
     return handleSensorValue(sdbpMsg, obj);
 }
+
+} // namespace pid_control
diff --git a/dbus/dbuspassive.hpp b/dbus/dbuspassive.hpp
index 16cf856..74db80b 100644
--- a/dbus/dbuspassive.hpp
+++ b/dbus/dbuspassive.hpp
@@ -20,6 +20,9 @@
 #include <tuple>
 #include <vector>
 
+namespace pid_control
+{
+
 int dbusHandleSignal(sd_bus_message* msg, void* data, sd_bus_error* err);
 
 /*
@@ -80,3 +83,5 @@
 };
 
 int handleSensorValue(sdbusplus::message::message& msg, DbusPassive* owner);
+
+} // namespace pid_control
diff --git a/dbus/dbuspassiveredundancy.cpp b/dbus/dbuspassiveredundancy.cpp
index 11533f2..2ca8fde 100644
--- a/dbus/dbuspassiveredundancy.cpp
+++ b/dbus/dbuspassiveredundancy.cpp
@@ -24,6 +24,9 @@
 #include <unordered_map>
 #include <variant>
 
+namespace pid_control
+{
+
 namespace properties
 {
 
@@ -175,4 +178,6 @@
 const std::set<std::string>& DbusPassiveRedundancy::getFailed()
 {
     return failed;
-}
\ No newline at end of file
+}
+
+} // namespace pid_control
diff --git a/dbus/dbuspassiveredundancy.hpp b/dbus/dbuspassiveredundancy.hpp
index 1c5c975..790c758 100644
--- a/dbus/dbuspassiveredundancy.hpp
+++ b/dbus/dbuspassiveredundancy.hpp
@@ -21,6 +21,8 @@
 
 #include <set>
 
+namespace pid_control
+{
 /*
  * DbusPassiveRedundancy monitors the fan redundancy interface via dbus match
  * for changes. When the "Status" property changes to  Failed, all sensors in
@@ -42,3 +44,5 @@
     std::set<std::string> failed;
     sdbusplus::bus::bus& passiveBus;
 };
+
+} // namespace pid_control
diff --git a/dbus/dbuswrite.cpp b/dbus/dbuswrite.cpp
index 2cff7ea..0b02872 100644
--- a/dbus/dbuswrite.cpp
+++ b/dbus/dbuswrite.cpp
@@ -24,6 +24,9 @@
 #include <string>
 #include <variant>
 
+namespace pid_control
+{
+
 constexpr const char* pwmInterface = "xyz.openbmc_project.Control.FanPwm";
 
 using namespace phosphor::logging;
@@ -128,3 +131,5 @@
     oldValue = static_cast<int64_t>(value);
     return;
 }
+
+} // namespace pid_control
diff --git a/dbus/dbuswrite.hpp b/dbus/dbuswrite.hpp
index b8a6035..5cc2d49 100644
--- a/dbus/dbuswrite.hpp
+++ b/dbus/dbuswrite.hpp
@@ -24,6 +24,9 @@
 #include <memory>
 #include <string>
 
+namespace pid_control
+{
+
 class DbusWritePercent : public WriteInterface
 {
   public:
@@ -65,3 +68,5 @@
     std::string connectionName;
     int64_t oldValue = -1;
 };
+
+} // namespace pid_control
diff --git a/dbus/util.cpp b/dbus/util.cpp
index 93efc6d..a464458 100644
--- a/dbus/util.cpp
+++ b/dbus/util.cpp
@@ -11,6 +11,9 @@
 using Value = std::variant<int64_t, double, std::string, bool>;
 using PropertyMap = std::map<Property, Value>;
 
+namespace pid_control
+{
+
 using namespace phosphor::logging;
 
 /* TODO(venture): Basically all phosphor apps need this, maybe it should be a
@@ -194,3 +197,5 @@
     }
     value /= (max - min);
 }
+
+} // namespace pid_control
diff --git a/experiments/drive.cpp b/experiments/drive.cpp
index 22fd4b6..5fdbcf4 100644
--- a/experiments/drive.cpp
+++ b/experiments/drive.cpp
@@ -25,6 +25,9 @@
 #include <memory>
 #include <tuple>
 
+namespace pid_control
+{
+
 using tstamp = std::chrono::high_resolution_clock::time_point;
 
 #define DRIVE_TIME 1
@@ -259,3 +262,5 @@
 
     return 0;
 }
+
+} // namespace pid_control
diff --git a/experiments/drive.hpp b/experiments/drive.hpp
index 94e74f3..e1a4d2d 100644
--- a/experiments/drive.hpp
+++ b/experiments/drive.hpp
@@ -1,3 +1,8 @@
 #pragma once
 
+namespace pid_control
+{
+
 int driveMain(void);
+
+}
diff --git a/interfaces.hpp b/interfaces.hpp
index 2002a61..b4b236b 100644
--- a/interfaces.hpp
+++ b/interfaces.hpp
@@ -2,6 +2,9 @@
 
 #include <chrono>
 
+namespace pid_control
+{
+
 struct ReadReturn
 {
     double value;
@@ -66,3 +69,5 @@
     int64_t _min;
     int64_t _max;
 };
+
+} // namespace pid_control
diff --git a/main.cpp b/main.cpp
index 1dbb072..5a94efb 100644
--- a/main.cpp
+++ b/main.cpp
@@ -49,6 +49,9 @@
 #include "dbus/dbusconfiguration.hpp"
 #endif
 
+namespace pid_control
+{
+
 /* The configuration converted sensor list. */
 std::map<std::string, struct conf::SensorConfig> sensorConfig = {};
 /* The configuration converted PID list. */
@@ -56,6 +59,8 @@
 /* The configuration converted Zone configuration. */
 std::map<int64_t, struct conf::ZoneConfig> zoneDetailsConfig = {};
 
+} // namespace pid_control
+
 /** the swampd daemon will check for the existence of this file. */
 constexpr auto jsonConfigurationPath = "/usr/share/swampd/config.json";
 std::string configPath = "";
@@ -70,6 +75,9 @@
 static sdbusplus::asio::connection
     passiveBus(io, sdbusplus::bus::new_system().release());
 
+namespace pid_control
+{
+
 void restartControlLoops()
 {
     static SensorManager mgmr;
@@ -150,6 +158,8 @@
     return;
 }
 
+} // namespace pid_control
+
 int main(int argc, char* argv[])
 {
     loggingPath = "";
@@ -182,7 +192,7 @@
      * it.
      */
 
-    tryRestartControlLoops();
+    pid_control::tryRestartControlLoops();
 
     io.run();
     return 0;
diff --git a/notimpl/readonly.cpp b/notimpl/readonly.cpp
index 1ae2b30..94d1702 100644
--- a/notimpl/readonly.cpp
+++ b/notimpl/readonly.cpp
@@ -18,6 +18,9 @@
 
 #include <stdexcept>
 
+namespace pid_control
+{
+
 void ReadOnly::write(double value)
 {
     throw std::runtime_error("Not supported.");
@@ -27,3 +30,5 @@
 {
     return;
 }
+
+} // namespace pid_control
diff --git a/notimpl/readonly.hpp b/notimpl/readonly.hpp
index 6a48f0b..3a2c806 100644
--- a/notimpl/readonly.hpp
+++ b/notimpl/readonly.hpp
@@ -4,6 +4,9 @@
 
 #include "interfaces.hpp"
 
+namespace pid_control
+{
+
 class ReadOnly : public WriteInterface
 {
   public:
@@ -21,3 +24,5 @@
 
     void write(double value) override;
 };
+
+} // namespace pid_control
diff --git a/notimpl/writeonly.cpp b/notimpl/writeonly.cpp
index 9fc99fd..de354e6 100644
--- a/notimpl/writeonly.cpp
+++ b/notimpl/writeonly.cpp
@@ -18,7 +18,12 @@
 
 #include <stdexcept>
 
+namespace pid_control
+{
+
 ReadReturn WriteOnly::read(void)
 {
     throw std::runtime_error("Not supported.");
 }
+
+} // namespace pid_control
diff --git a/notimpl/writeonly.hpp b/notimpl/writeonly.hpp
index ba7c0c4..c3b5323 100644
--- a/notimpl/writeonly.hpp
+++ b/notimpl/writeonly.hpp
@@ -3,6 +3,9 @@
 
 #include "interfaces.hpp"
 
+namespace pid_control
+{
+
 class WriteOnly : public ReadInterface
 {
   public:
@@ -11,3 +14,5 @@
 
     ReadReturn read(void) override;
 };
+
+} // namespace pid_control
diff --git a/pid/builder.cpp b/pid/builder.cpp
index 0ffadf1..b76d134 100644
--- a/pid/builder.cpp
+++ b/pid/builder.cpp
@@ -28,6 +28,9 @@
 #include <memory>
 #include <unordered_map>
 
+namespace pid_control
+{
+
 static constexpr bool deferSignals = true;
 static constexpr auto objectPath = "/xyz/openbmc_project/settings/fanctrl/zone";
 
@@ -135,3 +138,5 @@
 
     return zones;
 }
+
+} // namespace pid_control
diff --git a/pid/builder.hpp b/pid/builder.hpp
index a493a67..0ee3420 100644
--- a/pid/builder.hpp
+++ b/pid/builder.hpp
@@ -8,7 +8,12 @@
 #include <memory>
 #include <unordered_map>
 
+namespace pid_control
+{
+
 std::unordered_map<int64_t, std::unique_ptr<PIDZone>>
     buildZones(const std::map<int64_t, conf::PIDConf>& zonePids,
                std::map<int64_t, struct conf::ZoneConfig>& zoneConfigs,
                SensorManager& mgr, sdbusplus::bus::bus& modeControlBus);
+
+}
diff --git a/pid/buildjson.cpp b/pid/buildjson.cpp
index 9b3937b..c178293 100644
--- a/pid/buildjson.cpp
+++ b/pid/buildjson.cpp
@@ -23,6 +23,9 @@
 #include <map>
 #include <tuple>
 
+namespace pid_control
+{
+
 using json = nlohmann::json;
 
 namespace conf
@@ -152,3 +155,5 @@
 
     return std::make_pair(pidConfig, zoneConfig);
 }
+
+} // namespace pid_control
diff --git a/pid/buildjson.hpp b/pid/buildjson.hpp
index 2ac573a..5489c5a 100644
--- a/pid/buildjson.hpp
+++ b/pid/buildjson.hpp
@@ -7,6 +7,9 @@
 #include <map>
 #include <tuple>
 
+namespace pid_control
+{
+
 using json = nlohmann::json;
 
 /**
@@ -18,3 +21,5 @@
 std::pair<std::map<int64_t, conf::PIDConf>,
           std::map<int64_t, struct conf::ZoneConfig>>
     buildPIDsFromJson(const json& data);
+
+} // namespace pid_control
diff --git a/pid/controller.hpp b/pid/controller.hpp
index 5530843..5680052 100644
--- a/pid/controller.hpp
+++ b/pid/controller.hpp
@@ -5,6 +5,9 @@
 
 #include <string>
 
+namespace pid_control
+{
+
 /*
  * Base class for controllers.  Each controller that implements this needs to
  * provide an inputProc, process, and outputProc.
@@ -23,3 +26,5 @@
 
     virtual std::string getID(void) = 0;
 };
+
+} // namespace pid_control
diff --git a/pid/ec/pid.cpp b/pid/ec/pid.cpp
index 7d8b403..98968f7 100644
--- a/pid/ec/pid.cpp
+++ b/pid/ec/pid.cpp
@@ -16,6 +16,8 @@
 
 #include "pid.hpp"
 
+namespace pid_control
+{
 namespace ec
 {
 
@@ -119,3 +121,4 @@
 }
 
 } // namespace ec
+} // namespace pid_control
diff --git a/pid/ec/pid.hpp b/pid/ec/pid.hpp
index 74ad5a7..29c7bb3 100644
--- a/pid/ec/pid.hpp
+++ b/pid/ec/pid.hpp
@@ -2,6 +2,8 @@
 
 #include <cstdint>
 
+namespace pid_control
+{
 namespace ec
 {
 
@@ -54,3 +56,4 @@
 };
 
 } // namespace ec
+} // namespace pid_control
diff --git a/pid/ec/stepwise.cpp b/pid/ec/stepwise.cpp
index 0a5c0b0..0065228 100644
--- a/pid/ec/stepwise.cpp
+++ b/pid/ec/stepwise.cpp
@@ -20,8 +20,11 @@
 #include <cstddef>
 #include <limits>
 
+namespace pid_control
+{
 namespace ec
 {
+
 double stepwise(const ec::StepwiseInfo& info, double input)
 {
     double value = info.output[0]; // if we are below the lowest
@@ -43,4 +46,6 @@
 
     return value;
 }
-} // namespace ec
\ No newline at end of file
+
+} // namespace ec
+} // namespace pid_control
diff --git a/pid/ec/stepwise.hpp b/pid/ec/stepwise.hpp
index 3ce847a..88db332 100644
--- a/pid/ec/stepwise.hpp
+++ b/pid/ec/stepwise.hpp
@@ -20,6 +20,8 @@
 #include <cstddef>
 #include <vector>
 
+namespace pid_control
+{
 namespace ec
 {
 constexpr size_t maxStepwisePoints = 20;
@@ -36,4 +38,5 @@
 
 double stepwise(const ec::StepwiseInfo& info, double value);
 
-} // namespace ec
\ No newline at end of file
+} // namespace ec
+} // namespace pid_control
diff --git a/pid/fan.hpp b/pid/fan.hpp
index 7792d04..a16942b 100644
--- a/pid/fan.hpp
+++ b/pid/fan.hpp
@@ -1,9 +1,14 @@
 
 #pragma once
 
+namespace pid_control
+{
+
 enum class FanSpeedDirection
 {
     DOWN,
     UP,
     NEUTRAL, /* not sure this will ever happen, but for completeness. */
 };
+
+}
diff --git a/pid/fancontroller.cpp b/pid/fancontroller.cpp
index dd26d16..41f24da 100644
--- a/pid/fancontroller.cpp
+++ b/pid/fancontroller.cpp
@@ -23,6 +23,9 @@
 #include <algorithm>
 #include <iostream>
 
+namespace pid_control
+{
+
 std::unique_ptr<PIDController>
     FanController::createFanPid(ZoneInterface* owner, const std::string& id,
                                 const std::vector<std::string>& inputs,
@@ -140,3 +143,5 @@
 
     return;
 }
+
+} // namespace pid_control
diff --git a/pid/fancontroller.hpp b/pid/fancontroller.hpp
index d14aef7..25eebad 100644
--- a/pid/fancontroller.hpp
+++ b/pid/fancontroller.hpp
@@ -8,6 +8,9 @@
 #include <string>
 #include <vector>
 
+namespace pid_control
+{
+
 /*
  * A FanController is a PID controller that reads a number of fans and given
  * the output then tries to set them to the goal values set by the thermal
@@ -45,3 +48,5 @@
     std::vector<std::string> _inputs;
     FanSpeedDirection _direction;
 };
+
+} // namespace pid_control
diff --git a/pid/pidcontroller.cpp b/pid/pidcontroller.cpp
index e3eaaff..e7a4ad1 100644
--- a/pid/pidcontroller.cpp
+++ b/pid/pidcontroller.cpp
@@ -27,6 +27,9 @@
 #include <thread>
 #include <vector>
 
+namespace pid_control
+{
+
 void PIDController::process(void)
 {
     double input;
@@ -78,3 +81,5 @@
 
     return;
 }
+
+} // namespace pid_control
diff --git a/pid/pidcontroller.hpp b/pid/pidcontroller.hpp
index fd41c09..cb92377 100644
--- a/pid/pidcontroller.hpp
+++ b/pid/pidcontroller.hpp
@@ -8,6 +8,9 @@
 #include <memory>
 #include <vector>
 
+namespace pid_control
+{
+
 class ZoneInterface;
 
 /*
@@ -63,3 +66,5 @@
     std::string _id;
     double lastInput = std::numeric_limits<double>::quiet_NaN();
 };
+
+} // namespace pid_control
diff --git a/pid/pidloop.cpp b/pid/pidloop.cpp
index 8dc6221..f046c9d 100644
--- a/pid/pidloop.cpp
+++ b/pid/pidloop.cpp
@@ -28,6 +28,9 @@
 #include <thread>
 #include <vector>
 
+namespace pid_control
+{
+
 static void processThermals(PIDZone* zone)
 {
     // Get the latest margins.
@@ -121,3 +124,5 @@
             pidControlLoop(zone, timer, false, ms100cnt);
         });
 }
+
+} // namespace pid_control
diff --git a/pid/pidloop.hpp b/pid/pidloop.hpp
index 3a67954..cf4b7ce 100644
--- a/pid/pidloop.hpp
+++ b/pid/pidloop.hpp
@@ -4,6 +4,9 @@
 
 #include <boost/asio/steady_timer.hpp>
 
+namespace pid_control
+{
+
 /**
  * Main pid control loop for a given zone.
  * This function calls itself indefinitely in an async loop to calculate
@@ -16,3 +19,5 @@
  */
 void pidControlLoop(PIDZone* zone, boost::asio::steady_timer& timer,
                     bool first = true, int ms100cnt = 0);
+
+} // namespace pid_control
diff --git a/pid/stepwisecontroller.cpp b/pid/stepwisecontroller.cpp
index c72d61a..e8eb344 100644
--- a/pid/stepwisecontroller.cpp
+++ b/pid/stepwisecontroller.cpp
@@ -30,6 +30,9 @@
 #include <thread>
 #include <vector>
 
+namespace pid_control
+{
+
 void StepwiseController::process(void)
 {
     // Get input value
@@ -105,3 +108,5 @@
     }
     return;
 }
+
+} // namespace pid_control
diff --git a/pid/stepwisecontroller.hpp b/pid/stepwisecontroller.hpp
index 90e2317..e192fc7 100644
--- a/pid/stepwisecontroller.hpp
+++ b/pid/stepwisecontroller.hpp
@@ -8,6 +8,9 @@
 #include <memory>
 #include <vector>
 
+namespace pid_control
+{
+
 class ZoneInterface;
 
 class StepwiseController : public Controller
@@ -52,3 +55,5 @@
     double lastInput = std::numeric_limits<double>::quiet_NaN();
     double lastOutput = std::numeric_limits<double>::quiet_NaN();
 };
+
+} // namespace pid_control
diff --git a/pid/thermalcontroller.cpp b/pid/thermalcontroller.cpp
index 5a5b9cc..35dcd15 100644
--- a/pid/thermalcontroller.cpp
+++ b/pid/thermalcontroller.cpp
@@ -22,6 +22,9 @@
 
 #include <algorithm>
 
+namespace pid_control
+{
+
 ThermalType getThermalType(const std::string& typeString)
 {
     /* Currently it only supports the two types. */
@@ -106,3 +109,5 @@
 
     return;
 }
+
+} // namespace pid_control
diff --git a/pid/thermalcontroller.hpp b/pid/thermalcontroller.hpp
index 74e85ab..6144d49 100644
--- a/pid/thermalcontroller.hpp
+++ b/pid/thermalcontroller.hpp
@@ -7,6 +7,9 @@
 #include <string>
 #include <vector>
 
+namespace pid_control
+{
+
 /*
  * A ThermalController is a PID controller that reads a number of sensors and
  * provides the setpoints for the fans.
@@ -58,3 +61,5 @@
     std::vector<std::string> _inputs;
     ThermalType type;
 };
+
+} // namespace pid_control
diff --git a/pid/util.cpp b/pid/util.cpp
index 0a8f892..ad7c139 100644
--- a/pid/util.cpp
+++ b/pid/util.cpp
@@ -21,6 +21,9 @@
 #include <cstring>
 #include <iostream>
 
+namespace pid_control
+{
+
 void initializePIDStruct(ec::pid_info_t* info, const ec::pidinfo& initial)
 {
     std::memset(info, 0x00, sizeof(ec::pid_info_t));
@@ -57,3 +60,5 @@
 
     return;
 }
+
+} // namespace pid_control
diff --git a/pid/zone.cpp b/pid/zone.cpp
index 6a63671..9484658 100644
--- a/pid/zone.cpp
+++ b/pid/zone.cpp
@@ -32,6 +32,9 @@
 #include <iostream>
 #include <memory>
 
+namespace pid_control
+{
+
 using tstamp = std::chrono::high_resolution_clock::time_point;
 using namespace std::literals::chrono_literals;
 
@@ -380,3 +383,5 @@
 {
     return getFailSafeMode();
 }
+
+} // namespace pid_control
diff --git a/pid/zone.hpp b/pid/zone.hpp
index dc2ceb8..9dc433a 100644
--- a/pid/zone.hpp
+++ b/pid/zone.hpp
@@ -23,6 +23,9 @@
 using ModeInterface = sdbusplus::xyz::openbmc_project::Control::server::Mode;
 using ModeObject = ServerObject<ModeInterface>;
 
+namespace pid_control
+{
+
 class ZoneInterface
 {
   public:
@@ -119,3 +122,5 @@
     std::vector<std::unique_ptr<Controller>> _fans;
     std::vector<std::unique_ptr<Controller>> _thermals;
 };
+
+} // namespace pid_control
diff --git a/sensors/builder.cpp b/sensors/builder.cpp
index 1cea61a..8a1f54a 100644
--- a/sensors/builder.cpp
+++ b/sensors/builder.cpp
@@ -35,13 +35,12 @@
 #include "sysfs/sysfswrite.hpp"
 #include "util.hpp"
 
+namespace pid_control
+{
+
 static constexpr bool deferSignals = true;
 static DbusHelper helper;
 
-using ::pid_control::getReadInterfaceType;
-using ::pid_control::getWriteInterfaceType;
-using ::pid_control::IOInterfaceType;
-
 SensorManager
     buildSensors(const std::map<std::string, struct conf::SensorConfig>& config,
                  sdbusplus::bus::bus& passive, sdbusplus::bus::bus& host)
@@ -186,3 +185,5 @@
 
     return mgmr;
 }
+
+} // namespace pid_control
diff --git a/sensors/builder.hpp b/sensors/builder.hpp
index 688a931..236fee7 100644
--- a/sensors/builder.hpp
+++ b/sensors/builder.hpp
@@ -6,9 +6,14 @@
 #include <map>
 #include <string>
 
+namespace pid_control
+{
+
 /**
  * Build the sensors and associate them with a SensorManager.
  */
 SensorManager
     buildSensors(const std::map<std::string, struct conf::SensorConfig>& config,
                  sdbusplus::bus::bus& passive, sdbusplus::bus::bus& host);
+
+} // namespace pid_control
diff --git a/sensors/buildjson.cpp b/sensors/buildjson.cpp
index 7e5e29a..2bfc143 100644
--- a/sensors/buildjson.cpp
+++ b/sensors/buildjson.cpp
@@ -25,6 +25,8 @@
 
 using json = nlohmann::json;
 
+namespace pid_control
+{
 namespace conf
 {
 void from_json(const json& j, conf::SensorConfig& s)
@@ -113,3 +115,4 @@
 
     return config;
 }
+} // namespace pid_control
diff --git a/sensors/buildjson.hpp b/sensors/buildjson.hpp
index 979cd87..ee82381 100644
--- a/sensors/buildjson.hpp
+++ b/sensors/buildjson.hpp
@@ -9,6 +9,9 @@
 
 using json = nlohmann::json;
 
+namespace pid_control
+{
+
 /**
  * Given a json object generated from a configuration file, build the sensor
  * configuration representation. This expecteds the json configuration to be
@@ -19,3 +22,5 @@
  */
 std::map<std::string, struct conf::SensorConfig>
     buildSensorsFromJson(const json& data);
+
+} // namespace pid_control
diff --git a/sensors/host.cpp b/sensors/host.cpp
index 96a0514..e05ac37 100644
--- a/sensors/host.cpp
+++ b/sensors/host.cpp
@@ -21,6 +21,9 @@
 #include <memory>
 #include <mutex>
 
+namespace pid_control
+{
+
 template <typename T>
 void scaleHelper(T& ptr, int64_t value)
 {
@@ -92,3 +95,5 @@
 {
     throw std::runtime_error("Not Implemented.");
 }
+
+} // namespace pid_control
diff --git a/sensors/host.hpp b/sensors/host.hpp
index 7983e8a..35c7f45 100644
--- a/sensors/host.hpp
+++ b/sensors/host.hpp
@@ -16,6 +16,9 @@
 using ValueInterface = sdbusplus::xyz::openbmc_project::Sensor::server::Value;
 using ValueObject = ServerObject<ValueInterface>;
 
+namespace pid_control
+{
+
 class ValueHelper : public ValueInterface
 {
 
@@ -62,3 +65,5 @@
     std::chrono::high_resolution_clock::time_point _updated;
     double _value = 0;
 };
+
+} // namespace pid_control
diff --git a/sensors/manager.cpp b/sensors/manager.cpp
index 84f7435..95d2a6b 100644
--- a/sensors/manager.cpp
+++ b/sensors/manager.cpp
@@ -19,6 +19,12 @@
 
 #include "conf.hpp"
 
+#include <memory>
+#include <string>
+
+namespace pid_control
+{
+
 void SensorManager::addSensor(const std::string& type, const std::string& name,
                               std::unique_ptr<Sensor> sensor)
 {
@@ -32,3 +38,5 @@
 
     _sensorTypeList[type].push_back(name);
 }
+
+} // namespace pid_control
diff --git a/sensors/manager.hpp b/sensors/manager.hpp
index 740ef00..6fcd275 100644
--- a/sensors/manager.hpp
+++ b/sensors/manager.hpp
@@ -10,6 +10,9 @@
 #include <string>
 #include <vector>
 
+namespace pid_control
+{
+
 /*
  * The SensorManager holds all sensors across all zones.
  */
@@ -61,3 +64,5 @@
 
     static constexpr auto SensorRoot = "/xyz/openbmc_project/extsensors";
 };
+
+} // namespace pid_control
diff --git a/sensors/pluggable.cpp b/sensors/pluggable.cpp
index eb3eab9..07d3d0e 100644
--- a/sensors/pluggable.cpp
+++ b/sensors/pluggable.cpp
@@ -16,12 +16,8 @@
 
 #include "pluggable.hpp"
 
-#include "dbus/dbuspassive.hpp"
-#include "sysfs/sysfswrite.hpp"
-
-#include <iostream>
-#include <memory>
-#include <string>
+namespace pid_control
+{
 
 ReadReturn PluggableSensor::read(void)
 {
@@ -36,4 +32,6 @@
 bool PluggableSensor::getFailed(void)
 {
     return _reader->getFailed();
-}
\ No newline at end of file
+}
+
+} // namespace pid_control
diff --git a/sensors/pluggable.hpp b/sensors/pluggable.hpp
index 756b5cb..23aea99 100644
--- a/sensors/pluggable.hpp
+++ b/sensors/pluggable.hpp
@@ -3,11 +3,12 @@
 #include "interfaces.hpp"
 #include "sensor.hpp"
 
-#include <sdbusplus/bus.hpp>
-
 #include <memory>
 #include <string>
 
+namespace pid_control
+{
+
 /*
  * A Sensor that can use any reader or writer you provide.
  */
@@ -29,3 +30,5 @@
     std::unique_ptr<ReadInterface> _reader;
     std::unique_ptr<WriteInterface> _writer;
 };
+
+} // namespace pid_control
diff --git a/sensors/sensor.hpp b/sensors/sensor.hpp
index 01f4c02..8258b7b 100644
--- a/sensors/sensor.hpp
+++ b/sensors/sensor.hpp
@@ -4,6 +4,9 @@
 
 #include <string>
 
+namespace pid_control
+{
+
 /**
  * Abstract base class for all sensors.
  */
@@ -55,3 +58,5 @@
     std::string _name;
     int64_t _timeout;
 };
+
+} // namespace pid_control
diff --git a/sysfs/sysfsread.cpp b/sysfs/sysfsread.cpp
index a070af2..eee1c8a 100644
--- a/sysfs/sysfsread.cpp
+++ b/sysfs/sysfsread.cpp
@@ -20,6 +20,9 @@
 #include <fstream>
 #include <iostream>
 
+namespace pid_control
+{
+
 ReadReturn SysFsRead::read(void)
 {
     int64_t value;
@@ -34,3 +37,5 @@
 
     return r;
 }
+
+} // namespace pid_control
diff --git a/sysfs/sysfsread.hpp b/sysfs/sysfsread.hpp
index 4c1baec..32ce18e 100644
--- a/sysfs/sysfsread.hpp
+++ b/sysfs/sysfsread.hpp
@@ -5,6 +5,9 @@
 
 #include <string>
 
+namespace pid_control
+{
+
 /*
  * A ReadInterface that is expecting a path that's sysfs, but really could be
  * any filesystem path.
@@ -21,3 +24,5 @@
   private:
     const std::string _path;
 };
+
+} // namespace pid_control
diff --git a/sysfs/sysfswrite.cpp b/sysfs/sysfswrite.cpp
index 93a64dc..db903cb 100644
--- a/sysfs/sysfswrite.cpp
+++ b/sysfs/sysfswrite.cpp
@@ -19,6 +19,9 @@
 #include <fstream>
 #include <iostream>
 
+namespace pid_control
+{
+
 void SysFsWritePercent::write(double value)
 {
     double minimum = getMin();
@@ -45,3 +48,5 @@
 
     return;
 }
+
+} // namespace pid_control
diff --git a/sysfs/sysfswrite.hpp b/sysfs/sysfswrite.hpp
index 276d936..615cb37 100644
--- a/sysfs/sysfswrite.hpp
+++ b/sysfs/sysfswrite.hpp
@@ -5,6 +5,9 @@
 
 #include <string>
 
+namespace pid_control
+{
+
 /*
  * A WriteInterface that is expecting a path that's sysfs, but really could be
  * any filesystem path.
@@ -34,3 +37,5 @@
   private:
     std::string _writePath;
 };
+
+} // namespace pid_control
diff --git a/sysfs/util.cpp b/sysfs/util.cpp
index da678ce..b7cc6f3 100644
--- a/sysfs/util.cpp
+++ b/sysfs/util.cpp
@@ -20,6 +20,9 @@
 #include <iostream>
 #include <string>
 
+namespace pid_control
+{
+
 /*
  * There are two basic paths I want to support:
  * 1. /sys/class/hwmon/hwmon0/pwm1
@@ -68,3 +71,5 @@
         return original;
     }
 }
+
+} // namespace pid_control
diff --git a/test/controller_mock.hpp b/test/controller_mock.hpp
index 52c21a9..f1c9d56 100644
--- a/test/controller_mock.hpp
+++ b/test/controller_mock.hpp
@@ -4,6 +4,9 @@
 
 #include <gmock/gmock.h>
 
+namespace pid_control
+{
+
 class ControllerMock : public PIDController
 {
   public:
@@ -17,3 +20,5 @@
     MOCK_METHOD0(setptProc, double());
     MOCK_METHOD1(outputProc, void(double));
 };
+
+} // namespace pid_control
diff --git a/test/dbus_active_unittest.cpp b/test/dbus_active_unittest.cpp
index 142cc1a..054ad1d 100644
--- a/test/dbus_active_unittest.cpp
+++ b/test/dbus_active_unittest.cpp
@@ -8,6 +8,11 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
+namespace pid_control
+{
+namespace
+{
+
 using ::testing::_;
 using ::testing::Invoke;
 using ::testing::NotNull;
@@ -52,3 +57,6 @@
 
 // WARN: getProperties will raise an exception on failure
 // Instead of just not updating the value.
+
+} // namespace
+} // namespace pid_control
diff --git a/test/dbus_passive_unittest.cpp b/test/dbus_passive_unittest.cpp
index d4e9e98..5bddf51 100644
--- a/test/dbus_passive_unittest.cpp
+++ b/test/dbus_passive_unittest.cpp
@@ -11,6 +11,11 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
+namespace pid_control
+{
+namespace
+{
+
 using ::testing::_;
 using ::testing::InSequence;
 using ::testing::Invoke;
@@ -529,3 +534,6 @@
     EXPECT_DOUBLE_EQ(0, passive->getMin());
     EXPECT_DOUBLE_EQ(0, passive->getMax());
 }
+
+} // namespace
+} // namespace pid_control
diff --git a/test/dbushelper_mock.hpp b/test/dbushelper_mock.hpp
index 120c44d..6ce63c8 100644
--- a/test/dbushelper_mock.hpp
+++ b/test/dbushelper_mock.hpp
@@ -8,6 +8,9 @@
 
 #include <gmock/gmock.h>
 
+namespace pid_control
+{
+
 class DbusHelperMock : public DbusHelperInterface
 {
   public:
@@ -24,3 +27,5 @@
                  bool(sdbusplus::bus::bus& bus, const std::string& service,
                       const std::string& path));
 };
+
+} // namespace pid_control
diff --git a/test/helpers.hpp b/test/helpers.hpp
index 1ac21ca..10e8cd7 100644
--- a/test/helpers.hpp
+++ b/test/helpers.hpp
@@ -9,6 +9,9 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
+namespace pid_control
+{
+
 using ::testing::_;
 using ::testing::Invoke;
 using ::testing::IsNull;
@@ -67,3 +70,5 @@
 
     return;
 }
+
+} // namespace pid_control
diff --git a/test/json_parse_unittest.cpp b/test/json_parse_unittest.cpp
index 4913461..3345163 100644
--- a/test/json_parse_unittest.cpp
+++ b/test/json_parse_unittest.cpp
@@ -4,6 +4,11 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
+namespace pid_control
+{
+namespace
+{
+
 TEST(ConfigurationVerificationTest, VerifyHappy)
 {
     /* Verify a happy configuration throws no exceptions. */
@@ -152,3 +157,6 @@
 
     EXPECT_THROW(validateJson(j2), ConfigurationException);
 }
+
+} // namespace
+} // namespace pid_control
diff --git a/test/pid_fancontroller_unittest.cpp b/test/pid_fancontroller_unittest.cpp
index abf9aaa..866b743 100644
--- a/test/pid_fancontroller_unittest.cpp
+++ b/test/pid_fancontroller_unittest.cpp
@@ -9,6 +9,11 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
+namespace pid_control
+{
+namespace
+{
+
 using ::testing::_;
 using ::testing::DoubleEq;
 using ::testing::Invoke;
@@ -245,3 +250,6 @@
     // to the sensors.
     p->outputProc(percent);
 }
+
+} // namespace
+} // namespace pid_control
diff --git a/test/pid_json_unittest.cpp b/test/pid_json_unittest.cpp
index 2bd7d35..0e767f9 100644
--- a/test/pid_json_unittest.cpp
+++ b/test/pid_json_unittest.cpp
@@ -3,6 +3,11 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
+namespace pid_control
+{
+namespace
+{
+
 TEST(ZoneFromJson, emptyZone)
 {
     // There is a zone key, but it's empty.
@@ -199,4 +204,7 @@
                      1.0);
 
     EXPECT_DOUBLE_EQ(zoneConfig[1].minThermalOutput, 3000.0);
-}
\ No newline at end of file
+}
+
+} // namespace
+} // namespace pid_control
diff --git a/test/pid_stepwisecontroller_unittest.cpp b/test/pid_stepwisecontroller_unittest.cpp
index f5f6f9a..d9a7728 100644
--- a/test/pid_stepwisecontroller_unittest.cpp
+++ b/test/pid_stepwisecontroller_unittest.cpp
@@ -9,6 +9,11 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
+namespace pid_control
+{
+namespace
+{
+
 using ::testing::Return;
 using ::testing::StrEq;
 
@@ -83,3 +88,6 @@
         p->process();
     }
 }
+
+} // namespace
+} // namespace pid_control
diff --git a/test/pid_thermalcontroller_unittest.cpp b/test/pid_thermalcontroller_unittest.cpp
index d95f16e..ef4de66 100644
--- a/test/pid_thermalcontroller_unittest.cpp
+++ b/test/pid_thermalcontroller_unittest.cpp
@@ -8,6 +8,11 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
+namespace pid_control
+{
+namespace
+{
+
 using ::testing::_;
 using ::testing::Return;
 using ::testing::StrEq;
@@ -211,4 +216,7 @@
         p->process();
         EXPECT_EQ(p->getLastInput(), reading);
     }
-}
\ No newline at end of file
+}
+
+} // namespace
+} // namespace pid_control
diff --git a/test/pid_zone_unittest.cpp b/test/pid_zone_unittest.cpp
index 8593b97..d7ae9ec 100644
--- a/test/pid_zone_unittest.cpp
+++ b/test/pid_zone_unittest.cpp
@@ -14,6 +14,11 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
+namespace pid_control
+{
+namespace
+{
+
 using ::testing::_;
 using ::testing::IsNull;
 using ::testing::Return;
@@ -538,3 +543,6 @@
     // write to it will have no effect.
     EXPECT_EQ(zone->failSafe(), zone->getFailSafeMode());
 }
+
+} // namespace
+} // namespace pid_control
diff --git a/test/readinterface_mock.hpp b/test/readinterface_mock.hpp
index 1d2c82d..0b77c8a 100644
--- a/test/readinterface_mock.hpp
+++ b/test/readinterface_mock.hpp
@@ -4,6 +4,9 @@
 
 #include <gmock/gmock.h>
 
+namespace pid_control
+{
+
 class ReadInterfaceMock : public ReadInterface
 {
   public:
@@ -11,3 +14,5 @@
 
     MOCK_METHOD0(read, ReadReturn());
 };
+
+} // namespace pid_control
diff --git a/test/sensor_host_unittest.cpp b/test/sensor_host_unittest.cpp
index 8bb9cc7..8559081 100644
--- a/test/sensor_host_unittest.cpp
+++ b/test/sensor_host_unittest.cpp
@@ -11,6 +11,11 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
+namespace pid_control
+{
+namespace
+{
+
 using ::testing::IsNull;
 using ::testing::Return;
 using ::testing::StrEq;
@@ -105,3 +110,6 @@
     // Verify it was updated within the last second.
     EXPECT_TRUE(duration < 1);
 }
+
+} // namespace
+} // namespace pid_control
diff --git a/test/sensor_manager_unittest.cpp b/test/sensor_manager_unittest.cpp
index 9f0e26c..85865a8 100644
--- a/test/sensor_manager_unittest.cpp
+++ b/test/sensor_manager_unittest.cpp
@@ -6,6 +6,11 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
+namespace pid_control
+{
+namespace
+{
+
 using ::testing::_;
 using ::testing::IsNull;
 using ::testing::Return;
@@ -55,3 +60,6 @@
     s.addSensor(type, name, std::move(sensor));
     EXPECT_EQ(s.getSensor(name), sensor_ptr);
 }
+
+} // namespace
+} // namespace pid_control
diff --git a/test/sensor_mock.hpp b/test/sensor_mock.hpp
index b067c7c..d67c457 100644
--- a/test/sensor_mock.hpp
+++ b/test/sensor_mock.hpp
@@ -5,6 +5,9 @@
 
 #include <gmock/gmock.h>
 
+namespace pid_control
+{
+
 class SensorMock : public Sensor
 {
   public:
@@ -16,3 +19,5 @@
     MOCK_METHOD0(read, ReadReturn());
     MOCK_METHOD1(write, void(double));
 };
+
+} // namespace pid_control
diff --git a/test/sensor_pluggable_unittest.cpp b/test/sensor_pluggable_unittest.cpp
index a15f06c..ffd08cd 100644
--- a/test/sensor_pluggable_unittest.cpp
+++ b/test/sensor_pluggable_unittest.cpp
@@ -7,6 +7,11 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
+namespace pid_control
+{
+namespace
+{
+
 using ::testing::Invoke;
 
 TEST(PluggableSensorTest, BoringConstructorTest)
@@ -80,3 +85,6 @@
     EXPECT_CALL(*wip, write(value));
     p.write(value);
 }
+
+} // namespace
+} // namespace pid_control
diff --git a/test/sensors_json_unittest.cpp b/test/sensors_json_unittest.cpp
index 4777ae3..7b3dbc3 100644
--- a/test/sensors_json_unittest.cpp
+++ b/test/sensors_json_unittest.cpp
@@ -4,6 +4,11 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
+namespace pid_control
+{
+namespace
+{
+
 TEST(SensorsFromJson, emptyJsonNoSensors)
 {
     // If the json has no sensors, the map is empty.
@@ -127,3 +132,6 @@
     auto output = buildSensorsFromJson(j2);
     EXPECT_EQ(2, output.size());
 }
+
+} // namespace
+} // namespace pid_control
diff --git a/test/writeinterface_mock.hpp b/test/writeinterface_mock.hpp
index d25e332..0aed48d 100644
--- a/test/writeinterface_mock.hpp
+++ b/test/writeinterface_mock.hpp
@@ -4,6 +4,9 @@
 
 #include <gmock/gmock.h>
 
+namespace pid_control
+{
+
 class WriteInterfaceMock : public WriteInterface
 {
   public:
@@ -14,3 +17,5 @@
 
     MOCK_METHOD1(write, void(double));
 };
+
+} // namespace pid_control
diff --git a/test/zone_mock.hpp b/test/zone_mock.hpp
index cd97f1f..541f95c 100644
--- a/test/zone_mock.hpp
+++ b/test/zone_mock.hpp
@@ -6,6 +6,9 @@
 
 #include <gmock/gmock.h>
 
+namespace pid_control
+{
+
 class ZoneMock : public ZoneInterface
 {
   public:
@@ -19,3 +22,5 @@
     MOCK_CONST_METHOD0(getFailSafePercent, double());
     MOCK_METHOD1(getSensor, Sensor*(const std::string&));
 };
+
+} // namespace pid_control
diff --git a/util.hpp b/util.hpp
index 7930dba..f2ffd3f 100644
--- a/util.hpp
+++ b/util.hpp
@@ -8,6 +8,9 @@
 #include <limits>
 #include <string>
 
+namespace pid_control
+{
+
 void tryRestartControlLoops(void);
 
 /*
@@ -152,3 +155,5 @@
  * Given a path that optionally has a glob portion, fill it out.
  */
 std::string FixupPath(std::string original);
+
+} // namespace pid_control