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 | 075f7a2 | 2017-01-06 09:45:08 -0500 | [diff] [blame] | 4 | #include <vector> |
| 5 | #include <experimental/any> |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 6 | #include <sdbusplus/server.hpp> |
Brad Bishop | 3c344d3 | 2017-01-05 11:48:39 -0500 | [diff] [blame] | 7 | #include "sensorset.hpp" |
Brad Bishop | 075f7a2 | 2017-01-06 09:45:08 -0500 | [diff] [blame] | 8 | #include "interface.hpp" |
| 9 | |
| 10 | using Object = std::map<InterfaceType, std::experimental::any>; |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 11 | |
| 12 | /** @class MainLoop |
| 13 | * @brief hwmon-readd main application loop. |
| 14 | */ |
| 15 | class MainLoop |
| 16 | { |
| 17 | public: |
| 18 | MainLoop() = delete; |
| 19 | MainLoop(const MainLoop&) = delete; |
| 20 | MainLoop& operator=(const MainLoop&) = delete; |
| 21 | MainLoop(MainLoop&&) = default; |
| 22 | MainLoop& operator=(MainLoop&&) = default; |
| 23 | ~MainLoop() = default; |
| 24 | |
| 25 | /** @brief Constructor |
| 26 | * |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 27 | * @param[in] bus - sdbusplus bus client connection. |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 28 | * @param[in] path - hwmon sysfs instance to manage |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 29 | * @param[in] prefix - DBus busname prefix. |
| 30 | * @param[in] root - DBus sensors namespace root. |
| 31 | * |
| 32 | * Any DBus objects are created relative to the DBus |
| 33 | * sensors namespace root. |
| 34 | * |
| 35 | * At startup, the application will own a busname with |
| 36 | * the format <prefix>.hwmon<n>. |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 37 | */ |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 38 | MainLoop( |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 39 | sdbusplus::bus::bus&& bus, |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 40 | const std::string& path, |
| 41 | const char* prefix, |
| 42 | const char* root); |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 43 | |
| 44 | /** @brief Start polling loop and process dbus traffic. */ |
| 45 | void run(); |
| 46 | |
| 47 | /** @brief Stop loop from another thread. |
| 48 | * |
| 49 | * Typically only used by testcases. |
| 50 | */ |
| 51 | void shutdown() noexcept; |
| 52 | |
| 53 | private: |
Brad Bishop | 075f7a2 | 2017-01-06 09:45:08 -0500 | [diff] [blame] | 54 | using mapped_type = std::tuple<SensorSet::mapped_type, std::string, Object>; |
Brad Bishop | 3c344d3 | 2017-01-05 11:48:39 -0500 | [diff] [blame] | 55 | using SensorState = std::map<SensorSet::key_type, mapped_type>; |
| 56 | |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 57 | /** @brief sdbusplus bus client connection. */ |
| 58 | sdbusplus::bus::bus _bus; |
| 59 | /** @brief sdbusplus freedesktop.ObjectManager storage. */ |
| 60 | sdbusplus::server::manager::manager _manager; |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 61 | /** @brief Shutdown requested. */ |
| 62 | volatile bool _shutdown; |
| 63 | /** @brief Path to hwmon sysfs instance. */ |
| 64 | std::string _path; |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 65 | /** @brief DBus busname prefix. */ |
| 66 | const char* _prefix; |
| 67 | /** @brief DBus sensors namespace root. */ |
| 68 | const char* _root; |
Brad Bishop | 3c344d3 | 2017-01-05 11:48:39 -0500 | [diff] [blame] | 69 | /** @brief DBus object state. */ |
| 70 | SensorState state; |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 71 | }; |