| #ifndef PRODUCTION_BORG_MGMT_NODE_PROXY_SAFEPOWER_SAFEPOWER_AGENT_STATIC_STATE_H_ |
| #define PRODUCTION_BORG_MGMT_NODE_PROXY_SAFEPOWER_SAFEPOWER_AGENT_STATIC_STATE_H_ |
| |
| #include <memory> |
| #include <string> |
| |
| #include "safepower_agent.pb.h" |
| #include "state_updater.h" |
| #include "absl/functional/any_invocable.h" |
| #include "absl/status/statusor.h" |
| #include "absl/time/time.h" |
| |
| namespace safepower_agent { |
| |
| struct StaticStateLoaderConfig { |
| absl::Duration retry_interval = absl::Seconds(1); |
| absl::Duration timeout = absl::InfiniteDuration(); |
| int max_retries = -1; |
| }; |
| |
| class StaticStateLoader { |
| public: |
| using GetStateCallback = absl::AnyInvocable<void( |
| absl::StatusOr<safepower_agent_proto::SystemState>)>; |
| |
| explicit StaticStateLoader( |
| std::string name, |
| absl::AnyInvocable<absl::StatusOr<safepower_agent_proto::SystemState>()> |
| get_state, |
| std::shared_ptr<StateUpdater<safepower_agent_proto::SystemState>> |
| state_updater, |
| const StaticStateLoaderConfig& config = {}); |
| explicit StaticStateLoader( |
| std::string name, absl::AnyInvocable<void(GetStateCallback)> get_state, |
| std::shared_ptr<StateUpdater<safepower_agent_proto::SystemState>> |
| state_updater, |
| const StaticStateLoaderConfig& config = {}); |
| |
| ~StaticStateLoader(); |
| |
| private: |
| void TryLoadState(); |
| |
| std::string name_; |
| absl::AnyInvocable<void(GetStateCallback)> get_state_; |
| std::shared_ptr<StateUpdater<safepower_agent_proto::SystemState>> |
| state_updater_; |
| absl::Duration retry_interval_; |
| absl::Time timeout_time_; |
| int retries_left_ = 0; |
| }; |
| |
| } // namespace safepower_agent |
| |
| #endif // PRODUCTION_BORG_MGMT_NODE_PROXY_SAFEPOWER_SAFEPOWER_AGENT_STATIC_STATE_H_ |