blob: 23ee683cd86f1c72063b83e71b68867872cf6d57 [file] [log] [blame]
Brad Bishope55ef3d2016-12-19 09:12:40 -05001#pragma once
2
Brad Bishopd499ca62016-12-19 09:24:50 -05003#include <string>
Brad Bishop9c7b6e02016-12-19 12:43:36 -05004#include <sdbusplus/server.hpp>
Brad Bishopd499ca62016-12-19 09:24:50 -05005
6/** @class MainLoop
7 * @brief hwmon-readd main application loop.
8 */
9class MainLoop
10{
11 public:
12 MainLoop() = delete;
13 MainLoop(const MainLoop&) = delete;
14 MainLoop& operator=(const MainLoop&) = delete;
15 MainLoop(MainLoop&&) = default;
16 MainLoop& operator=(MainLoop&&) = default;
17 ~MainLoop() = default;
18
19 /** @brief Constructor
20 *
Brad Bishop9c7b6e02016-12-19 12:43:36 -050021 * @param[in] bus - sdbusplus bus client connection.
Brad Bishopd499ca62016-12-19 09:24:50 -050022 * @param[in] path - hwmon sysfs instance to manage
Brad Bishopb9e2b072016-12-19 13:47:10 -050023 * @param[in] prefix - DBus busname prefix.
24 * @param[in] root - DBus sensors namespace root.
25 *
26 * Any DBus objects are created relative to the DBus
27 * sensors namespace root.
28 *
29 * At startup, the application will own a busname with
30 * the format <prefix>.hwmon<n>.
Brad Bishopd499ca62016-12-19 09:24:50 -050031 */
Brad Bishopb9e2b072016-12-19 13:47:10 -050032 MainLoop(
Brad Bishop9c7b6e02016-12-19 12:43:36 -050033 sdbusplus::bus::bus&& bus,
Brad Bishopb9e2b072016-12-19 13:47:10 -050034 const std::string& path,
35 const char* prefix,
36 const char* root);
Brad Bishopd499ca62016-12-19 09:24:50 -050037
38 /** @brief Start polling loop and process dbus traffic. */
39 void run();
40
41 /** @brief Stop loop from another thread.
42 *
43 * Typically only used by testcases.
44 */
45 void shutdown() noexcept;
46
47 private:
Brad Bishop9c7b6e02016-12-19 12:43:36 -050048 /** @brief sdbusplus bus client connection. */
49 sdbusplus::bus::bus _bus;
50 /** @brief sdbusplus freedesktop.ObjectManager storage. */
51 sdbusplus::server::manager::manager _manager;
Brad Bishopd499ca62016-12-19 09:24:50 -050052 /** @brief Shutdown requested. */
53 volatile bool _shutdown;
54 /** @brief Path to hwmon sysfs instance. */
55 std::string _path;
Brad Bishopb9e2b072016-12-19 13:47:10 -050056 /** @brief DBus busname prefix. */
57 const char* _prefix;
58 /** @brief DBus sensors namespace root. */
59 const char* _root;
Brad Bishopd499ca62016-12-19 09:24:50 -050060};