blob: f2dc163c7bf55fda714801db07e8338a80369fda [file] [log] [blame]
Ed Tanous911ac312017-08-15 09:37:42 -07001#pragma once
2
3#include <dbus_singleton.hpp>
4#include <fstream>
5#include <crow/app.h>
6
7namespace crow {
8namespace intel_oem {
9
10template <typename... Middlewares>
11void request_routes(Crow<Middlewares...>& app) {
12 CROW_ROUTE(app, "/intel/firmwareupload")
Ed Tanousaa2e59c2018-04-12 12:17:20 -070013 .methods(
14 "POST"_method)([](const crow::request& req, crow::response& res) {
Ed Tanous911ac312017-08-15 09:37:42 -070015 std::string filepath("/tmp/fw_update_image");
16 std::ofstream out(filepath, std::ofstream::out | std::ofstream::binary |
17 std::ofstream::trunc);
18 out << req.body;
19 out.close();
Ed Tanousaa2e59c2018-04-12 12:17:20 -070020 crow::connections::system_bus->async_method_call(
21 [&](boost::system::error_code ec) {
22 std::cout << "async_method_call callback\n";
23 if (ec) {
24 std::cerr << "error with async_method_call \n";
25 res.json_value["status"] = "Upload failed";
26 } else {
27 res.json_value["status"] = "Upload Successful";
28 }
29 res.end();
30 },
31 "xyz.openbmc_project.fwupdate1.server",
32 "/xyz/openbmc_project/fwupdate1", "xyz.openbmc_project.fwupdate1",
33 "start", "file://" + filepath);
Ed Tanous911ac312017-08-15 09:37:42 -070034
Ed Tanous911ac312017-08-15 09:37:42 -070035 });
36}
Ed Tanousaa2e59c2018-04-12 12:17:20 -070037} // namespace intel_oem
Ed Tanous911ac312017-08-15 09:37:42 -070038} // namespace crow