OpenBMC:BmcWeb定义service

1.定义service

cpp 复制代码
//src\webserver_run.cpp

int run()
{
    ...
    std::shared_ptr<sdbusplus::asio::connection> systemBus =
        std::make_shared<sdbusplus::asio::connection>(io);
    crow::connections::systemBus = systemBus.get();

    auto server = sdbusplus::asio::object_server(systemBus);

    std::shared_ptr<sdbusplus::asio::dbus_interface> iface =
        server.add_interface("/xyz/openbmc_project/bmcweb",
                             "xyz.openbmc_project.bmcweb");

    iface->register_method("SetLogLevel", setLogLevel);

    iface->initialize();
    ...

    systemBus->request_name("xyz.openbmc_project.bmcweb");
    ...
}

为BmcWeb定义了

Service:xyz.openbmc_project.bmcweb

ObjPath:/xyz/openbmc_project/bmcweb

Interface:xyz.openbmc_project.bmcweb

Method:SetLogLevel

2.设置日志级别

cpp 复制代码
//http\logging.hpp
constexpr std::array<std::string_view, 7> mapLogLevelFromName{
    "DISABLED", "CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "ENABLED"};

constexpr crow::LogLevel getLogLevelFromName(std::string_view name)
{
    const auto* iter = std::ranges::find(mapLogLevelFromName, name);
    if (iter != mapLogLevelFromName.end())
    {
        return static_cast<LogLevel>(iter - mapLogLevelFromName.begin());
    }
    return crow::LogLevel::Disabled;
}

enum class LogLevel
{
    Disabled = 0,
    Critical,
    Error,
    Warning,
    Info,
    Debug,
    Enabled,
};

inline crow::LogLevel& getBmcwebCurrentLoggingLevel()
{
    static crow::LogLevel level = getLogLevelFromName(BMCWEB_LOGGING_LEVEL);
    return level;
}
cpp 复制代码
//src\webserver_run.cpp
static void setLogLevel(const std::string& logLevel)
{
    const std::basic_string_view<char>* iter =
        std::ranges::find(crow::mapLogLevelFromName, logLevel);
    if (iter == crow::mapLogLevelFromName.end())
    {
        BMCWEB_LOG_ERROR("log-level {} not found", logLevel);
        return;
    }
    crow::getBmcwebCurrentLoggingLevel() = crow::getLogLevelFromName(logLevel);
    BMCWEB_LOG_INFO("Requested log-level change to: {}", logLevel);
}

BmcWeb被实现为一个service,目的只有一个就是设置日志级别

而日志级别被保存在函数getBmcwebCurrentLoggingLevel返回的单例对象中

相关推荐
消失的旧时光-19432 分钟前
函数指针 + 结构体 = C 语言的“对象模型”?——从 C 到 C++ / Java 的本质统一
linux·c语言·开发语言·c++·c
郝学胜-神的一滴6 分钟前
Linux系统编程:深入理解读写锁的原理与应用
linux·服务器·开发语言·c++·程序人生
Larry_Yanan6 分钟前
Qt多进程(十一)Linux下socket通信
linux·开发语言·c++·qt
__雨夜星辰__20 分钟前
VMware 17 下 Ubuntu 虚拟机与宿主机间复制粘贴失效问题
linux·运维·ubuntu
prettyxian22 分钟前
【linux】进程调度:优先级、时间片与O(1)算法
linux·运维·服务器
小猪佩奇TONY30 分钟前
Linux 内核学习(15) --- linux MMU 和 分页机制
linux·学习
jerryinwuhan30 分钟前
期末总复习
linux·运维
浅安的邂逅31 分钟前
ubuntu 18.04及以上版本配置静态IP方法
linux·运维·网络·ubuntu·ip设置
lxysbly36 分钟前
ps1模拟器安卓版带金手指
android·linux·运维
C_心欲无痕9 小时前
ts - tsconfig.json配置讲解
linux·前端·ubuntu·typescript·json