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") |
Ed Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 13 | .methods( |
| 14 | "POST"_method)([](const crow::request& req, crow::response& res) { |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 15 | 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 Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 20 | 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 Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 34 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 35 | }); |
| 36 | } |
Ed Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 37 | } // namespace intel_oem |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 38 | } // namespace crow |