summaryrefslogtreecommitdiffstats
path: root/mainloop.cpp
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2017-01-06 10:43:29 -0500
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2017-01-17 20:35:42 -0500
commite9fdee0c3a959a8bd0425d0203b1361ab03a0fb7 (patch)
tree8983cc72f4e6960a2265a600307ba1da636f99b2 /mainloop.cpp
parentf3df6b4fc061c274e712e53ae87617e2e8a8633b (diff)
downloadphosphor-hwmon-e9fdee0c3a959a8bd0425d0203b1361ab03a0fb7.tar.gz
phosphor-hwmon-e9fdee0c3a959a8bd0425d0203b1361ab03a0fb7.zip
Move value interface creation to a helper method.
Change-Id: Id383f18e681a30f41976c07be1c7c9929af6abb5 Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Diffstat (limited to 'mainloop.cpp')
-rw-r--r--mainloop.cpp68
1 files changed, 40 insertions, 28 deletions
diff --git a/mainloop.cpp b/mainloop.cpp
index a59fc1e..e8cf0ee 100644
--- a/mainloop.cpp
+++ b/mainloop.cpp
@@ -62,6 +62,45 @@ auto getScale(decltype(typeAttrMap)::const_reference attrs)
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 @@ void MainLoop::run()
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 @@ void MainLoop::run()
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),
OpenPOWER on IntegriCloud