* Copyright (c) 2026 Huawei Technologies Co., Ltd.
* openUBMC is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#include "one_power.h"
#include <cctype>
#include <mc/engine/property/ref_object.h>
#include <mc/engine/service.h>
#include <mc/log.h>
#include <mc/timer.h>
namespace dev {
#define DEFINE_PS_PROTOCOL(name, ClassType) \
{name, [](mc::dict& data) -> std::unique_ptr<ps_protocol_t> { \
return std::make_unique<ClassType>(data); \
}}
static const ps_protocol_map_t smc_protocol_map = {
};
const ps_protocol_map_t& OnePowerSmc::get_protocol_map() const
{
return smc_protocol_map;
}
bool OnePowerSmc::start()
{
m_power_supply.init(this);
m_power_supply_control.init(this);
m_power_supply_metrics.init(this);
m_power_supply_status.init(this);
m_power_supply_log_collection.init(this);
auto ref_chip_value = RefChip.get_value();
if (!ref_chip_value.is_null()) {
m_power_supply.RefChip = ref_chip_value.as<std::string>();
}
setup_oob_management();
m_power_supply.start();
m_power_supply_control.start();
m_power_supply_metrics.start();
m_power_supply_status.start();
evaluate_oob_management();
ilog("OnePowerSmc ${slot} started successfully", ("slot", m_power_supply.SlotNumber));
return true;
}
bool OnePowerSmc::stop()
{
teardown_oob_management();
m_power_supply.stop();
m_power_supply_control.stop();
m_power_supply_metrics.stop();
m_power_supply_status.stop();
ilog("OnePowerSmc ${slot} stopped", ("slot", m_power_supply.SlotNumber));
return true;
}
bool OnePowerSmc::init(mc::mutable_dict& csr_object, const mc::dict& connector)
{
m_self = this;
try {
OnePowerSmc::from_variant(csr_object, *this);
m_ref_obj = RefChip.get_value().as<mc::engine::ref_object*>();
if (m_ref_obj == nullptr) {
elog("OnePowerSmc ${slot} init FAILED: RefChip ref_object is NULL", ("slot", m_power_supply.SlotNumber));
return false;
}
ilog("OnePowerSmc ${slot} initialized successfully, protocol: ${protocol}",
("slot", m_power_supply.SlotNumber)("protocol", m_power_supply.Protocol));
} catch (const std::exception& e) {
elog("OnePowerSmc init failed, exception: ${exception}", ("exception", e.what()));
return false;
}
return true;
}
void OnePowerSmc::from_variant(const mc::dict& d, dev::OnePowerSmc& obj)
{
mc::from_variant(d, obj);
}
std::string OnePowerSmc::get_active_interface() const
{
return PhysicalInterface.get_value().as<std::string>();
}
bool OnePowerSmc::start_oob_management()
{
return true;
}
}
MC_REFLECT(dev::OnePowerSmc,
((RefChip, "RefChip"))((PhysicalInterface, "PhysicalInterface"))((m_power_supply, "bmc.dev.PowerSupply"))(
(m_power_supply_control, "bmc.dev.PowerSupply.Control"))(
(m_power_supply_metrics, "bmc.dev.PowerSupply.Metrics"))((m_power_supply_status,
"bmc.dev.PowerSupply.Status"))(
(m_power_supply_log_collection, "bmc.dev.PowerSupply.LogCollection"))((m_shared_mgmt,
"bmc.dev.SharedManagement")))