| #ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_COLLECTOR_MONITORING_CHANGE_BASE_H_ |
| #define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_COLLECTOR_MONITORING_CHANGE_BASE_H_ |
| |
| #include <optional> |
| #include <string_view> |
| |
| namespace milotic_tlbmc { |
| |
| // Sampling interval in milliseconds |
| using Interval = int; |
| // Interval used for stopping the monitoring of a sensor |
| constexpr Interval kStopMonitoring = 0; |
| // Interval used for resetting the monitoring of a sensor to the default |
| // ambient interval and batch size. |
| constexpr Interval kResetMonitoring = -1; |
| constexpr Interval kDefaultAmbientPollingIntervalMsec = 2000; |
| using BatchSize = int; |
| constexpr BatchSize kDefaultAmbientBatchSize = 1; |
| |
| // A change to the monitoring configuration of a sensor. |
| struct Mutation { |
| std::optional<Interval> interval; |
| std::optional<BatchSize> batch_size; |
| |
| bool operator==(const Mutation&) const = default; |
| bool operator!=(const Mutation&) const = default; |
| |
| void MergeWith(const Mutation& other) { |
| if (other.interval.has_value()) { |
| interval = other.interval; |
| } |
| if (other.batch_size.has_value()) { |
| batch_size = other.batch_size; |
| } |
| } |
| }; |
| |
| // Transaction like object, capturing monitoring changes to be applied to a |
| // store or collector. |
| // Once create, one or more sensor mutations are added, then Apply() is called |
| // to apply the changes, after which the object is destroyed. |
| class MonitoringChangeBase { |
| public: |
| virtual ~MonitoringChangeBase() = default; |
| virtual bool AddSensor(std::string_view sensor_key, Mutation mutation) & = 0; |
| virtual void Apply() && = 0; |
| }; |
| |
| } // namespace milotic_tlbmc |
| |
| #endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_COLLECTOR_MONITORING_CHANGE_BASE_H_ |