Move value interface creation to a helper method.
Change-Id: Id383f18e681a30f41976c07be1c7c9929af6abb5
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/mainloop.cpp b/mainloop.cpp
index a59fc1e..e8cf0ee 100644
--- a/mainloop.cpp
+++ b/mainloop.cpp
@@ -62,6 +62,45 @@
return std::get<2>(attrs);
}
+auto addValue(const SensorSet::key_type& sensor,
+ const std::string& sysfsRoot, ObjectInfo& info)
+{
+ // Get the initial value for the value interface.
+ auto& bus = *std::get<sdbusplus::bus::bus*>(info);
+ auto& obj = std::get<Object>(info);
+ auto& objPath = std::get<std::string>(info);
+
+ auto sysfsPath = make_sysfs_path(
+ sysfsRoot,
+ sensor.first,
+ sensor.second,
+ hwmon::entry::input);
+ int val = 0;
+ read_sysfs(sysfsPath, val);
+
+ auto iface = std::make_shared<ValueObject>(bus, objPath.c_str());
+ iface->value(val);
+
+ // *INDENT-OFF*
+ const auto& attrs = std::find_if(
+ typeAttrMap.begin(),
+ typeAttrMap.end(),
+ [&](const auto & e)
+ {
+ return sensor.first == getHwmonType(e);
+ });
+ // *INDENT-ON*
+
+ if (attrs != typeAttrMap.end())
+ {
+ iface->unit(getUnit(*attrs));
+ iface->scale(getScale(*attrs));
+ }
+
+ obj[InterfaceType::VALUE] = iface;
+ return iface;
+}
+
MainLoop::MainLoop(
sdbusplus::bus::bus&& bus,
const std::string& path,
@@ -102,15 +141,6 @@
continue;
}
- // Get the initial value for the value interface.
- auto sysfsPath = make_sysfs_path(
- _path,
- i.first.first,
- i.first.second,
- hwmon::entry::input);
- int val = 0;
- read_sysfs(sysfsPath, val);
-
std::string objectPath{_root};
objectPath.append("/");
objectPath.append(i.first.first);
@@ -118,25 +148,7 @@
objectPath.append(label);
ObjectInfo info(&_bus, std::move(objectPath), Object());
- auto& o = std::get<Object>(info);
-
- auto iface = std::make_shared<ValueObject>(_bus, objectPath.c_str());
- iface->value(val);
-
- const auto& attrs = std::find_if(
- typeAttrMap.begin(),
- typeAttrMap.end(),
- [&](const auto & e)
- {
- return i.first.first == getHwmonType(e);
- });
- if (attrs != typeAttrMap.end())
- {
- iface->unit(getUnit(*attrs));
- iface->scale(getScale(*attrs));
- }
-
- o.emplace(InterfaceType::VALUE, iface);
+ auto valueInterface = addValue(i.first, _path, info);
auto value = std::make_tuple(
std::move(i.second),