Jagpal Singh Gill | ca8c7e9 | 2024-11-02 16:51:48 -0700 | [diff] [blame^] | 1 | #include "CableEvents.hpp" |
| 2 | |
| 3 | #include <phosphor-logging/commit.hpp> |
| 4 | #include <phosphor-logging/lg2.hpp> |
| 5 | #include <sdbusplus/async.hpp> |
| 6 | #include <xyz/openbmc_project/State/Cable/event.hpp> |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | PHOSPHOR_LOG2_USING; |
| 11 | |
| 12 | namespace cable |
| 13 | { |
| 14 | |
| 15 | auto Events::generateCableEvent(Type type, std::string name) |
| 16 | -> sdbusplus::async::task<> |
| 17 | { |
| 18 | // Added NO_LINT to bypass clang-tidy warning about STDEXEC_ASSERT as clang |
| 19 | // seems to be confused about context being uninitialized. |
| 20 | // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.Branch) |
| 21 | if (type == Type::connected) |
| 22 | { |
| 23 | auto pendingEvent = pendingEvents.find(name); |
| 24 | if (pendingEvent != pendingEvents.end()) |
| 25 | { |
| 26 | co_await lg2::resolve(ctx, pendingEvent->second); |
| 27 | |
| 28 | using CableConnected = sdbusplus::event::xyz::openbmc_project:: |
| 29 | state::Cable::CableConnected; |
| 30 | co_await lg2::commit(ctx, CableConnected("PORT_ID", name)); |
| 31 | pendingEvents.erase(pendingEvent); |
| 32 | } |
| 33 | } |
| 34 | else if (type == Type::disconnected) |
| 35 | { |
| 36 | using CableDisconnected = sdbusplus::error::xyz::openbmc_project:: |
| 37 | state::Cable::CableDisconnected; |
| 38 | auto eventPath = |
| 39 | co_await lg2::commit(ctx, CableDisconnected("PORT_ID", name)); |
| 40 | warning("Generate CableDisconnected for {NAME}", "NAME", name); |
| 41 | pendingEvents.emplace(name, eventPath); |
| 42 | } |
| 43 | else |
| 44 | { |
| 45 | error("Unknown cable event type"); |
| 46 | } |
| 47 | co_return; |
| 48 | } |
| 49 | |
| 50 | } // namespace cable |