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 | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 5 | |
| 6 | /** @class MainLoop |
| 7 | * @brief hwmon-readd main application loop. |
| 8 | */ |
| 9 | class 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 Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame^] | 21 | * @param[in] bus - sdbusplus bus client connection. |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 22 | * @param[in] path - hwmon sysfs instance to manage |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 23 | * @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 Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 31 | */ |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 32 | MainLoop( |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame^] | 33 | sdbusplus::bus::bus&& bus, |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 34 | const std::string& path, |
| 35 | const char* prefix, |
| 36 | const char* root); |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 37 | |
| 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 Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame^] | 48 | /** @brief sdbusplus bus client connection. */ |
| 49 | sdbusplus::bus::bus _bus; |
| 50 | /** @brief sdbusplus freedesktop.ObjectManager storage. */ |
| 51 | sdbusplus::server::manager::manager _manager; |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 52 | /** @brief Shutdown requested. */ |
| 53 | volatile bool _shutdown; |
| 54 | /** @brief Path to hwmon sysfs instance. */ |
| 55 | std::string _path; |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 56 | /** @brief DBus busname prefix. */ |
| 57 | const char* _prefix; |
| 58 | /** @brief DBus sensors namespace root. */ |
| 59 | const char* _root; |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 60 | }; |