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