Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 3 | #include <string> |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 4 | #include <sdbusplus/server.hpp> |
Brad Bishop | 3c344d3 | 2017-01-05 11:48:39 -0500 | [diff] [blame] | 5 | #include "sensorset.hpp" |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 6 | |
| 7 | /** @class MainLoop |
| 8 | * @brief hwmon-readd main application loop. |
| 9 | */ |
| 10 | class 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 Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 22 | * @param[in] bus - sdbusplus bus client connection. |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 23 | * @param[in] path - hwmon sysfs instance to manage |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 24 | * @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 Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 32 | */ |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 33 | MainLoop( |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 34 | sdbusplus::bus::bus&& bus, |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 35 | const std::string& path, |
| 36 | const char* prefix, |
| 37 | const char* root); |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 38 | |
| 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 Bishop | 3c344d3 | 2017-01-05 11:48:39 -0500 | [diff] [blame] | 49 | using mapped_type = std::tuple<SensorSet::mapped_type>; |
| 50 | using SensorState = std::map<SensorSet::key_type, mapped_type>; |
| 51 | |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 52 | /** @brief sdbusplus bus client connection. */ |
| 53 | sdbusplus::bus::bus _bus; |
| 54 | /** @brief sdbusplus freedesktop.ObjectManager storage. */ |
| 55 | sdbusplus::server::manager::manager _manager; |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 56 | /** @brief Shutdown requested. */ |
| 57 | volatile bool _shutdown; |
| 58 | /** @brief Path to hwmon sysfs instance. */ |
| 59 | std::string _path; |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 60 | /** @brief DBus busname prefix. */ |
| 61 | const char* _prefix; |
| 62 | /** @brief DBus sensors namespace root. */ |
| 63 | const char* _root; |
Brad Bishop | 3c344d3 | 2017-01-05 11:48:39 -0500 | [diff] [blame] | 64 | /** @brief DBus object state. */ |
| 65 | SensorState state; |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 66 | }; |