xref: /openbmc/phosphor-dbus-monitor/src/event_entry.hpp (revision 6524b9d8385919276d21471bec4352b00146c2d0)
13e84ec66SRatan Gupta #pragma once
23e84ec66SRatan Gupta 
33e84ec66SRatan Gupta #include "sdbusplus.hpp"
43e84ec66SRatan Gupta #include "xyz/openbmc_project/Logging/Event/server.hpp"
53e84ec66SRatan Gupta 
63e84ec66SRatan Gupta #include <sdbusplus/bus.hpp>
73e84ec66SRatan Gupta #include <sdbusplus/server/object.hpp>
83e84ec66SRatan Gupta 
93e84ec66SRatan Gupta namespace phosphor
103e84ec66SRatan Gupta {
113e84ec66SRatan Gupta namespace events
123e84ec66SRatan Gupta {
133e84ec66SRatan Gupta 
143e84ec66SRatan Gupta using namespace phosphor::dbus::monitoring;
153e84ec66SRatan Gupta 
163e84ec66SRatan Gupta using EntryIface = sdbusplus::server::object::object<
173e84ec66SRatan Gupta     sdbusplus::xyz::openbmc_project::Logging::server::Event>;
183e84ec66SRatan Gupta 
193e84ec66SRatan Gupta /** @class Entry
203e84ec66SRatan Gupta  *  @brief OpenBMC Event entry implementation.
213e84ec66SRatan Gupta  *  @details A concrete implementation for the
223e84ec66SRatan Gupta  *  xyz.openbmc_project.Event.Entry.
233e84ec66SRatan Gupta  */
243e84ec66SRatan Gupta class Entry : public EntryIface
253e84ec66SRatan Gupta {
263e84ec66SRatan Gupta   public:
273e84ec66SRatan Gupta     Entry() = delete;
283e84ec66SRatan Gupta     Entry(const Entry&) = delete;
293e84ec66SRatan Gupta     Entry& operator=(const Entry&) = delete;
303e84ec66SRatan Gupta     Entry(Entry&&) = delete;
313e84ec66SRatan Gupta     Entry& operator=(Entry&&) = delete;
323e84ec66SRatan Gupta     virtual ~Entry() = default;
333e84ec66SRatan Gupta 
343e84ec66SRatan Gupta     /** @brief Constructor to put object onto bus at a dbus path.
353e84ec66SRatan Gupta      *  @param[in] path - Path to attach at.
363e84ec66SRatan Gupta      *  @param[in] eventId - The event entry id.
373e84ec66SRatan Gupta      *  @param[in] timestamp - timestamp when the event created.
383e84ec66SRatan Gupta      *  @param[in] msg - The message of the event.
393e84ec66SRatan Gupta      *  @param[in] metaData - The event metadata.
403e84ec66SRatan Gupta      */
41d1eac88dSBrad Bishop     Entry(const std::string& path, uint64_t eventTimestamp, std::string&& msg,
423e84ec66SRatan Gupta           std::vector<std::string>&& metaData) :
433e84ec66SRatan Gupta         EntryIface(SDBusPlus::getBus(), path.c_str(), true),
443e84ec66SRatan Gupta         objectPath(path)
453e84ec66SRatan Gupta     {
463e84ec66SRatan Gupta         timestamp(eventTimestamp);
473e84ec66SRatan Gupta         message(msg);
483e84ec66SRatan Gupta         additionalData(metaData);
493e84ec66SRatan Gupta         // Emit deferred signal.
503e84ec66SRatan Gupta         this->emit_object_added();
513e84ec66SRatan Gupta     }
523e84ec66SRatan Gupta 
53*6524b9d8SDhruvaraj Subhashchandran     /** @brief Constructor to create an empty event object with only
54*6524b9d8SDhruvaraj Subhashchandran      *  timestamp, caller should make a call to emit added signal.
55*6524b9d8SDhruvaraj Subhashchandran      *  @param[in] path - Path to attach at.
56*6524b9d8SDhruvaraj Subhashchandran      *  @param[in] timestamp - timestamp when the event created.
57*6524b9d8SDhruvaraj Subhashchandran      */
58*6524b9d8SDhruvaraj Subhashchandran     Entry(const std::string& path, uint64_t eventTimestamp) :
59*6524b9d8SDhruvaraj Subhashchandran         EntryIface(SDBusPlus::getBus(), path.c_str(), true), objectPath(path)
60*6524b9d8SDhruvaraj Subhashchandran     {
61*6524b9d8SDhruvaraj Subhashchandran         timestamp(eventTimestamp);
62*6524b9d8SDhruvaraj Subhashchandran     }
63*6524b9d8SDhruvaraj Subhashchandran 
643e84ec66SRatan Gupta     /** @brief Path of Object. */
653e84ec66SRatan Gupta     std::string objectPath;
663e84ec66SRatan Gupta };
673e84ec66SRatan Gupta 
683e84ec66SRatan Gupta } // namespace events
693e84ec66SRatan Gupta } // namespace phosphor
70