xref: /openbmc/phosphor-dbus-monitor/src/event_entry.hpp (revision ae4c95c6860b113e6898df059e7c41f75fb0b07a)
1 #pragma once
2 
3 #include "sdbusplus.hpp"
4 #include "xyz/openbmc_project/Logging/Event/server.hpp"
5 
6 #include <sdbusplus/bus.hpp>
7 #include <sdbusplus/server/object.hpp>
8 #include <string>
9 
10 namespace phosphor
11 {
12 namespace events
13 {
14 
15 using namespace phosphor::dbus::monitoring;
16 
17 using EntryIface = sdbusplus::server::object::object<
18     sdbusplus::xyz::openbmc_project::Logging::server::Event>;
19 
20 /** @class Entry
21  *  @brief OpenBMC Event entry implementation.
22  *  @details A concrete implementation for the
23  *  xyz.openbmc_project.Event.Entry.
24  */
25 class Entry : public EntryIface
26 {
27   public:
28     Entry() = delete;
29     Entry(const Entry&) = delete;
30     Entry& operator=(const Entry&) = delete;
31     Entry(Entry&&) = delete;
32     Entry& operator=(Entry&&) = delete;
33     virtual ~Entry() = default;
34 
35     /** @brief Constructor to put object onto bus at a dbus path.
36      *  @param[in] path - Path to attach at.
37      *  @param[in] eventId - The event entry id.
38      *  @param[in] timestamp - timestamp when the event created.
39      *  @param[in] msg - The message of the event.
40      *  @param[in] metaData - The event metadata.
41      */
42     Entry(const std::string& path, uint64_t eventTimestamp, std::string&& msg,
43           std::vector<std::string>&& metaData) :
44         EntryIface(SDBusPlus::getBus(), path.c_str(), true),
45         objectPath(path)
46     {
47         timestamp(eventTimestamp);
48         message(msg);
49         additionalData(metaData);
50         // Emit deferred signal.
51         this->emit_object_added();
52     }
53 
54     /** @brief Constructor to create an empty event object with only
55      *  timestamp, caller should make a call to emit added signal.
56      *  @param[in] path - Path to attach at.
57      *  @param[in] timestamp - timestamp when the event created.
58      */
59     Entry(const std::string& path, uint64_t eventTimestamp) :
60         EntryIface(SDBusPlus::getBus(), path.c_str(), true), objectPath(path)
61     {
62         timestamp(eventTimestamp);
63     }
64 
65     /** @brief Path of Object. */
66     std::string objectPath;
67 };
68 
69 } // namespace events
70 } // namespace phosphor
71