Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 1 | #include <memory> |
Deepak Kodihalli | 02ba9ec | 2017-03-18 02:57:43 -0500 | [diff] [blame^] | 2 | #include <algorithm> |
| 3 | #include <phosphor-logging/log.hpp> |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 4 | #include "occ_pass_through.hpp" |
| 5 | #include "occ_finder.hpp" |
| 6 | |
| 7 | namespace open_power |
| 8 | { |
| 9 | namespace occ |
| 10 | { |
| 11 | namespace pass_through |
| 12 | { |
| 13 | |
| 14 | void run() |
| 15 | { |
| 16 | auto bus = sdbusplus::bus::new_default(); |
| 17 | sdbusplus::server::manager::manager objManager(bus, |
| 18 | OCC_PASS_THROUGH_ROOT); |
| 19 | |
| 20 | std::vector<std::unique_ptr<PassThrough>> objects; |
| 21 | auto occs = open_power::occ::finder::get(); |
| 22 | |
| 23 | for (const auto& occ : occs) |
| 24 | { |
| 25 | auto occPassThrough = object(occ); |
| 26 | objects.emplace_back( |
| 27 | std::make_unique<PassThrough>(bus, occPassThrough.c_str())); |
| 28 | } |
| 29 | bus.request_name(OCC_PASS_THROUGH_BUSNAME); |
| 30 | |
| 31 | while (true) |
| 32 | { |
| 33 | bus.process_discard(); |
| 34 | bus.wait(); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | PassThrough::PassThrough( |
| 39 | sdbusplus::bus::bus& bus, |
| 40 | const char* path) : |
| 41 | Iface(bus, path), |
| 42 | path(path) |
| 43 | { |
| 44 | this->emit_object_added(); |
| 45 | } |
| 46 | |
| 47 | std::vector<int32_t> PassThrough::send(std::vector<int32_t> command) |
| 48 | { |
Deepak Kodihalli | 02ba9ec | 2017-03-18 02:57:43 -0500 | [diff] [blame^] | 49 | std::string msg = "Pass through to OCC "; |
| 50 | msg += path; |
| 51 | |
| 52 | std::string cmd; |
| 53 | std::for_each(command.cbegin(), command.cend(), |
| 54 | [&cmd](const auto& c) |
| 55 | { |
| 56 | cmd += std::to_string(c); |
| 57 | cmd += ','; |
| 58 | }); |
| 59 | if (!cmd.empty()) |
| 60 | { |
| 61 | // Remove trailing ',' |
| 62 | cmd.pop_back(); |
| 63 | } |
| 64 | |
| 65 | using namespace phosphor::logging; |
| 66 | log<level::INFO>(msg.c_str(), entry("COMMAND=%s", cmd.c_str())); |
| 67 | |
Deepak Kodihalli | 6b492fb | 2017-03-18 01:09:28 -0500 | [diff] [blame] | 68 | return {}; |
| 69 | } |
| 70 | |
| 71 | } // namespace pass_through |
| 72 | } // namespace occ |
| 73 | } // namespace open_power |