Add a shutdown option to main loop
A shutdown option allows another thread to shut the server
down. Typically this is only done at the end of a testcase
that runs the server in one thread, and then executes tests
from another.
Change-Id: I7658bba79285d7c3e41b578c3510faa3363c5e01
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/mainloop.hpp b/mainloop.hpp
index d3a5f96..4bc08c4 100644
--- a/mainloop.hpp
+++ b/mainloop.hpp
@@ -1,3 +1,39 @@
#pragma once
-int serverMain(const char* path);
+#include <string>
+
+/** @class MainLoop
+ * @brief hwmon-readd main application loop.
+ */
+class MainLoop
+{
+ public:
+ MainLoop() = delete;
+ MainLoop(const MainLoop&) = delete;
+ MainLoop& operator=(const MainLoop&) = delete;
+ MainLoop(MainLoop&&) = default;
+ MainLoop& operator=(MainLoop&&) = default;
+ ~MainLoop() = default;
+
+ /** @brief Constructor
+ *
+ * @param[in] path - hwmon sysfs instance to manage
+ */
+ explicit MainLoop(const std::string& path);
+
+ /** @brief Start polling loop and process dbus traffic. */
+ void run();
+
+ /** @brief Stop loop from another thread.
+ *
+ * Typically only used by testcases.
+ */
+ void shutdown() noexcept;
+
+ private:
+
+ /** @brief Shutdown requested. */
+ volatile bool _shutdown;
+ /** @brief Path to hwmon sysfs instance. */
+ std::string _path;
+};