blob: f779939658cb7fa5b46a4b6f1f2f901b901798cd [file] [log] [blame]
Matt Spinlere0017eb2018-03-27 11:17:38 -05001#pragma once
2
3#include <experimental/any>
4#include <experimental/filesystem>
5#include <map>
6#include <sdbusplus/bus.hpp>
7#include "dbus.hpp"
8#include "interfaces.hpp"
9
10namespace ibm
11{
12namespace logging
13{
14
15
16/**
17 * @class Manager
18 *
19 * This class hosts IBM specific interfaces for the error logging
20 * entry objects. It watches for interfaces added and removed
21 * signals to know when to create and delete objects. Handling the
22 * xyz.openbmc_project.Logging service going away is done at the
23 * systemd service level where this app will be stopped too.
24 */
25class Manager
26{
27 public:
28
29 Manager() = delete;
30 ~Manager() = default;
31 Manager(const Manager&) = delete;
32 Manager& operator=(const Manager&) = delete;
33 Manager(Manager&&) = delete;
34 Manager& operator=(Manager&&) = delete;
35
36 /**
37 * Constructor
38 *
39 * @param[in] bus - the D-Bus bus object
40 */
41 explicit Manager(sdbusplus::bus::bus& bus);
42
43 private:
44
45 /**
46 * The callback for an interfaces added signal
47 *
48 * Creates the IBM interfaces for the log entry
49 * that was just created.
50 *
51 * @param[in] msg - the sdbusplus message
52 */
53 void interfaceAdded(sdbusplus::message::message& msg);
54
55 /**
56 * The callback for an interfaces removed signal
57 *
58 * Removes the IBM interfaces for the log entry
59 * that was just removed.
60 *
61 * @param[in] msg - the sdbusplus message
62 */
63 void interfaceRemoved(sdbusplus::message::message& msg);
64
65 /**
66 * Returns the entry ID for a log
67 *
68 * @param[in] objectPath - the object path of the log
69 *
70 * @return uint32_t - the ID
71 */
72 inline uint32_t getEntryID(const std::string& objectPath)
73 {
74 std::experimental::filesystem::path path(objectPath);
75 return std::stoul(path.filename());
76 }
77
78 /**
79 * The sdbusplus bus object
80 */
81 sdbusplus::bus::bus& bus;
82
83 /**
84 * The match object for interfacesAdded
85 */
86 sdbusplus::bus::match_t addMatch;
87
88 /**
89 * The match object for interfacesRemoved
90 */
91 sdbusplus::bus::match_t removeMatch;
92
93 using EntryID = uint32_t;
94 using InterfaceMap = std::map<InterfaceType, std::experimental::any>;
95 using EntryMap = std::map<EntryID, InterfaceMap>;
96
97 /**
98 * A map of the error log IDs to their IBM interface objects.
99 * There may be multiple interfaces per ID.
100 */
101 EntryMap entries;
102};
103
104}
105}