Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <dbus_singleton.hpp> |
| 4 | #include <fstream> |
| 5 | #include <crow/app.h> |
| 6 | |
| 7 | namespace crow { |
| 8 | namespace intel_oem { |
| 9 | |
| 10 | template <typename... Middlewares> |
| 11 | void request_routes(Crow<Middlewares...>& app) { |
| 12 | CROW_ROUTE(app, "/intel/firmwareupload") |
| 13 | .methods("POST"_method)([](const crow::request& req) { |
| 14 | std::string filepath("/tmp/fw_update_image"); |
| 15 | std::ofstream out(filepath, std::ofstream::out | std::ofstream::binary | |
| 16 | std::ofstream::trunc); |
| 17 | out << req.body; |
| 18 | out.close(); |
| 19 | |
| 20 | auto m = dbus::message::new_call( |
| 21 | {"xyz.openbmc_project.fwupdate1.server", |
| 22 | "/xyz/openbmc_project/fwupdate1", "xyz.openbmc_project.fwupdate1"}, |
| 23 | "start"); |
| 24 | |
| 25 | m.pack(std::string("file://") + filepath); |
| 26 | crow::connections::system_bus->send(m); |
| 27 | nlohmann::json j; |
| 28 | j["status"] = "Upload Successful"; |
| 29 | return j; |
| 30 | }); |
| 31 | } |
| 32 | } // namespace redfish |
| 33 | } // namespace crow |