OpenBMC:BmcWeb app.run

1.监听用户移除signal

cpp 复制代码
//src\webserver_run.cpp
int run()
{
    ...
    bmcweb::registerUserRemovedSignal();

    ...
}
cpp 复制代码
//include\user_monitor.hpp
inline void onUserRemoved(sdbusplus::message_t& msg)
{
    sdbusplus::message::object_path p;
    msg.read(p);
    std::string username = p.filename();
    persistent_data::SessionStore::getInstance().removeSessionsByUsername(
        username);
}

inline void registerUserRemovedSignal()
{
    std::string userRemovedMatchStr =
        sdbusplus::bus::match::rules::interfacesRemoved(
            "/xyz/openbmc_project/user");

    static sdbusplus::bus::match_t userRemovedMatch(
        *crow::connections::systemBus, userRemovedMatchStr, onUserRemoved);
}

关于注册signal,可以参考

sdbusplus:监听属性的变化_sdbusplus::bus::match::match-CSDN博客

这部分的作用是当发现某个用户被移除后,删除该用户的session

session部分后续再介绍

2.app.run获取socket

cpp 复制代码
//src\webserver_run.cpp
int run()
{
    ...
    app.run();

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

    io.run();

    crow::connections::systemBus = nullptr;

    return 0;
}

其中app.run的定义如下:

cpp 复制代码
//http\app.hpp
void run()
{
    validate();

    std::vector<Acceptor> acceptors = setupSocket();

    server.emplace(this, std::move(acceptors));
    server->run();
}

validate();是用于检验route,这个后续跟路由一起解释

cpp 复制代码
//http\http_server.hpp
struct Acceptor
{
    boost::asio::ip::tcp::acceptor acceptor;
    HttpType httpType;
};
cpp 复制代码
//http\http_connect_types.hpp
enum class HttpType
{
    HTTPS, // Socket supports HTTPS only
    HTTP,  // Socket supports HTTP only
    BOTH   // Socket supports both HTTPS and HTTP, with HTTP Redirect
};

static std::vector<Acceptor> setupSocket() 的作用是获取socket,这个后续再详细解释

3.app.run构造server对象

cpp 复制代码
//http\http_server.hpp
template <typename Handler, typename Adaptor = boost::asio::ip::tcp::socket>
class Server
{
public:
    Server(Handler* handlerIn, std::vector<Acceptor>&& acceptorsIn) :
        acceptors(std::move(acceptorsIn)),

        // NOLINTNEXTLINE(misc-include-cleaner)
        signals(getIoContext(), SIGINT, SIGTERM, SIGHUP), handler(handlerIn)
    {}
    ...
private:
    std::vector<Acceptor> acceptors;
    Handler* handler;
}

OpenBMC:BmcWeb实例化App-CSDN博客

介绍了server类,但是当时没有构造server类的实例,

构造server类的实例是在app.run中

server.emplace(this, std::move(acceptors));完成的

将App做为handle传入Server,用于反向指回app对象

将setupSocket()获取的socket也传入了Server,用于后续接受连接请求。

相关推荐
wj3055853787 小时前
课程 9:模型测试记录与 Prompt 策略
linux·人工智能·python·comfyui
abigriver7 小时前
打造 Linux 离线大模型级语音输入法:Whisper.cpp + 3090 显卡加速与 Rime 中英混输终极调优指南
linux·运维·whisper
wangqiaowq8 小时前
windows下nginx的安装
linux·服务器·前端
YYRAN_ZZU8 小时前
Petalinux新建自动脚本启动
linux
charlie1145141919 小时前
嵌入式Linux驱动开发pinctrl篇(1)——从寄存器到子系统:驱动演进之路
linux·运维·驱动开发
于小猿Sup9 小时前
VMware在Ubuntu22.04驱动Livox Mid360s
linux·c++·嵌入式硬件·自动驾驶
cen__y9 小时前
Linux12(Git01)
linux·运维·服务器·c语言·开发语言·git
不仙52011 小时前
VMware Workstation 26.0.0 在 Ubuntu 24.04 (内核 6.17.0) 上的安装与内核模块编译问题
linux·ubuntu·elasticsearch
AI视觉网奇11 小时前
linux 检索库 判断库是否支持
java·linux·服务器
dapeng-大鹏11 小时前
KVM+LVM 零停机在线扩容 Ubuntu 根分区:从磁盘添加到逻辑卷扩展完整
linux·运维·ubuntu·磁盘空间扩展