blob: 878269196d198585f225f8a5250d9a2d4f50f36d [file]
#ifndef PRODUCTION_BORG_MGMT_NODE_PROXY_SAFEPOWER_SAFEPOWER_AGENT_POLLING_STATE_MONITOR_H_
#define PRODUCTION_BORG_MGMT_NODE_PROXY_SAFEPOWER_SAFEPOWER_AGENT_POLLING_STATE_MONITOR_H_
#include <memory>
#include <string>
#include "callback_manager.h"
#include "safepower_agent.pb.h"
#include "state_updater.h"
#include "absl/base/thread_annotations.h"
#include "absl/status/status.h"
#include "absl/strings/string_view.h"
#include "absl/synchronization/mutex.h"
#include "absl/time/time.h"
namespace safepower_agent {
class PollingStateMonitor {
public:
PollingStateMonitor(
std::string entity_tag, absl::Duration interval,
std::shared_ptr<StateUpdater<safepower_agent_proto::SystemState>>
system_state_updater,
std::string monitor_name);
PollingStateMonitor(const PollingStateMonitor&) = delete;
PollingStateMonitor& operator=(const PollingStateMonitor&) = delete;
virtual ~PollingStateMonitor();
absl::Status Start();
absl::string_view node_entity_tag() const { return entity_tag_; }
protected:
virtual void Check() = 0;
void StartTimer(absl::Duration interval)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(task_mutex_);
void StopTimer() ABSL_EXCLUSIVE_LOCKS_REQUIRED(task_mutex_);
void Pause() ABSL_LOCKS_EXCLUDED(task_mutex_);
void Resume() ABSL_LOCKS_EXCLUDED(task_mutex_);
virtual void OnPause() {}
std::string monitor_name_;
std::string entity_tag_;
absl::Duration interval_;
std::shared_ptr<StateUpdater<safepower_agent_proto::SystemState>>
system_state_updater_;
mutable absl::Mutex task_mutex_;
// The name of the timer task, or empty if the timer is not running.
std::string task_name_ ABSL_GUARDED_BY(task_mutex_);
private:
CallbackManager::Handle activate_callback_handle_;
CallbackManager::Handle idle_callback_handle_;
};
} // namespace safepower_agent
#endif // PRODUCTION_BORG_MGMT_NODE_PROXY_SAFEPOWER_SAFEPOWER_AGENT_POLLING_STATE_MONITOR_H_