| #ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_SHARED_MEM_BASED_SENSOR_H_ |
| #define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_SHARED_MEM_BASED_SENSOR_H_ |
| |
| #include <array> |
| #include <atomic> |
| #include <cstddef> |
| #include <fstream> |
| #include <memory> |
| #include <optional> |
| #include <string> |
| #include <string_view> |
| |
| #include "absl/functional/any_invocable.h" |
| #include "absl/status/statusor.h" |
| #include "boost/asio.hpp" //NOLINT: boost::asio is commonly used in BMC |
| #include "i2c_common_config.pb.h" |
| #include "shared_mem_sensor_config.pb.h" |
| #include "sensor.pb.h" |
| #include "tlbmc/sensors/sensor.h" |
| |
| namespace milotic_tlbmc { |
| class SharedMemBasedSensor |
| : public Sensor, |
| public std::enable_shared_from_this<SharedMemBasedSensor> { |
| private: |
| class Token; |
| |
| public: |
| static absl::StatusOr<std::shared_ptr<Sensor>> Create( |
| const SharedMemSensorConfig& config, |
| const std::shared_ptr<boost::asio::io_context>& io_context, |
| std::optional<NotificationCb> on_batch_notify = std::nullopt); |
| |
| SharedMemBasedSensor( |
| Token token, SharedMemSensorType sensor_type, SensorUnit sensor_unit, |
| const std::string& sensor_name, |
| const EntityCommonConfig& entity_common_config, |
| const ThresholdConfigs& threshold_configs, |
| const std::shared_ptr<boost::asio::io_context>& io_context, |
| std::optional<NotificationCb> on_batch_notify = std::nullopt); |
| |
| ~SharedMemBasedSensor() override = default; |
| |
| void RefreshOnceAsync( |
| absl::AnyInvocable<void(const std::shared_ptr<const SensorValue>&)> |
| callback) override; |
| |
| private: |
| class Token { |
| private: |
| explicit Token() = default; |
| friend SharedMemBasedSensor; |
| }; |
| |
| std::shared_ptr<boost::asio::io_context> io_context_; |
| const SharedMemSensorType sensor_type_ = SHARED_MEM_SENSOR_TYPE_TYPE0_UNKNOWN; |
| const std::string sensor_name_; |
| const std::string board_config_name_; |
| }; |
| |
| } // namespace milotic_tlbmc |
| |
| #endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_SHARED_MEM_BASED_SENSOR_H_ |