blob: 2d2cea28f529014dd4bfe5d06e914b65d87737be [file] [log] [blame]
Brad Bishope55ef3d2016-12-19 09:12:40 -05001#pragma once
2
Brad Bishopd499ca62016-12-19 09:24:50 -05003#include <string>
4
5/** @class MainLoop
6 * @brief hwmon-readd main application loop.
7 */
8class MainLoop
9{
10 public:
11 MainLoop() = delete;
12 MainLoop(const MainLoop&) = delete;
13 MainLoop& operator=(const MainLoop&) = delete;
14 MainLoop(MainLoop&&) = default;
15 MainLoop& operator=(MainLoop&&) = default;
16 ~MainLoop() = default;
17
18 /** @brief Constructor
19 *
20 * @param[in] path - hwmon sysfs instance to manage
Brad Bishopb9e2b072016-12-19 13:47:10 -050021 * @param[in] prefix - DBus busname prefix.
22 * @param[in] root - DBus sensors namespace root.
23 *
24 * Any DBus objects are created relative to the DBus
25 * sensors namespace root.
26 *
27 * At startup, the application will own a busname with
28 * the format <prefix>.hwmon<n>.
Brad Bishopd499ca62016-12-19 09:24:50 -050029 */
Brad Bishopb9e2b072016-12-19 13:47:10 -050030 MainLoop(
31 const std::string& path,
32 const char* prefix,
33 const char* root);
Brad Bishopd499ca62016-12-19 09:24:50 -050034
35 /** @brief Start polling loop and process dbus traffic. */
36 void run();
37
38 /** @brief Stop loop from another thread.
39 *
40 * Typically only used by testcases.
41 */
42 void shutdown() noexcept;
43
44 private:
45
46 /** @brief Shutdown requested. */
47 volatile bool _shutdown;
48 /** @brief Path to hwmon sysfs instance. */
49 std::string _path;
Brad Bishopb9e2b072016-12-19 13:47:10 -050050 /** @brief DBus busname prefix. */
51 const char* _prefix;
52 /** @brief DBus sensors namespace root. */
53 const char* _root;
Brad Bishopd499ca62016-12-19 09:24:50 -050054};