blob: 1637b01f72ee907d8ed4f50c175446df79a206b0 [file] [log] [blame] [edit]
#include "bmc/daemon_context_bmc.h"
#include <cstdint>
#include "bmc/scheduler_bmc.h"
#include "daemon_context.h"
#include "persistent_storage.h"
#include "scheduler_interface.h"
#include "absl/synchronization/mutex.h"
#include "absl/time/time.h"
#include "boost/asio/io_context.hpp" // NOLINT(readability/boost)
namespace safepower_agent {
using boost::asio::io_context;
DaemonContextBMC::DaemonContextBMC()
: io_context_(1), // concurrency_hint 1
scheduler_(io_context_),
persistent_storage_manager_() {
epoch_ms_ = absl::ToUnixMillis(now());
}
DaemonContextBMC& DaemonContextBMC::Get() {
return static_cast<DaemonContextBMC&>(DaemonContext::Get());
}
SchedulerInterface& DaemonContextBMC::scheduler() { return scheduler_; }
PersistentStorageManager& DaemonContextBMC::persistent_storage_manager() {
absl::MutexLock lock(persistent_storage_manager_mutex_);
if (!persistent_storage_manager_.has_value()) {
if (config().has_persistent_storage_config()) {
persistent_storage_manager_.emplace(config().persistent_storage_config());
} else {
// Ignore deprecated warning to preserve backward compatibility with old gBMC
// configs. (-Werror causes build failure on gBMC otherwise.)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
persistent_storage_manager_.emplace(
config().gpowerd_config().persistent_storage_config());
#pragma GCC diagnostic pop
}
}
return *persistent_storage_manager_;
}
io_context& DaemonContextBMC::get_io_context() { return io_context_; }
uint64_t DaemonContextBMC::epoch_ms() { return epoch_ms_; }
} // namespace safepower_agent