blob: 4522a2a00de0c4efd6a87c5c8872b670b2625ad2 [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
5#include <phosphor-logging/log.hpp>
6#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 {
16 event = sd_event_unref(event);
17 }
18};
19
20using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
21
Patrick Williams1334b7b2021-02-22 17:15:12 -060022int main(int argc, char* argv[])
Ratan Gupta1dc91782018-04-19 16:47:12 +053023{
24 using namespace phosphor::logging;
25
26 auto bus = sdbusplus::bus::new_default();
27
Patrick Williams1334b7b2021-02-22 17:15:12 -060028 sd_event* event = nullptr;
Ratan Gupta1dc91782018-04-19 16:47:12 +053029 auto r = sd_event_default(&event);
30 if (r < 0)
31 {
32 log<level::ERR>("Error creating a default sd_event handler");
33 return r;
34 }
35
36 EventPtr eventPtr{event};
37 event = nullptr;
38
39 // Attach the bus to sd_event to service user requests
40 bus.attach_event(eventPtr.get(), SD_EVENT_PRIORITY_NORMAL);
41
42 // Add sdbusplus Object Manager for the 'root' path of the snmp.
43 sdbusplus::server::manager::manager objManager(bus, OBJ_NETWORK_SNMP);
44 bus.request_name(BUSNAME_NETWORK_SNMP);
45
46 auto manager = std::make_unique<phosphor::network::snmp::ConfManager>(
47 bus, OBJ_NETWORK_SNMP);
48
Ratan Gupta212f53e2018-04-30 17:28:05 +053049 manager->restoreClients();
50
Ratan Gupta1dc91782018-04-19 16:47:12 +053051 return sd_event_loop(eventPtr.get());
52}