blob: d1fc9cab217ec87c369b29cff893b2e10f86b0a8 [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 Bishop3c344d32017-01-05 11:48:39 -05005#include "sensorset.hpp"
Brad Bishopd499ca62016-12-19 09:24:50 -05006
7/** @class MainLoop
8 * @brief hwmon-readd main application loop.
9 */
10class MainLoop
11{
12 public:
13 MainLoop() = delete;
14 MainLoop(const MainLoop&) = delete;
15 MainLoop& operator=(const MainLoop&) = delete;
16 MainLoop(MainLoop&&) = default;
17 MainLoop& operator=(MainLoop&&) = default;
18 ~MainLoop() = default;
19
20 /** @brief Constructor
21 *
Brad Bishop9c7b6e02016-12-19 12:43:36 -050022 * @param[in] bus - sdbusplus bus client connection.
Brad Bishopd499ca62016-12-19 09:24:50 -050023 * @param[in] path - hwmon sysfs instance to manage
Brad Bishopb9e2b072016-12-19 13:47:10 -050024 * @param[in] prefix - DBus busname prefix.
25 * @param[in] root - DBus sensors namespace root.
26 *
27 * Any DBus objects are created relative to the DBus
28 * sensors namespace root.
29 *
30 * At startup, the application will own a busname with
31 * the format <prefix>.hwmon<n>.
Brad Bishopd499ca62016-12-19 09:24:50 -050032 */
Brad Bishopb9e2b072016-12-19 13:47:10 -050033 MainLoop(
Brad Bishop9c7b6e02016-12-19 12:43:36 -050034 sdbusplus::bus::bus&& bus,
Brad Bishopb9e2b072016-12-19 13:47:10 -050035 const std::string& path,
36 const char* prefix,
37 const char* root);
Brad Bishopd499ca62016-12-19 09:24:50 -050038
39 /** @brief Start polling loop and process dbus traffic. */
40 void run();
41
42 /** @brief Stop loop from another thread.
43 *
44 * Typically only used by testcases.
45 */
46 void shutdown() noexcept;
47
48 private:
Brad Bishop3c344d32017-01-05 11:48:39 -050049 using mapped_type = std::tuple<SensorSet::mapped_type>;
50 using SensorState = std::map<SensorSet::key_type, mapped_type>;
51
Brad Bishop9c7b6e02016-12-19 12:43:36 -050052 /** @brief sdbusplus bus client connection. */
53 sdbusplus::bus::bus _bus;
54 /** @brief sdbusplus freedesktop.ObjectManager storage. */
55 sdbusplus::server::manager::manager _manager;
Brad Bishopd499ca62016-12-19 09:24:50 -050056 /** @brief Shutdown requested. */
57 volatile bool _shutdown;
58 /** @brief Path to hwmon sysfs instance. */
59 std::string _path;
Brad Bishopb9e2b072016-12-19 13:47:10 -050060 /** @brief DBus busname prefix. */
61 const char* _prefix;
62 /** @brief DBus sensors namespace root. */
63 const char* _root;
Brad Bishop3c344d32017-01-05 11:48:39 -050064 /** @brief DBus object state. */
65 SensorState state;
Brad Bishopd499ca62016-12-19 09:24:50 -050066};