cpusensor: Change cpusensor to intelcpusensor

cpusensor class is specifically used for Intel CPU. The name of this
class and the build option should be changed to reflect with their
role.
The patch set https://gerrit.openbmc.org/c/openbmc/openbmc/+/56096 is
required to prevent the build error in openbmc source.

Tested:
1. No build error.

Signed-off-by: Thu Nguyen <thu@os.amperecomputing.com>
Change-Id: I1f941fffa10222cdac908fd763dccc866ba0e8a6
diff --git a/src/CPUSensor.cpp b/src/IntelCPUSensor.cpp
similarity index 85%
rename from src/CPUSensor.cpp
rename to src/IntelCPUSensor.cpp
index f40c96f..79a51ed 100644
--- a/src/CPUSensor.cpp
+++ b/src/IntelCPUSensor.cpp
@@ -16,7 +16,7 @@
 
 #include <unistd.h>
 
-#include <CPUSensor.hpp>
+#include <IntelCPUSensor.hpp>
 #include <Utils.hpp>
 #include <boost/algorithm/string/predicate.hpp>
 #include <boost/algorithm/string/replace.hpp>
@@ -34,19 +34,20 @@
 #include <string>
 #include <vector>
 
-CPUSensor::CPUSensor(const std::string& path, const std::string& objectType,
-                     sdbusplus::asio::object_server& objectServer,
-                     std::shared_ptr<sdbusplus::asio::connection>& conn,
-                     boost::asio::io_service& io, const std::string& sensorName,
-                     std::vector<thresholds::Threshold>&& thresholdsIn,
-                     const std::string& sensorConfiguration, int cpuId,
-                     bool show, double dtsOffset) :
+IntelCPUSensor::IntelCPUSensor(
+    const std::string& path, const std::string& objectType,
+    sdbusplus::asio::object_server& objectServer,
+    std::shared_ptr<sdbusplus::asio::connection>& conn,
+    boost::asio::io_service& io, const std::string& sensorName,
+    std::vector<thresholds::Threshold>&& thresholdsIn,
+    const std::string& sensorConfiguration, int cpuId, bool show,
+    double dtsOffset) :
     Sensor(escapeName(sensorName), std::move(thresholdsIn), sensorConfiguration,
            objectType, false, false, 0, 0, conn, PowerState::on),
     objServer(objectServer), inputDev(io), waitTimer(io),
     nameTcontrol("Tcontrol CPU" + std::to_string(cpuId)), path(path),
     privTcontrol(std::numeric_limits<double>::quiet_NaN()),
-    dtsOffset(dtsOffset), show(show), pollTime(CPUSensor::sensorPollMs)
+    dtsOffset(dtsOffset), show(show), pollTime(IntelCPUSensor::sensorPollMs)
 
 {
     if (show)
@@ -92,7 +93,7 @@
     setupPowerMatch(conn);
 }
 
-CPUSensor::~CPUSensor()
+IntelCPUSensor::~IntelCPUSensor()
 {
     // close the input dev to cancel async operations
     inputDev.close();
@@ -110,9 +111,9 @@
     }
 }
 
-void CPUSensor::restartRead(void)
+void IntelCPUSensor::restartRead(void)
 {
-    std::weak_ptr<CPUSensor> weakRef = weak_from_this();
+    std::weak_ptr<IntelCPUSensor> weakRef = weak_from_this();
     waitTimer.expires_from_now(boost::posix_time::milliseconds(pollTime));
     waitTimer.async_wait([weakRef](const boost::system::error_code& ec) {
         if (ec == boost::asio::error::operation_aborted)
@@ -120,7 +121,7 @@
             std::cerr << "Failed to reschedule\n";
             return;
         }
-        std::shared_ptr<CPUSensor> self = weakRef.lock();
+        std::shared_ptr<IntelCPUSensor> self = weakRef.lock();
 
         if (self)
         {
@@ -129,7 +130,7 @@
     });
 }
 
-void CPUSensor::setupRead(void)
+void IntelCPUSensor::setupRead(void)
 {
     if (readingStateGood())
     {
@@ -153,10 +154,10 @@
         return;
     }
 
-    std::weak_ptr<CPUSensor> weakRef = weak_from_this();
+    std::weak_ptr<IntelCPUSensor> weakRef = weak_from_this();
     inputDev.async_wait(boost::asio::posix::descriptor_base::wait_read,
                         [weakRef](const boost::system::error_code& ec) {
-        std::shared_ptr<CPUSensor> self = weakRef.lock();
+        std::shared_ptr<IntelCPUSensor> self = weakRef.lock();
 
         if (self)
         {
@@ -165,7 +166,7 @@
     });
 }
 
-void CPUSensor::updateMinMaxValues(void)
+void IntelCPUSensor::updateMinMaxValues(void)
 {
     const boost::container::flat_map<
         std::string,
@@ -192,7 +193,7 @@
                 const auto& [suffix, oldValue, dbusName] = vectorItem;
                 auto attrPath = boost::replace_all_copy(path, fileItem, suffix);
                 if (auto newVal =
-                        readFile(attrPath, CPUSensor::sensorScaleFactor))
+                        readFile(attrPath, IntelCPUSensor::sensorScaleFactor))
                 {
                     updateProperty(sensorInterface, oldValue, *newVal,
                                    dbusName);
@@ -215,7 +216,7 @@
     }
 }
 
