blob: be4bea1e849f273e19d11fb9400575050c031571 [file] [log] [blame]
Ratan Gupta1dc91782018-04-19 16:47:12 +05301#include "config.h"
Patrick Williams1334b7b2021-02-22 17:15:12 -06002
Ratan Gupta1dc91782018-04-19 16:47:12 +05303#include "snmp_conf_manager.hpp"
4
George Liu4caedfb2022-05-10 16:26:53 +08005#include <phosphor-logging/lg2.hpp>
Ratan Gupta1dc91782018-04-19 16:47:12 +05306#include <sdbusplus/bus.hpp>
7#include <sdbusplus/server/manager.hpp>
8
9#include <memory>
10
11/* Need a custom deleter for freeing up sd_event */
12struct EventDeleter
13{
Patrick Williams1334b7b2021-02-22 17:15:12 -060014 void operator()(sd_event* event) const
Ratan Gupta1dc91782018-04-19 16:47:12 +053015 {
Ratan Gupta34d129a2021-12-04 21:04:51 +053016 sd_event_unref(event);
Ratan Gupta1dc91782018-04-19 16:47:12 +053017 }
18};
19
20using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
21
Ratan Gupta34d129a2021-12-04 21:04:51 +053022int main(int /*argc*/, char** /*argv[]*/)
Ratan Gupta1dc91782018-04-19 16:47:12 +053023{
Ratan Gupta1dc91782018-04-19 16:47:12 +053024 auto bus = sdbusplus::bus::new_default();
25
Patrick Williams1334b7b2021-02-22 17:15:12 -060026 sd_event* event = nullptr;
Ratan Gupta1dc91782018-04-19 16:47:12 +053027 auto r = sd_event_default(&event);
28 if (r < 0)
29 {
George Liu4caedfb2022-05-10 16:26:53 +080030 lg2::error("Error creating a default sd_event handler: {RC}", "RC", r);
Ratan Gupta1dc91782018-04-19 16:47:12 +053031 return r;
32 }
33
34 EventPtr eventPtr{event};
35 event = nullptr;
36
37 // Attach the bus to sd_event to service user requests
38 bus.attach_event(eventPtr.get(), SD_EVENT_PRIORITY_NORMAL);
39
40 // Add sdbusplus Object Manager for the 'root' path of the snmp.
41 sdbusplus::server::manager::manager objManager(bus, OBJ_NETWORK_SNMP);
42 bus.request_name(BUSNAME_NETWORK_SNMP);
43
44 auto manager = std::make_unique<phosphor::network::snmp::ConfManager>(
45 bus, OBJ_NETWORK_SNMP);
46
Ratan Gupta212f53e2018-04-30 17:28:05 +053047 manager->restoreClients();
48
Ratan Gupta1dc91782018-04-19 16:47:12 +053049 return sd_event_loop(eventPtr.get());
50}