cleanup: apply constness to read-only iterators

Apply const to read-only iterators to indicate intent more clearly.

Change-Id: Ic14304c69361da203d3d3a900180bd54346acc87
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/dbus/dbusconfiguration.cpp b/dbus/dbusconfiguration.cpp
index be372af..93f9c1f 100644
--- a/dbus/dbusconfiguration.cpp
+++ b/dbus/dbusconfiguration.cpp
@@ -75,7 +75,7 @@
     // print sensor config
     std::cout << "sensor config:\n";
     std::cout << "{\n";
-    for (auto& pair : SensorConfig)
+    for (const auto& pair : SensorConfig)
     {
 
         std::cout << "\t{" << pair.first << ",\n\t\t{";
@@ -89,7 +89,7 @@
     std::cout << "}\n\n";
     std::cout << "ZoneDetailsConfig\n";
     std::cout << "{\n";
-    for (auto& zone : ZoneDetailsConfig)
+    for (const auto& zone : ZoneDetailsConfig)
     {
         std::cout << "\t{" << zone.first << ",\n";
         std::cout << "\t\t{" << zone.second.minthermalrpm << ", ";
@@ -98,15 +98,15 @@
     std::cout << "}\n\n";
     std::cout << "ZoneConfig\n";
     std::cout << "{\n";
-    for (auto& zone : ZoneConfig)
+    for (const auto& zone : ZoneConfig)
     {
         std::cout << "\t{" << zone.first << "\n";
-        for (auto& pidconf : zone.second)
+        for (const auto& pidconf : zone.second)
         {
             std::cout << "\t\t{" << pidconf.first << ",\n";
             std::cout << "\t\t\t{" << pidconf.second.type << ",\n";
             std::cout << "\t\t\t{";
-            for (auto& input : pidconf.second.inputs)
+            for (const auto& input : pidconf.second.inputs)
             {
                 std::cout << "\n\t\t\t" << input << ",\n";
             }
diff --git a/experiments/drive.cpp b/experiments/drive.cpp
index d73148a..3eed0a0 100644
--- a/experiments/drive.cpp
+++ b/experiments/drive.cpp
@@ -243,7 +243,7 @@
     tstamp tp = t1;
 
     /* Output the values and the timepoints as a time series for review. */
-    for (auto& t : series)
+    for (const auto& t : series)
     {
         tstamp ts = std::get<0>(t);
         int64_t n0 = std::get<1>(t);
diff --git a/main.cpp b/main.cpp
index d8b1135..ff0952d 100644
--- a/main.cpp
+++ b/main.cpp
@@ -158,7 +158,7 @@
      * however, a system isn't likely going to have more than a couple zones.
      * If it only has a couple zones, then this is fine.
      */
-    for (auto& i : zones)
+    for (const auto& i : zones)
     {
         std::cerr << "pushing zone" << std::endl;
         zoneThreads.push_back(std::thread(PIDControlThread, i.second.get()));
diff --git a/pid/builder.cpp b/pid/builder.cpp
index e98ba22..1e7a737 100644
--- a/pid/builder.cpp
+++ b/pid/builder.cpp
@@ -42,7 +42,7 @@
 {
     std::unordered_map<int64_t, std::unique_ptr<PIDZone>> zones;
 
-    for (auto& zi : zonePids)
+    for (const auto& zi : zonePids)
     {
         auto zoneId = static_cast<int64_t>(zi.first);
         /* The above shouldn't be necessary but is, and I am having trouble
@@ -60,7 +60,7 @@
             throw std::runtime_error(err);
         }
 
-        PIDConf& PIDConfig = zi.second;
+        const PIDConf& PIDConfig = zi.second;
 
         auto zone = std::make_unique<PIDZone>(
             zoneId, zoneConf->second.minthermalrpm,
@@ -70,11 +70,11 @@
         std::cerr << "Zone Id: " << zone->getZoneId() << "\n";
 
         // For each PID create a Controller and a Sensor.
-        for (auto& pit : PIDConfig)
+        for (const auto& pit : PIDConfig)
         {
             std::vector<std::string> inputs;
             std::string name = pit.first;
-            struct controller_info* info = &pit.second;
+            const struct controller_info* info = &pit.second;
 
             std::cerr << "PID name: " << name << "\n";
 
@@ -84,7 +84,7 @@
              */
             if (info->type == "fan")
             {
-                for (auto i : info->inputs)
+                for (const auto& i : info->inputs)
                 {
                     inputs.push_back(i);
                     zone->addFanInput(i);
@@ -96,7 +96,7 @@
             }
             else if (info->type == "temp" || info->type == "margin")
             {
-                for (auto i : info->inputs)
+                for (const auto& i : info->inputs)
                 {
                     inputs.push_back(i);
                     zone->addThermalInput(i);
@@ -109,7 +109,7 @@
             }
             else if (info->type == "stepwise")
             {
-                for (auto& i : info->inputs)
+                for (const auto& i : info->inputs)
                 {
                     inputs.push_back(i);
                     zone->addThermalInput(i);
@@ -120,7 +120,7 @@
             }
 
             std::cerr << "inputs: ";
-            for (auto& i : inputs)
+            for (const auto& i : inputs)
             {
                 std::cerr << i << ", ";
             }
diff --git a/pid/fancontroller.cpp b/pid/fancontroller.cpp
index b1c923f..f085927 100644
--- a/pid/fancontroller.cpp
+++ b/pid/fancontroller.cpp
@@ -24,7 +24,7 @@
 
 std::unique_ptr<PIDController>
     FanController::CreateFanPid(ZoneInterface* owner, const std::string& id,
-                                std::vector<std::string>& inputs,
+                                const std::vector<std::string>& inputs,
                                 ec::pidinfo initial)
 {
     if (inputs.size() == 0)
@@ -130,7 +130,7 @@
     percent /= 100;
 
     // PidSensorMap for writing.
-    for (auto& it : _inputs)
+    for (const auto& it : _inputs)
     {
         auto sensor = _owner->getSensor(it);
         sensor->write(static_cast<double>(percent));
diff --git a/pid/fancontroller.hpp b/pid/fancontroller.hpp
index 521d638..c081ce1 100644
--- a/pid/fancontroller.hpp
+++ b/pid/fancontroller.hpp
@@ -18,9 +18,10 @@
   public:
     static std::unique_ptr<PIDController>
         CreateFanPid(ZoneInterface* owner, const std::string& id,
-                     std::vector<std::string>& inputs, ec::pidinfo initial);
+                     const std::vector<std::string>& inputs,
+                     ec::pidinfo initial);
 
-    FanController(const std::string& id, std::vector<std::string>& inputs,
+    FanController(const std::string& id, const std::vector<std::string>& inputs,
                   ZoneInterface* owner) :
         PIDController(id, owner),
         _inputs(inputs), _direction(FanSpeedDirection::NEUTRAL)
diff --git a/pid/thermalcontroller.cpp b/pid/thermalcontroller.cpp
index 1422bef..d7ea5ae 100644
--- a/pid/thermalcontroller.cpp
+++ b/pid/thermalcontroller.cpp
@@ -21,7 +21,7 @@
 
 std::unique_ptr<PIDController> ThermalController::CreateThermalPid(
     ZoneInterface* owner, const std::string& id,
-    std::vector<std::string>& inputs, float setpoint, ec::pidinfo initial)
+    const std::vector<std::string>& inputs, float setpoint, ec::pidinfo initial)
 {
     // ThermalController currently only supports precisely one input.
     if (inputs.size() != 1)
diff --git a/pid/thermalcontroller.hpp b/pid/thermalcontroller.hpp
index 85c3a2b..e38938f 100644
--- a/pid/thermalcontroller.hpp
+++ b/pid/thermalcontroller.hpp
@@ -16,10 +16,11 @@
   public:
     static std::unique_ptr<PIDController>
         CreateThermalPid(ZoneInterface* owner, const std::string& id,
-                         std::vector<std::string>& inputs, float setpoint,
+                         const std::vector<std::string>& inputs, float setpoint,
                          ec::pidinfo initial);
 
-    ThermalController(const std::string& id, std::vector<std::string>& inputs,
+    ThermalController(const std::string& id,
+                      const std::vector<std::string>& inputs,
                       ZoneInterface* owner) :
         PIDController(id, owner),
         _inputs(inputs)
diff --git a/pid/zone.cpp b/pid/zone.cpp
index 35abb13..ab5cc8c 100644
--- a/pid/zone.cpp
+++ b/pid/zone.cpp
@@ -163,11 +163,11 @@
 
     _log << "epoch_ms,setpt";
 
-    for (auto& f : _fanInputs)
+    for (const auto& f : _fanInputs)
     {
         _log << "," << f;
     }
-    for (auto& t : _thermalInputs)
+    for (const auto& t : _thermalInputs)
     {
         _log << "," << t;
     }
@@ -210,7 +210,7 @@
     _log << "," << _maximumRPMSetPt;
 #endif
 
-    for (auto& f : _fanInputs)
+    for (const auto& f : _fanInputs)
     {
         auto sensor = _mgr.getSensor(f);
         ReadReturn r = sensor->read();
@@ -227,7 +227,7 @@
     }
 
 #ifdef __TUNING_LOGGING__
-    for (auto& t : _thermalInputs)
+    for (const auto& t : _thermalInputs)
     {
         _log << "," << _cachedValuesByName[t];
     }
@@ -242,7 +242,7 @@
     /* margin and temp are stored as temp */
     tstamp now = high_resolution_clock::now();
 
-    for (auto& t : _thermalInputs)
+    for (const auto& t : _thermalInputs)
     {
         auto sensor = _mgr.getSensor(t);
         ReadReturn r = sensor->read();
@@ -285,12 +285,12 @@
 
 void PIDZone::initializeCache(void)
 {
-    for (auto& f : _fanInputs)
+    for (const auto& f : _fanInputs)
     {
         _cachedValuesByName[f] = 0;
     }
 
-    for (auto& t : _thermalInputs)
+    for (const auto& t : _thermalInputs)
     {
         _cachedValuesByName[t] = 0;
 
@@ -302,7 +302,7 @@
 void PIDZone::dumpCache(void)
 {
     std::cerr << "Cache values now: \n";
-    for (auto& k : _cachedValuesByName)
+    for (const auto& k : _cachedValuesByName)
     {
         std::cerr << k.first << ": " << k.second << "\n";
     }
diff --git a/sensors/builder.cpp b/sensors/builder.cpp
index 881a9c2..7927dd0 100644
--- a/sensors/builder.cpp
+++ b/sensors/builder.cpp
@@ -42,7 +42,7 @@
     auto& HostSensorBus = mgmr.getHostBus();
     auto& PassiveListeningBus = mgmr.getPassiveBus();
 
-    for (auto& it : config)
+    for (const auto& it : config)
     {
         std::unique_ptr<ReadInterface> ri;
         std::unique_ptr<WriteInterface> wi;