-void CPUSensor::handleResponse(const boost::system::error_code& err)
+void IntelCPUSensor::handleResponse(const boost::system::error_code& err)
 {
     if ((err == boost::system::errc::bad_file_descriptor) ||
         (err == boost::asio::error::misc_errors::not_found))
@@ -231,7 +232,7 @@
                 std::cerr << name << " interface down!\n";
                 loggedInterfaceDown = true;
             }
-            pollTime = static_cast<size_t>(CPUSensor::sensorPollMs) * 10U;
+            pollTime = static_cast<size_t>(IntelCPUSensor::sensorPollMs) * 10U;
             markFunctional(false);
         }
         return;
@@ -261,7 +262,7 @@
         try
         {
             rawValue = std::stod(response);
-            double nvalue = rawValue / CPUSensor::sensorScaleFactor;
+            double nvalue = rawValue / IntelCPUSensor::sensorScaleFactor;
 
             if (show)
             {
@@ -286,9 +287,9 @@
                 if (!thresholds.empty())
                 {
                     std::vector<thresholds::Threshold> newThresholds;
-                    if (parseThresholdsFromAttr(newThresholds, path,
-                                                CPUSensor::sensorScaleFactor,
-                                                dtsOffset))
+                    if (parseThresholdsFromAttr(
+                            newThresholds, path,
+                            IntelCPUSensor::sensorScaleFactor, dtsOffset))
                     {
                         if (!std::equal(thresholds.begin(), thresholds.end(),
                                         newThresholds.begin(),
@@ -322,7 +323,7 @@
     restartRead();
 }
 
-void CPUSensor::checkThresholds(void)
+void IntelCPUSensor::checkThresholds(void)
 {
     if (show)
     {
diff --git a/src/CPUSensorMain.cpp b/src/IntelCPUSensorMain.cpp
similarity index 98%
rename from src/CPUSensorMain.cpp
rename to src/IntelCPUSensorMain.cpp
index e9e6433..7ca6bc1 100644
--- a/src/CPUSensorMain.cpp
+++ b/src/IntelCPUSensorMain.cpp
@@ -16,7 +16,7 @@
 
 #include <fcntl.h>
 
-#include <CPUSensor.hpp>
+#include <IntelCPUSensor.hpp>
 #include <Utils.hpp>
 #include <VariantVisitors.hpp>
 #include <boost/algorithm/string/predicate.hpp>
@@ -53,7 +53,8 @@
 
 static constexpr bool debug = false;
 
-boost::container::flat_map<std::string, std::shared_ptr<CPUSensor>> gCpuSensors;
+boost::container::flat_map<std::string, std::shared_ptr<IntelCPUSensor>>
+    gCpuSensors;
 boost::container::flat_map<std::string,
                            std::shared_ptr<sdbusplus::asio::dbus_interface>>
     inventoryIfaces;
@@ -93,7 +94,7 @@
     "xyz.openbmc_project.Configuration.";
 static constexpr auto sensorTypes{std::to_array<const char*>({"XeonCPU"})};
 static constexpr auto hiddenProps{std::to_array<const char*>(
-    {CPUSensor::labelTcontrol, "Tthrottle", "Tjmax"})};
+    {IntelCPUSensor::labelTcontrol, "Tthrottle", "Tjmax"})};
 
 void detectCpuAsync(
     boost::asio::deadline_timer& pingTimer,
@@ -372,7 +373,7 @@
             if (sensorThresholds.empty())
             {
                 if (!parseThresholdsFromAttr(sensorThresholds, inputPathStr,
-                                             CPUSensor::sensorScaleFactor,
+                                             IntelCPUSensor::sensorScaleFactor,
                                              dtsOffset))
                 {
                     std::cerr << "error populating thresholds for "
@@ -382,7 +383,7 @@
             auto& sensorPtr = gCpuSensors[sensorName];
             // make sure destructor fires before creating a new one
             sensorPtr = nullptr;
-            sensorPtr = std::make_shared<CPUSensor>(
+            sensorPtr = std::make_shared<IntelCPUSensor>(
                 inputPathStr, sensorType, objectServer, dbusConnection, io,
                 sensorName, std::move(sensorThresholds), *interfacePath, cpuId,
                 show, dtsOffset);
@@ -776,7 +777,7 @@
         matches.emplace_back(std::move(match));
     }
 
-    systemBus->request_name("xyz.openbmc_project.CPUSensor");
+    systemBus->request_name("xyz.openbmc_project.IntelCPUSensor");
 
     setupManufacturingModeMatch(*systemBus);
     io.run();
diff --git a/src/meson.build b/src/meson.build
index 4c3d61c..e420b27 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -21,11 +21,11 @@
     )
 endif
 
-if get_option('cpu').enabled()
+if get_option('intel-cpu').enabled()
     executable(
-        'cpusensor',
-        'CPUSensorMain.cpp',
-        'CPUSensor.cpp',
+        'intelcpusensor',
+        'IntelCPUSensorMain.cpp',
+        'IntelCPUSensor.cpp',
         dependencies: [
             default_deps,
             gpiodcxx,