blob: 94f1cb98d131e2fb506210000e3121a240062180 [file] [log] [blame]
Carol Wangd82a3ac2019-11-21 13:56:38 +08001#pragma once
2
3#include "node.hpp"
4
5namespace redfish
6{
7/**
8 * BiosService class supports handle get method for bios.
9 */
10class BiosService : public Node
11{
12 public:
13 BiosService(CrowApp &app) : Node(app, "/redfish/v1/Systems/system/Bios/")
14 {
15 entityPrivileges = {{boost::beast::http::verb::get, {{"Login"}}}};
16 }
17
18 private:
19 void doGet(crow::Response &res, const crow::Request &req,
20 const std::vector<std::string> &params) override
21 {
22 auto asyncResp = std::make_shared<AsyncResp>(res);
23
24 asyncResp->res.jsonValue["@odata.id"] =
25 "/redfish/v1/Systems/system/Bios";
26 asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios";
27 asyncResp->res.jsonValue["Name"] = "BIOS Configuration";
28 asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service";
29 asyncResp->res.jsonValue["Id"] = "BIOS";
30 asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"] = {
31 {"target",
32 "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios"}};
33 }
34};
35/**
36 * BiosReset class supports handle POST method for Reset bios.
37 * The class retrieves and sends data directly to D-Bus.
38 */
39class BiosReset : public Node
40{
41 public:
42 BiosReset(CrowApp &app) :
43 Node(app, "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios/")
44 {
45 entityPrivileges = {
46 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
47 }
48
49 private:
50 /**
51 * Function handles POST method request.
52 * Analyzes POST body message before sends Reset request data to D-Bus.
53 */
54 void doPost(crow::Response &res, const crow::Request &req,
55 const std::vector<std::string> &params) override
56 {
57 auto asyncResp = std::make_shared<AsyncResp>(res);
58
59 crow::connections::systemBus->async_method_call(
60 [asyncResp](const boost::system::error_code ec) {
61 if (ec)
62 {
63 BMCWEB_LOG_ERROR << "Failed to reset bios: " << ec;
64 messages::internalError(asyncResp->res);
65 return;
66 }
67 },
68 "org.open_power.Software.Host.Updater",
69 "/xyz/openbmc_project/software",
70 "xyz.openbmc_project.Common.FactoryReset", "Reset");
71 }
72};
73} // namespace redfish