Initial read-daemon for hwmon entries
Discoveres hwmon entries for fans, input voltage, and temperature
sensors. Polls entries on a 1s interval and displays a message to
stdout if one of the entries have changed.
diff --git a/directory.C b/directory.C
new file mode 100644
index 0000000..5be9ff1
--- /dev/null
+++ b/directory.C
@@ -0,0 +1,38 @@
+#include <cerrno>
+#include <cstring>
+#include <iostream>
+#include "directory.H"
+
+Directory::Directory(const std::string& path) : entry(nullptr)
+{
+ dirp = opendir(path.c_str());
+ if (NULL == dirp)
+ {
+ auto e = errno;
+ std::cerr << "Error opening directory " << path.c_str()
+ << " : " << strerror(e) << std::endl;
+ }
+}
+
+Directory::~Directory()
+{
+ if (dirp)
+ {
+ closedir(dirp);
+ }
+}
+
+bool Directory::next(std::string& name)
+{
+ if (!dirp) return false;
+
+ dirent entry;
+ dirent* result;
+
+ auto rc = readdir_r(dirp, &entry, &result);
+
+ if ((rc) || (NULL == result)) return false;
+
+ name = entry.d_name;
+ return true;
+}