Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 1 | #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 */ |
| 11 | struct EventDeleter |
| 12 | { |
Ratan Gupta | 6347619 | 2018-04-19 16:55:32 +0530 | [diff] [blame] | 13 | void operator()(sd_event *event) const |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 14 | { |
| 15 | event = sd_event_unref(event); |
| 16 | } |
| 17 | }; |
| 18 | |
| 19 | using EventPtr = std::unique_ptr<sd_event, EventDeleter>; |
| 20 | |
Ratan Gupta | 6347619 | 2018-04-19 16:55:32 +0530 | [diff] [blame] | 21 | int main(int argc, char *argv[]) |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 22 | { |
| 23 | using namespace phosphor::logging; |
| 24 | |
| 25 | auto bus = sdbusplus::bus::new_default(); |
| 26 | |
Ratan Gupta | 6347619 | 2018-04-19 16:55:32 +0530 | [diff] [blame] | 27 | sd_event *event = nullptr; |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 28 | 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 Gupta | 212f53e | 2018-04-30 17:28:05 +0530 | [diff] [blame] | 48 | manager->restoreClients(); |
| 49 | |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 50 | return sd_event_loop(eventPtr.get()); |
| 51 | } |