xref: /openbmc/phosphor-dbus-monitor/src/event_entry.hpp (revision 232f395e3acd8dd68098fa915438e0f9ea4fc0f6)
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>
8ae4c95c6SAndrew Geissler #include <string>
93e84ec66SRatan Gupta 
103e84ec66SRatan Gupta namespace phosphor
113e84ec66SRatan Gupta {
123e84ec66SRatan Gupta namespace events
133e84ec66SRatan Gupta {
143e84ec66SRatan Gupta 
153e84ec66SRatan Gupta using namespace phosphor::dbus::monitoring;
163e84ec66SRatan Gupta 
173e84ec66SRatan Gupta using EntryIface = sdbusplus::server::object::object<
183e84ec66SRatan Gupta     sdbusplus::xyz::openbmc_project::Logging::server::Event>;
193e84ec66SRatan Gupta 
203e84ec66SRatan Gupta /** @class Entry
213e84ec66SRatan Gupta  *  @brief OpenBMC Event entry implementation.
223e84ec66SRatan Gupta  *  @details A concrete implementation for the
233e84ec66SRatan Gupta  *  xyz.openbmc_project.Event.Entry.
243e84ec66SRatan Gupta  */
253e84ec66SRatan Gupta class Entry : public EntryIface
263e84ec66SRatan Gupta {
273e84ec66SRatan Gupta   public:
283e84ec66SRatan Gupta     Entry() = delete;
293e84ec66SRatan Gupta     Entry(const Entry&) = delete;
303e84ec66SRatan Gupta     Entry& operator=(const Entry&) = delete;
313e84ec66SRatan Gupta     Entry(Entry&&) = delete;
323e84ec66SRatan Gupta     Entry& operator=(Entry&&) = delete;
333e84ec66SRatan Gupta     virtual ~Entry() = default;
343e84ec66SRatan Gupta 
353e84ec66SRatan Gupta     /** @brief Constructor to put object onto bus at a dbus path.
363e84ec66SRatan Gupta      *  @param[in] path - Path to attach at.
373e84ec66SRatan Gupta      *  @param[in] eventId - The event entry id.
383e84ec66SRatan Gupta      *  @param[in] timestamp - timestamp when the event created.
393e84ec66SRatan Gupta      *  @param[in] msg - The message of the event.
403e84ec66SRatan Gupta      *  @param[in] metaData - The event metadata.
413e84ec66SRatan Gupta      */
42d1eac88dSBrad Bishop     Entry(const std::string& path, uint64_t eventTimestamp, std::string&& msg,
433e84ec66SRatan Gupta           std::vector<std::string>&& metaData) :
44*232f395eSPatrick Williams         EntryIface(SDBusPlus::getBus(), path.c_str(),
45*232f395eSPatrick Williams                    EntryIface::action::defer_emit),
463e84ec66SRatan Gupta         objectPath(path)
473e84ec66SRatan Gupta     {
483e84ec66SRatan Gupta         timestamp(eventTimestamp);
493e84ec66SRatan Gupta         message(msg);
503e84ec66SRatan Gupta         additionalData(metaData);
513e84ec66SRatan Gupta         // Emit deferred signal.
523e84ec66SRatan Gupta         this->emit_object_added();
533e84ec66SRatan Gupta     }
543e84ec66SRatan Gupta 
556524b9d8SDhruvaraj Subhashchandran     /** @brief Constructor to create an empty event object with only
566524b9d8SDhruvaraj Subhashchandran      *  timestamp, caller should make a call to emit added signal.
576524b9d8SDhruvaraj Subhashchandran      *  @param[in] path - Path to attach at.
586524b9d8SDhruvaraj Subhashchandran      *  @param[in] timestamp - timestamp when the event created.
596524b9d8SDhruvaraj Subhashchandran      */
606524b9d8SDhruvaraj Subhashchandran     Entry(const std::string& path, uint64_t eventTimestamp) :
61*232f395eSPatrick Williams         EntryIface(SDBusPlus::getBus(), path.c_str(),
62*232f395eSPatrick Williams                    EntryIface::action::defer_emit),
63*232f395eSPatrick Williams         objectPath(path)
646524b9d8SDhruvaraj Subhashchandran     {
656524b9d8SDhruvaraj Subhashchandran         timestamp(eventTimestamp);
666524b9d8SDhruvaraj Subhashchandran     }
676524b9d8SDhruvaraj Subhashchandran 
683e84ec66SRatan Gupta     /** @brief Path of Object. */
693e84ec66SRatan Gupta     std::string objectPath;
703e84ec66SRatan Gupta };
713e84ec66SRatan Gupta 
723e84ec66SRatan Gupta } // namespace events
733e84ec66SRatan Gupta } // namespace phosphor
74