blob: 1cc1ce27671e1b1411d70e4d4caef158d93862f5 [file] [log] [blame]
Adriana Kobylak1db1bd32016-10-10 11:39:20 -05001#include <stdio.h>
2#include <sdbusplus/vtable.hpp>
3#include <systemd/sd-bus.h>
4#include "log.hpp"
5
6/*
7 * @fn commit()
8 * @brief Create an error/event log based on a message id
9 * @param[in] msg - dbus message
10 * @param[in] user_data - user data
11 * @param[in] error - dbus error
12 * @return Commit id
13 */
14auto commit(sd_bus_message *msg, void *user_data, sd_bus_error *error)
15{
16 int rc = 0;
17
18 return rc;
19}
20
21constexpr sdbusplus::vtable::vtable_t log_vtable[] =
22{
23 sdbusplus::vtable::start(),
24
25 sdbusplus::vtable::method("Commit", "i", "i", commit),
26 sdbusplus::vtable::end()
27};
28
29int main(int argc, char *argv[])
30{
31 constexpr const auto dbusLogObj = "/xyz/openbmc_project/Logging";
32 constexpr const auto dbusLogName = "xyz.openbmc_project.Logging";
33 int rc = -1;
34 sd_bus *bus = nullptr;
35
36 rc = sd_bus_open_system(&bus);
37 if (rc < 0)
38 {
39 logging::log<logging::level::ERR>("Failed to open system bus",
40 logging::entry("DESCRIPTION=%s", strerror(-rc)));
41 goto cleanup;
42 }
43
44 rc = sd_bus_add_object_manager(bus, nullptr, dbusLogObj);
45 if (rc < 0)
46 {
47 logging::log<logging::level::ERR>("Failed to add object mgr",
48 logging::entry("DESCRIPTION=%s", strerror(-rc)));
49 goto cleanup;
50 }
51
52 rc = sd_bus_add_object_vtable(bus,
53 nullptr,
54 dbusLogObj,
55 dbusLogName,
56 log_vtable,
57 nullptr);
58 if (rc < 0)
59 {
60 logging::log<logging::level::ERR>("Failed to add vtable",
61 logging::entry("DESCRIPTION=%s", strerror(-rc)));
62 goto cleanup;
63 }
64
65 rc = sd_bus_request_name(bus, dbusLogName, 0);
66 if (rc < 0)
67 {
68 logging::log<logging::level::ERR>("Failed to acquire service name",
69 logging::entry("DESCRIPTION=%s", strerror(-rc)));
70 }
71 else
72 {
73 for(;;)
74 {
75 rc = sd_bus_process(bus, nullptr);
76 if (rc < 0)
77 {
78 logging::log<logging::level::ERR>("Failed to connect to bus",
79 logging::entry("DESCRIPTION=%s", strerror(-rc)));
80 break;
81 }
82 if (rc > 0)
83 {
84 continue;
85 }
86
87 rc = sd_bus_wait(bus, (uint64_t) - 1);
88 if (rc < 0)
89 {
90 logging::log<logging::level::ERR>("Failed to wait on bus",
91 logging::entry("DESCRIPTION=%s", strerror(-rc)));
92 break;
93 }
94 }
95 }
96
97cleanup:
98 sd_bus_unref(bus);
99
100 return rc;
101}
102