blob: 123c05e5bae375be1c3e86a29c4f2dc8b38a446c [file] [log] [blame]
Ratan Gupta1dc91782018-04-19 16:47:12 +05301#include "config.h"
2#include "snmp_conf_manager.hpp"
3
4#include <phosphor-logging/log.hpp>
5#include <sdbusplus/bus.hpp>
6#include <sdbusplus/server/manager.hpp>
7
8#include <memory>
9
10/* Need a custom deleter for freeing up sd_event */
11struct EventDeleter
12{
Ratan Gupta63476192018-04-19 16:55:32 +053013 void operator()(sd_event *event) const
Ratan Gupta1dc91782018-04-19 16:47:12 +053014 {
15 event = sd_event_unref(event);
16 }
17};
18
19using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
20
Ratan Gupta63476192018-04-19 16:55:32 +053021int main(int argc, char *argv[])
Ratan Gupta1dc91782018-04-19 16:47:12 +053022{
23 using namespace phosphor::logging;
24
25 auto bus = sdbusplus::bus::new_default();
26
Ratan Gupta63476192018-04-19 16:55:32 +053027 sd_event *event = nullptr;
Ratan Gupta1dc91782018-04-19 16:47:12 +053028 auto r = sd_event_default(&event);
29 if (r < 0)
30 {
31 log<level::ERR>("Error creating a default sd_event handler");
32 return r;
33 }
34
35 EventPtr eventPtr{event};
36 event = nullptr;
37
38 // Attach the bus to sd_event to service user requests
39 bus.attach_event(eventPtr.get(), SD_EVENT_PRIORITY_NORMAL);
40
41 // Add sdbusplus Object Manager for the 'root' path of the snmp.
42 sdbusplus::server::manager::manager objManager(bus, OBJ_NETWORK_SNMP);
43 bus.request_name(BUSNAME_NETWORK_SNMP);
44
45 auto manager = std::make_unique<phosphor::network::snmp::ConfManager>(
46 bus, OBJ_NETWORK_SNMP);
47
Ratan Gupta212f53e2018-04-30 17:28:05 +053048 manager->restoreClients();
49
Ratan Gupta1dc91782018-04-19 16:47:12 +053050 return sd_event_loop(eventPtr.get());
51}